Skip to content

Commit cc2127d

Browse files
author
Grok Compression
committed
compress: ensure that tile width is not less than code block width
1 parent a5ef903 commit cc2127d

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

src/lib/core/t1/part1/Coder.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ bool Coder::preCompress(CompressBlockExec* block, uint32_t& maximum)
4343
grklog.error("Unable to compress degenerate code block of dimensions %ux%u", w, h);
4444
return false;
4545
}
46+
if(block->tile_width < w)
47+
{
48+
grklog.error("Tile width %u less than code block width %u", block->tile_width, w);
49+
return false;
50+
}
4651
if(!blockCoder_->alloc(w, h))
4752
return false;
4853
auto tileLineAdvance = block->tile_width - w;

src/lib/core/t1/part15/CoderOJPH.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,14 @@ T1OJPH::~T1OJPH()
107107
delete allocator;
108108
delete elastic_alloc;
109109
}
110-
void T1OJPH::preCompress([[maybe_unused]] CompressBlockExec* block)
110+
bool T1OJPH::preCompress([[maybe_unused]] CompressBlockExec* block)
111111
{
112112
auto cblk = block->cblk;
113113
auto w = cblk->width();
114114
auto h = cblk->height();
115115
uint32_t tile_width = block->tile_width;
116+
if(tile_width < w)
117+
return false;
116118
auto tileLineAdvance = tile_width - w;
117119
uint32_t cblk_index = 0;
118120
int32_t shift = 31 - (block->k_msbs + 1);
@@ -152,10 +154,12 @@ void T1OJPH::preCompress([[maybe_unused]] CompressBlockExec* block)
152154
tiledp += tileLineAdvance;
153155
}
154156
}
157+
return true;
155158
}
156159
bool T1OJPH::compress(CompressBlockExec* block)
157160
{
158-
preCompress(block);
161+
if(!preCompress(block))
162+
return false;
159163

160164
coded_lists* next_coded = nullptr;
161165
auto cblk = block->cblk;

src/lib/core/t1/part15/CoderOJPH.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class T1OJPH : public ICoder
3535
bool decompress(DecompressBlockExec* block) override;
3636

3737
private:
38-
void preCompress(CompressBlockExec* block);
38+
bool preCompress(CompressBlockExec* block);
3939
bool postProcess(DecompressBlockExec* block);
4040

4141
uint32_t coded_data_size;

0 commit comments

Comments
 (0)