You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-04 22:03:09 +02:00
avcodec/mjpegenc: Don't allocate unnecessarily much memory
We need to allocate space for 64 coefficients per block;
24dbc4c2e8
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@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
@ -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);
|
||||
|
Reference in New Issue
Block a user