[FFmpeg-devel] [PATCH v2 43/71] avcodec/mpegpicture: Split MPVPicture into WorkPicture and ordinary Pic

Michael Niedermayer michael at niedermayer.cc
Mon Jun 24 01:28:28 EEST 2024


On Sat, May 11, 2024 at 10:51:07PM +0200, Andreas Rheinhardt wrote:
> There are two types of MPVPictures: Three (cur_pic, last_pic, next_pic)
> that are directly part of MpegEncContext and an array of MPVPictures
> that are separately allocated and are mostly accessed via pointers
> (cur|last|next)_pic_ptr; they are also used to store AVFrames in the
> encoder (necessary due to B-frames). As the name implies, each of the
> former is directly associated with one of the _ptr pointers:
> They actually share the same underlying buffers, but the ones
> that are part of the context can have their data pointers offset
> and their linesize doubled for field pictures.
> 
> Up until now, each of these had their own references; in particular,
> there was an underlying av_frame_ref() to sync cur_pic and cur_pic_ptr
> etc. This is wasteful.
> 
> This commit changes this relationship: cur_pic, last_pic and next_pic
> now become MPVWorkPictures; this structure does not have an AVFrame
> at all any more, but only the cached values of data and linesize.
> It also contains a pointer to the corresponding MPVPicture, establishing
> a more natural relationsship between the two.
> This already means that creating the context-pictures from the pointers
> can no longer fail.
> 
> What has not been changed is the fact that the MPVPicture* pointers
> are not ownership pointers and that the MPVPictures are part of an
> array of MPVPictures that is owned by a single AVCodecContext.
> Doing so will be done in a latter commit.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
> ---
>  libavcodec/d3d12va_mpeg2.c               |  10 +-
>  libavcodec/d3d12va_vc1.c                 |  10 +-
>  libavcodec/dxva2_mpeg2.c                 |  16 +--
>  libavcodec/dxva2_vc1.c                   |  20 ++--
>  libavcodec/h261dec.c                     |   7 +-
>  libavcodec/h263dec.c                     |  33 +++---
>  libavcodec/ituh263dec.c                  |   4 +-
>  libavcodec/mpeg12dec.c                   |  56 ++++-----
>  libavcodec/mpeg12enc.c                   |  14 +--
>  libavcodec/mpeg4videodec.c               |   4 +-
>  libavcodec/mpeg4videoenc.c               |   4 +-
>  libavcodec/mpeg_er.c                     |   6 +-
>  libavcodec/mpegpicture.c                 |  56 ++++++---
>  libavcodec/mpegpicture.h                 |  30 ++++-
>  libavcodec/mpegvideo.c                   |  11 --
>  libavcodec/mpegvideo.h                   |   9 +-
>  libavcodec/mpegvideo_dec.c               | 143 +++++++++--------------
>  libavcodec/mpegvideo_enc.c               |  99 ++++++----------
>  libavcodec/mpegvideo_motion.c            |   8 +-
>  libavcodec/mpv_reconstruct_mb_template.c |   4 +-
>  libavcodec/mss2.c                        |   2 +-
>  libavcodec/nvdec_mpeg12.c                |   6 +-
>  libavcodec/nvdec_mpeg4.c                 |   6 +-
>  libavcodec/nvdec_vc1.c                   |   6 +-
>  libavcodec/ratecontrol.c                 |  10 +-
>  libavcodec/rv10.c                        |  28 ++---
>  libavcodec/rv34.c                        |  38 +++---
>  libavcodec/snowenc.c                     |  17 +--
>  libavcodec/svq1enc.c                     |   5 +-
>  libavcodec/vaapi_mpeg2.c                 |  12 +-
>  libavcodec/vaapi_mpeg4.c                 |  14 +--
>  libavcodec/vaapi_vc1.c                   |  14 ++-
>  libavcodec/vc1.c                         |   2 +-
>  libavcodec/vc1_block.c                   |  12 +-
>  libavcodec/vc1_mc.c                      |  14 +--
>  libavcodec/vc1_pred.c                    |   2 +-
>  libavcodec/vc1dec.c                      |  40 +++----
>  libavcodec/vdpau.c                       |   2 +-
>  libavcodec/vdpau_mpeg12.c                |   8 +-
>  libavcodec/vdpau_mpeg4.c                 |   6 +-
>  libavcodec/vdpau_vc1.c                   |  12 +-
>  libavcodec/videotoolbox.c                |   2 +-
>  libavcodec/wmv2dec.c                     |   2 +-
>  43 files changed, 386 insertions(+), 418 deletions(-)
[...]

after this the linesize for teh last field picture goes exponential
s->last_pic.linesize[i] *= 2;

libavcodec/mpeg12dec.c:1304:41: runtime error: signed integer overflow: 4611686018427387904 * 2 cannot be represented in type 'long'

issue: 69732/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MPEGVIDEO_fuzzer-5123551179374592

