Skip to content

Commit

Permalink
cbd marker: validate precision
Browse files Browse the repository at this point in the history
  • Loading branch information
Grok Compression committed Dec 22, 2024
1 parent 33de944 commit 88a626b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
5 changes: 3 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@
"-i",
"~/temp/input_01",
"-o",
"~/temp/input_01.tif",
"-v"
"~/temp/input_01.png",
"-v",
"-d 0,0,1024,1024"
],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
Expand Down
10 changes: 9 additions & 1 deletion src/lib/core/codestream/CodeStreamDecompress_Markers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,15 @@ bool CodeStreamDecompress::read_cbd(uint8_t* headerData, uint16_t header_size)
grk_read<uint8_t>(headerData++, &comp_def);
auto comp = getHeaderImage()->comps + i;
comp->sgnd = ((uint32_t)(comp_def >> 7U) & 1U);
comp->prec = (uint8_t)((comp_def & 0x7f) + 1U);
auto prec = (uint8_t)((comp_def & 0x7f) + 1U);
if(prec > GRK_MAX_SUPPORTED_IMAGE_PRECISION)
{
Logger::logger_.error("CBD marker: precision %d for component %d is greater than maximum "
"supported precision %d",
prec, i, GRK_MAX_SUPPORTED_IMAGE_PRECISION);
return false;
}
comp->prec = prec;
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/core/tile/TileProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ bool TileProcessor::decompressT2T1(GrkImage* outputImage)
catch([[maybe_unused]] const std::bad_alloc& baex)
{
std::string msg = std::string("Memory allocation failed: ") + baex.what();
Logger::logger_.error("%s",msg.c_str());
Logger::logger_.error("%s", msg.c_str());
return false;
}
}
Expand Down

0 comments on commit 88a626b

Please sign in to comment.