avformat/aviobuf: Check buf_size in ffio_ensure_seekback()

buffer_size is an int

Fixes: signed integer overflow: 9223372036854775754 + 32767 cannot be represented in type 'long'
Fixes: 45691/clusterfuzz-testcase-minimized-ffmpeg_IO_DEMUXER_fuzzer-5263458831040512

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
Michael Niedermayer 2022-03-20 23:32:53 +01:00
parent 35dc93ab44
commit c4b130e876
1 changed files with 3 additions and 0 deletions

View File

@ -1062,6 +1062,9 @@ int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size)
if (buf_size <= s->buf_end - s->buf_ptr)
return 0;
if (buf_size > INT_MAX - max_buffer_size)
return AVERROR(EINVAL);
buf_size += max_buffer_size - 1;
if (buf_size + s->buf_ptr - s->buffer <= s->buffer_size || s->seekable || !s->read_packet)