You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-10 06:10:52 +02:00
avfilter/formats: Make check for buffer overflow redundant
and remove the redundant check. This check for whether the allocated buffer is sufficient has been added in commit1cbf7fb434
(merging commit5775a1832c
). It is not sufficient to detect invalid input lists (namely lists with duplicates); its only use is to avoid buffer overflows. And this can be achieved by simpler means: Make sure that one allocates space for so many elements as the outer loop ranges over and break out of the inner loop if a match has been found. For valid input without duplicates, no further match will be found anyway. This change will temporarily make the allocated formats array larger than before and larger than necessary; this will be fixed in a later commit that avoids the allocation altogether. If a check for duplicates in the lists is deemed necessary, it should be done properly somewhere else. Finally, the error message that is removed in this commit used __FUNCTION__, which is a GCC extension (C99 added __func__ for this). So this commit removes a warning when compiling in -pedantic mode. Reviewed-by: Nicolas George <george@nsup.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
This commit is contained in:
@@ -65,7 +65,7 @@ do { \
|
|||||||
*/
|
*/
|
||||||
#define MERGE_FORMATS(ret, a, b, fmts, nb, type, fail) \
|
#define MERGE_FORMATS(ret, a, b, fmts, nb, type, fail) \
|
||||||
do { \
|
do { \
|
||||||
int i, j, k = 0, count = FFMIN(a->nb, b->nb); \
|
int i, j, k = 0, count = a->nb; \
|
||||||
type ***tmp; \
|
type ***tmp; \
|
||||||
\
|
\
|
||||||
if (!(ret = av_mallocz(sizeof(*ret)))) \
|
if (!(ret = av_mallocz(sizeof(*ret)))) \
|
||||||
@@ -77,13 +77,8 @@ do {
|
|||||||
for (i = 0; i < a->nb; i++) \
|
for (i = 0; i < a->nb; i++) \
|
||||||
for (j = 0; j < b->nb; j++) \
|
for (j = 0; j < b->nb; j++) \
|
||||||
if (a->fmts[i] == b->fmts[j]) { \
|
if (a->fmts[i] == b->fmts[j]) { \
|
||||||
if(k >= FFMIN(a->nb, b->nb)){ \
|
|
||||||
av_log(NULL, AV_LOG_ERROR, "Duplicate formats in %s detected\n", __FUNCTION__); \
|
|
||||||
av_free(ret->fmts); \
|
|
||||||
av_free(ret); \
|
|
||||||
return NULL; \
|
|
||||||
} \
|
|
||||||
ret->fmts[k++] = a->fmts[i]; \
|
ret->fmts[k++] = a->fmts[i]; \
|
||||||
|
break; \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
ret->nb = k; \
|
ret->nb = k; \
|
||||||
|
Reference in New Issue
Block a user