[FFmpeg-devel] [PATCH 2/4] avcodec/avpacket: Perform fewer reallocations in repeated av_grow_packet()

Michael Niedermayer michael at niedermayer.cc
Mon Dec 6 15:19:22 EET 2021


On Mon, Dec 06, 2021 at 11:17:17AM +0100, Michael Niedermayer wrote:
> On Mon, Dec 06, 2021 at 11:04:09AM +0100, Anton Khirnov wrote:
> > Quoting Michael Niedermayer (2021-12-04 22:32:56)
> > > 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);
> > 
> > This needs a comment, e.g.
> > // allocate slightly more than requested to avoid excessive
> > // reallocations
> 
> above comment added

will apply

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Let us carefully observe those good qualities wherein our enemies excel us
and endeavor to excel them, by avoiding what is faulty, and imitating what
is excellent in them. -- Plutarch
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20211206/ee7ddddb/attachment.sig>


More information about the ffmpeg-devel mailing list