Re: [libav-devel] [PATCH] mov: Rework stsc index validation
On Fri, Feb 03, 2017 at 01:51:50PM +0100, Diego Biurrun wrote: > On Fri, Feb 03, 2017 at 01:05:27PM +0100, Vittorio Giovara wrote: > > In order to avoid potential integer overflow change the comparison > > andmake sure to use the same unsigned type for both elements. > > In order to avoid a potential integer overflow change the comparison > and make sure to use the same unsigned type for both elements. > > > --- a/libavformat/mov.c > > +++ b/libavformat/mov.c > > @@ -1983,13 +1983,13 @@ static int mov_read_stsc(MOVContext *c, AVIOContext > > *pb, MOVAtom atom) > > > > -static inline int mov_stsc_index_valid(int index, int count) > > +static inline int mov_stsc_index_valid(unsigned int index, unsigned int > > count) > > { > > -return index + 1 < count; > > +return index < count - 1; > > If count is 0, this changes behavior; is that intentional? Yes, so probably OK. Diego ___ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel
Re: [libav-devel] [PATCH] mov: Rework stsc index validation
On Fri, Feb 03, 2017 at 01:05:27PM +0100, Vittorio Giovara wrote: > In order to avoid potential integer overflow change the comparison > andmake sure to use the same unsigned type for both elements. In order to avoid a potential integer overflow change the comparison and make sure to use the same unsigned type for both elements. > --- a/libavformat/mov.c > +++ b/libavformat/mov.c > @@ -1983,13 +1983,13 @@ static int mov_read_stsc(MOVContext *c, AVIOContext > *pb, MOVAtom atom) > > -static inline int mov_stsc_index_valid(int index, int count) > +static inline int mov_stsc_index_valid(unsigned int index, unsigned int > count) > { > -return index + 1 < count; > +return index < count - 1; If count is 0, this changes behavior; is that intentional? > -static inline int mov_get_stsc_samples(MOVStreamContext *sc, int index) > +static inline int mov_get_stsc_samples(MOVStreamContext *sc, unsigned int > index) I'd use plain "unsigned" everywhere, but whatever. Diego ___ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel
[libav-devel] [PATCH] mov: Rework stsc index validation
In order to avoid potential integer overflow change the comparison andmake sure to use the same unsigned type for both elements. --- Thanks to Clement for pointing this issue out. Vittorio libavformat/isom.h | 2 +- libavformat/mov.c | 8 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libavformat/isom.h b/libavformat/isom.h index 85b8761..8cc5ab7 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -111,7 +111,7 @@ typedef struct MOVStreamContext { MOVStts *ctts_data; unsigned int stsc_count; MOVStsc *stsc_data; -int stsc_index; +unsigned int stsc_index; int stsc_sample; unsigned int stps_count; unsigned *stps_data; ///< partial sync sample for mpeg-2 open gop diff --git a/libavformat/mov.c b/libavformat/mov.c index 9afd020..e42e04f 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -1983,13 +1983,13 @@ static int mov_read_stsc(MOVContext *c, AVIOContext *pb, MOVAtom atom) return 0; } -static inline int mov_stsc_index_valid(int index, int count) +static inline int mov_stsc_index_valid(unsigned int index, unsigned int count) { -return index + 1 < count; +return index < count - 1; } /* Compute the samples value for the stsc entry at the given index. */ -static inline int mov_get_stsc_samples(MOVStreamContext *sc, int index) +static inline int mov_get_stsc_samples(MOVStreamContext *sc, unsigned int index) { int chunk_count; @@ -3982,7 +3982,7 @@ static int mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t timestamp, { MOVStreamContext *sc = st->priv_data; int sample, time_sample; -int i; +unsigned int i; sample = av_index_search_timestamp(st, timestamp, flags); av_log(s, AV_LOG_TRACE, "stream %d, timestamp %"PRId64", sample %d\n", st->index, timestamp, sample); -- 2.10.0 ___ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel