Skip to content

Commit a5ef903

Browse files
author
Grok Compression
committed
compress: fix ASAN error by setting min size of MQ coder output buffer
1 parent e902905 commit a5ef903

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/lib/core/t1/codeblock/CodeblockCompressImpl.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#pragma once
1919

20+
#include <algorithm>
2021
#include "CodeblockImpl.h"
2122
const 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

0 commit comments

Comments
 (0)