something like this:
L0 40 0x62e0001f8400 0x613000000780
L1 40 0x62a0001fe200 0x613000000780
L2 40 0x62a000204200 0x613000000780
L0 80 0x62e0001f8400 0x613000000780
L1 80 0x62a0001fe200 0x613000000780
L2 80 0x62a000204200 0x613000000780
L0 100 0x62e0001f8400 0x613000000780
L1 100 0x62a0001fe200 0x613000000780
L2 100 0x62a000204200 0x613000000780
L0 200 0x62e0001f8400 0x613000000780
L1 200 0x62a0001fe200 0x613000000780
L2 200 0x62a000204200 0x613000000780
L0 400 0x62e0001f8400 0x613000000780
L1 400 0x62a0001fe200 0x613000000780
L2 400 0x62a000204200 0x613000000780
L0 800 0x62e0001f8400 0x613000000780
L1 800 0x62a0001fe200 0x613000000780
L2 800 0x62a000204200 0x613000000780
L0 1000 0x62e0001f8400 0x613000000780
L1 1000 0x62a0001fe200 0x613000000780
L2 1000 0x62a000204200 0x613000000780
L0 2000 0x62e0001f8400 0x613000000780
L1 2000 0x62a0001fe200 0x613000000780
L2 2000 0x62a000204200 0x613000000780
L0 4000 0x62e0001f8400 0x613000000780
L1 4000 0x62a0001fe200 0x613000000780
L2 4000 0x62a000204200 0x613000000780
L0 8000 0x62e0001f8400 0x613000000780
L1 8000 0x62a0001fe200 0x613000000780
L2 8000 0x62a000204200 0x613000000780
L0 10000 0x62e0001f8400 0x613000000780
L1 10000 0x62a0001fe200 0x613000000780
L2 10000 0x62a000204200 0x613000000780
L0 20000 0x62e0001f8400 0x613000000780
L1 20000 0x62a0001fe200 0x613000000780
L2 20000 0x62a000204200 0x613000000780
L0 40000 0x62e0001f8400 0x613000000780
L1 40000 0x62a0001fe200 0x613000000780
L2 40000 0x62a000204200 0x613000000780
L0 80000 0x62e0001f8400 0x613000000780
L1 80000 0x62a0001fe200 0x613000000780
L2 80000 0x62a000204200 0x613000000780
L0 100000 0x62e0001f8400 0x613000000780
L1 100000 0x62a0001fe200 0x613000000780
L2 100000 0x62a000204200 0x613000000780
L0 200000 0x62e0001f8400 0x613000000780
L1 200000 0x62a0001fe200 0x613000000780
L2 200000 0x62a000204200 0x613000000780
L0 400000 0x62e0001f8400 0x613000000780
L1 400000 0x62a0001fe200 0x613000000780
L2 400000 0x62a000204200 0x613000000780
L0 800000 0x62e0001f8400 0x613000000780
L1 800000 0x62a0001fe200 0x613000000780
L2 800000 0x62a000204200 0x613000000780
L0 1000000 0x62e0001f8400 0x613000000780
L1 1000000 0x62a0001fe200 0x613000000780
L2 1000000 0x62a000204200 0x613000000780
L0 2000000 0x62e0001f8400 0x613000000780
L1 2000000 0x62a0001fe200 0x613000000780
L2 2000000 0x62a000204200 0x613000000780
L0 4000000 0x62e0001f8400 0x613000000780
L1 4000000 0x62a0001fe200 0x613000000780
L2 4000000 0x62a000204200 0x613000000780
L0 8000000 0x62e0001f8400 0x613000000780
L1 8000000 0x62a0001fe200 0x613000000780
L2 8000000 0x62a000204200 0x613000000780
L0 10000000 0x62e0001f8400 0x613000000780
L1 10000000 0x62a0001fe200 0x613000000780
L2 10000000 0x62a000204200 0x613000000780
L0 20000000 0x62e0001f8400 0x613000000780
L1 20000000 0x62a0001fe200 0x613000000780
L2 20000000 0x62a000204200 0x613000000780
L0 40000000 0x62e0001f8400 0x613000000780
L1 40000000 0x62a0001fe200 0x613000000780
L2 40000000 0x62a000204200 0x613000000780
L0 80000000 0x62e0001f8400 0x613000000780
L1 80000000 0x62a0001fe200 0x613000000780
L2 80000000 0x62a000204200 0x613000000780
L0 100000000 0x62e0001f8400 0x613000000780
L1 100000000 0x62a0001fe200 0x613000000780
L2 100000000 0x62a000204200 0x613000000780
L0 200000000 0x62e0001f8400 0x613000000780
L1 200000000 0x62a0001fe200 0x613000000780
L2 200000000 0x62a000204200 0x613000000780
L0 400000000 0x62e0001f8400 0x613000000780
L1 400000000 0x62a0001fe200 0x613000000780
L2 400000000 0x62a000204200 0x613000000780
L0 800000000 0x62e0001f8400 0x613000000780
L1 800000000 0x62a0001fe200 0x613000000780
L2 800000000 0x62a000204200 0x613000000780
L0 1000000000 0x62e0001f8400 0x613000000780
L1 1000000000 0x62a0001fe200 0x613000000780
L2 1000000000 0x62a000204200 0x613000000780
L0 2000000000 0x62e0001f8400 0x613000000780
L1 2000000000 0x62a0001fe200 0x613000000780
L2 2000000000 0x62a000204200 0x613000000780
L0 4000000000 0x62e0001f8400 0x613000000780
L1 4000000000 0x62a0001fe200 0x613000000780
L2 4000000000 0x62a000204200 0x613000000780
L0 8000000000 0x62e0001f8400 0x613000000780
L1 8000000000 0x62a0001fe200 0x613000000780
L2 8000000000 0x62a000204200 0x613000000780
L0 10000000000 0x62e0001f8400 0x613000000780
L1 10000000000 0x62a0001fe200 0x613000000780
L2 10000000000 0x62a000204200 0x613000000780
L0 20000000000 0x62e0001f8400 0x613000000780
L1 20000000000 0x62a0001fe200 0x613000000780
L2 20000000000 0x62a000204200 0x613000000780
L0 40000000000 0x62e0001f8400 0x613000000780
L1 40000000000 0x62a0001fe200 0x613000000780
L2 40000000000 0x62a000204200 0x613000000780
L0 80000000000 0x62e0001f8400 0x613000000780
L1 80000000000 0x62a0001fe200 0x613000000780
L2 80000000000 0x62a000204200 0x613000000780
L0 100000000000 0x62e0001f8400 0x613000000780
L1 100000000000 0x62a0001fe200 0x613000000780
L2 100000000000 0x62a000204200 0x613000000780
L0 200000000000 0x62e0001f8400 0x613000000780
L1 200000000000 0x62a0001fe200 0x613000000780
L2 200000000000 0x62a000204200 0x613000000780
L0 400000000000 0x62e0001f8400 0x613000000780
L1 400000000000 0x62a0001fe200 0x613000000780
L2 400000000000 0x62a000204200 0x613000000780
L0 800000000000 0x62e0001f8400 0x613000000780
L1 800000000000 0x62a0001fe200 0x613000000780
L2 800000000000 0x62a000204200 0x613000000780
L0 1000000000000 0x62e0001f8400 0x613000000780
L1 1000000000000 0x62a0001fe200 0x613000000780
L2 1000000000000 0x62a000204200 0x613000000780
L0 2000000000000 0x62e0001f8400 0x613000000780
L1 2000000000000 0x62a0001fe200 0x613000000780
L2 2000000000000 0x62a000204200 0x613000000780
L0 4000000000000 0x62e0001f8400 0x613000000780
L1 4000000000000 0x62a0001fe200 0x613000000780
L2 4000000000000 0x62a000204200 0x613000000780
L0 8000000000000 0x62e0001f8400 0x613000000780
L1 8000000000000 0x62a0001fe200 0x613000000780
L2 8000000000000 0x62a000204200 0x613000000780
L0 10000000000000 0x62e0001f8400 0x613000000780
L1 10000000000000 0x62a0001fe200 0x613000000780
L2 10000000000000 0x62a000204200 0x613000000780
L0 20000000000000 0x62e0001f8400 0x613000000780
L1 20000000000000 0x62a0001fe200 0x613000000780
L2 20000000000000 0x62a000204200 0x613000000780
L0 40000000000000 0x62e0001f8400 0x613000000780
L1 40000000000000 0x62a0001fe200 0x613000000780
L2 40000000000000 0x62a000204200 0x613000000780
L0 80000000000000 0x62e0001f8400 0x613000000780
L1 80000000000000 0x62a0001fe200 0x613000000780
L2 80000000000000 0x62a000204200 0x613000000780
L0 100000000000000 0x62e0001f8400 0x613000000780
L1 100000000000000 0x62a0001fe200 0x613000000780
L2 100000000000000 0x62a000204200 0x613000000780
L0 200000000000000 0x62e0001f8400 0x613000000780
L1 200000000000000 0x62a0001fe200 0x613000000780
L2 200000000000000 0x62a000204200 0x613000000780
L0 400000000000000 0x62e0001f8400 0x613000000780
L1 400000000000000 0x62a0001fe200 0x613000000780
L2 400000000000000 0x62a000204200 0x613000000780
L0 800000000000000 0x62e0001f8400 0x613000000780
L1 800000000000000 0x62a0001fe200 0x613000000780
L2 800000000000000 0x62a000204200 0x613000000780
L0 1000000000000000 0x62e0001f8400 0x613000000780
L1 1000000000000000 0x62a0001fe200 0x613000000780
L2 1000000000000000 0x62a000204200 0x613000000780
L0 2000000000000000 0x62e0001f8400 0x613000000780
L1 2000000000000000 0x62a0001fe200 0x613000000780
L2 2000000000000000 0x62a000204200 0x613000000780
L0 4000000000000000 0x62e0001f8400 0x613000000780


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The greatest way to live with honor in this world is to be what we pretend
to be. -- Socrates
-------------- 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/20240624/5b429f3d/attachment.sig>


More information about the ffmpeg-devel mailing list