[FFmpeg-devel] [PATCH 2/4] avcodec/avpacket: Perform fewer reallocations in repeated av_grow_packet()
Michael Niedermayer
michael at niedermayer.cc
Sat Dec 4 23:32:56 EET 2021
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>
---
libavcodec/avpacket.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index d8d8fef3b9e..b10498bfc1d 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -142,7 +142,12 @@ 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;
+
+ 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;
--
2.17.1
More information about the ffmpeg-devel
mailing list