[FFmpeg-cvslog] avcodec/avpacket: Perform fewer reallocations in repeated av_grow_packet()
Michael Niedermayer
git at videolan.org
Mon Dec 6 15:27:16 EET 2021
ffmpeg | branch: master | Michael Niedermayer <michael at niedermayer.cc> | Sat Dec 4 20:33:30 2021 +0100| [235ac7b4925ab963afd7719577a8fd6ce25b4d5f] | committer: Michael Niedermayer
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 at niedermayer.cc>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=235ac7b4925ab963afd7719577a8fd6ce25b4d5f
---
libavcodec/avpacket.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index d8d8fef3b9..a0134e405c 100644
--- a/libavcodec/avpacket.c
+++ b/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;
More information about the ffmpeg-cvslog
mailing list