From: Michael Niedermayer <michael@niedermayer.cc> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Subject: [FFmpeg-devel] [PATCH 1/4] avcodec/ffv1dec: Limit size of fltmap* to pixel number Date: Thu, 3 Apr 2025 12:50:46 +0200 Message-ID: <20250403105049.883948-1-michael@niedermayer.cc> (raw) This reduces needed memory and also removes the 65536 maximum for remap on the decoder side Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> --- libavcodec/ffv1.c | 2 ++ libavcodec/ffv1.h | 2 ++ libavcodec/ffv1dec.c | 25 ++++++++++--------------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c index 86fe9455c4c..885cef265f7 100644 --- a/libavcodec/ffv1.c +++ b/libavcodec/ffv1.c @@ -273,6 +273,8 @@ av_cold void ff_ffv1_close(FFV1Context *s) for(int p = 0; p < 4 ; p++) { av_freep(&sc->fltmap[p]); av_freep(&sc->fltmap32[p]); + sc->fltmap_size [p] = 0; + sc->fltmap32_size[p] = 0; } av_refstruct_unref(&sc->plane); diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h index c95508e2844..664a48d1f0d 100644 --- a/libavcodec/ffv1.h +++ b/libavcodec/ffv1.h @@ -111,6 +111,8 @@ typedef struct FFV1SliceContext { uint16_t *bitmap [4]; //float encode uint16_t *fltmap [4]; //halffloat encode & decode uint32_t *fltmap32[4]; //float decode + unsigned int fltmap_size[4]; + unsigned int fltmap32_size[4]; struct Unit { uint32_t val; //this is unneeded if you accept a dereference on each access uint16_t ndx; diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index dc4eeecc87c..8d10d2cf8b7 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -264,10 +264,6 @@ static int decode_slice_header(const FFV1Context *f, av_log(f->avctx, AV_LOG_ERROR, "unsupported remap\n"); return AVERROR_INVALIDDATA; } - if (sc->slice_width * sc->slice_height > 65536) { - av_log(f->avctx, AV_LOG_ERROR, "32bit needs remap\n"); - return AVERROR_INVALIDDATA; - } } return 0; @@ -298,6 +294,7 @@ static int decode_remap(FFV1Context *f, FFV1SliceContext *sc) { unsigned int end = (1LL<<f->avctx->bits_per_raw_sample) - 1; int flip = sc->remap == 2 ? (end>>1) : 0; + const int pixel_num = sc->slice_width * sc->slice_height; for (int p= 0; p < 1 + 2*f->chroma_planes + f->transparency; p++) { int j = 0; @@ -336,7 +333,7 @@ static int decode_remap(FFV1Context *f, FFV1SliceContext *sc) } if (i - 1 >= end) break; - if (j >= 65536 /*FF_ARRAY_ELEMS(sc->fltmap[p])*/) + if (j >= pixel_num) return AVERROR_INVALIDDATA; if (end <= 0xFFFF) { sc->fltmap [p][j++] = i ^ ((i& 0x8000) ? 0 : flip); @@ -398,19 +395,17 @@ static int decode_slice(AVCodecContext *c, void *arg) y = sc->slice_y; if (sc->remap) { + const int pixel_num = sc->slice_width * sc->slice_height; + for(int p = 0; p < 1 + 2*f->chroma_planes + f->transparency ; p++) { if (f->avctx->bits_per_raw_sample == 32) { - if (!sc->fltmap32[p]) { - sc->fltmap32[p] = av_malloc_array(65536, sizeof(*sc->fltmap32[p])); - if (!sc->fltmap32[p]) - return AVERROR(ENOMEM); - } + av_fast_malloc(&sc->fltmap32[p], &sc->fltmap32_size[p], pixel_num * sizeof(*sc->fltmap32[p])); + if (!sc->fltmap32[p]) + return AVERROR(ENOMEM); } else { - if (!sc->fltmap[p]) { - sc->fltmap[p] = av_malloc_array(65536, sizeof(*sc->fltmap[p])); - if (!sc->fltmap[p]) - return AVERROR(ENOMEM); - } + av_fast_malloc(&sc->fltmap[p], &sc->fltmap_size[p], pixel_num * sizeof(*sc->fltmap[p])); + if (!sc->fltmap[p]) + return AVERROR(ENOMEM); } } -- 2.49.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next reply other threads:[~2025-04-03 10:51 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2025-04-03 10:50 Michael Niedermayer [this message] 2025-04-03 10:50 ` [FFmpeg-devel] [PATCH 2/4] avcodec/ffv1enc: Remove 65536 pixel per slice limit for remap Michael Niedermayer 2025-04-03 10:50 ` [FFmpeg-devel] [PATCH 3/4] avcodec/ffv1enc: Consider 2s x s slice configurations Michael Niedermayer 2025-04-03 10:50 ` [FFmpeg-devel] [PATCH 4/4] avcodec/ffv1enc: avoid slices larger than 360x288 if no value is specified Michael Niedermayer 2025-04-06 23:29 ` James Almer 2025-04-06 23:44 ` Michael Niedermayer 2025-04-07 1:13 ` James Almer 2025-04-07 12:35 ` Michael Niedermayer 2025-04-06 18:43 ` [FFmpeg-devel] [PATCH 1/4] avcodec/ffv1dec: Limit size of fltmap* to pixel number Michael Niedermayer
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20250403105049.883948-1-michael@niedermayer.cc \ --to=michael@niedermayer.cc \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git