[FFmpeg-cvslog] avcodec/mjpegenc: Don't allocate unnecessarily much memory
Andreas Rheinhardt
git at videolan.org
Thu Mar 27 14:45:45 EET 2025
ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Thu Mar 27 03:03:02 2025 +0100| [2ac2485c1f901638870c956d816f4d20a184ca23] | committer: Andreas Rheinhardt
avcodec/mjpegenc: Don't allocate unnecessarily much memory
We need to allocate space for 64 coefficients per block;
24dbc4c2e82481f89d6fcacee1949e5038c5c2fc wanted to
perform the calculation 64*sizeof(MJpegHuffmanCode)
at compile time, yet in the end did it in a way that
made it allocate 64 times as much memory as needed.
Reported-by: Michael Niedermayer <michael at niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2ac2485c1f901638870c956d816f4d20a184ca23
---
libavcodec/mjpegenc.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c
index 668065011c..214e2b0ec1 100644
--- a/libavcodec/mjpegenc.c
+++ b/libavcodec/mjpegenc.c
@@ -291,13 +291,12 @@ static int alloc_huffman(MJPEGEncContext *const m2)
static const char blocks_per_mb[] = {
[CHROMA_420] = 6, [CHROMA_422] = 8, [CHROMA_444] = 12
};
- size_t num_blocks, num_codes;
+ size_t num_blocks;
// Make sure we have enough space to hold this frame.
num_blocks = s->c.mb_num * blocks_per_mb[s->c.chroma_format];
- num_codes = num_blocks * 64;
- m->huff_buffer = av_malloc_array(num_codes,
+ m->huff_buffer = av_malloc_array(num_blocks,
64 /* codes per MB */ * sizeof(MJpegHuffmanCode));
if (!m->huff_buffer)
return AVERROR(ENOMEM);
More information about the ffmpeg-cvslog
mailing list