File tree Expand file tree Collapse file tree
src/lib/core/t1/codeblock Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1717
1818#pragma once
1919
20+ #include < algorithm>
2021#include " CodeblockImpl.h"
2122const uint8_t grk_cblk_enc_compressed_data_pad_left = 2 ;
2223
@@ -124,7 +125,11 @@ struct CodeblockCompressImpl : public CodeblockImpl
124125 */
125126 bool allocData (size_t nominalBlockSize)
126127 {
127- uint32_t desired_data_size = (uint32_t )(nominalBlockSize * sizeof (uint32_t ));
128+ // The MQ coder output can exceed nominalBlockSize * 4 for small code blocks
129+ // with many bit-planes (up to ~30 planes × 3 passes each, with flush/termination
130+ // overhead per pass). Use a minimum of 4096 bytes to prevent overflow.
131+ uint32_t desired_data_size =
132+ std::max ((uint32_t )(nominalBlockSize * sizeof (uint32_t )), (uint32_t )4096 );
128133 // we add two fake zero bytes at beginning of buffer, so that mq coder
129134 // can be initialized to data[-1] == actualData[1], and still point
130135 // to a valid memory location
You can’t perform that action at this time.
0 commit comments