diff --git a/libavcodec/parser.c b/libavcodec/parser.c index 670680ea7c..1b50f40b20 100644 --- a/libavcodec/parser.c +++ b/libavcodec/parser.c @@ -262,6 +262,9 @@ int ff_combine_frame(ParseContext *pc, int next, for (; pc->overread > 0; pc->overread--) pc->buffer[pc->index++] = pc->buffer[pc->overread_index++]; + if (next > *buf_size) + return AVERROR(EINVAL); + /* flush remaining if EOF */ if (!*buf_size && next == END_NOT_FOUND) next = 0;