avcodec/avpacket: Perform fewer reallocations in repeated av_grow_packet()

Fixes: Timeout
Fixes: 41446/clusterfuzz-testcase-minimized-ffmpeg_dem_SAMI_fuzzer-4667644540747776

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
pull/375/head
Michael Niedermayer 3 years ago
parent 59b4e7cbd8
commit 235ac7b492
  1. 9
      libavcodec/avpacket.c

@ -142,7 +142,14 @@ int av_grow_packet(AVPacket *pkt, int grow_by)
if (new_size + data_offset > pkt->buf->size ||
!av_buffer_is_writable(pkt->buf)) {
int ret = av_buffer_realloc(&pkt->buf, new_size + data_offset);
int ret;
// allocate slightly more than requested to avoid excessive
// reallocations
if (new_size + data_offset < INT_MAX - new_size/16)
new_size += new_size/16;
ret = av_buffer_realloc(&pkt->buf, new_size + data_offset);
if (ret < 0) {
pkt->data = old_data;
return ret;

Loading…
Cancel
Save