Skip to content
This repository was archived by the owner on Apr 18, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pik/ans_decode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ Status ReadHistogram(int precision_bits, std::vector<int>* counts,
input->FillBitBuffer();
int rle_length = input->PeekFixedBits<8>();
input->Advance(8);
if (rle_length < 2) {
return PIK_FAILURE("Invalid RLE length in histogram");
}
same[i] = rle_length;
i += rle_length - 2;
continue;
Expand Down
8 changes: 8 additions & 0 deletions pik/entropy_coder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,10 @@ bool DecodeQuantField(BitReader* PIK_RESTRICT br,
} else {
row_quant[bx] = UnpackSigned(q) + predicted_quant;
}
if (by + acs.covered_blocks_y() > ysize ||
bx + acs.covered_blocks_x() > xsize) {
return PIK_FAILURE("AC strategy extends outside quant field");
}
for (size_t iy = 0; iy < acs.covered_blocks_y(); iy++) {
for (size_t ix = 0; ix < acs.covered_blocks_x(); ix++) {
row_quant[bx + iy * stride + ix] = row_quant[bx];
Expand All @@ -998,6 +1002,10 @@ bool DecodeQuantField(BitReader* PIK_RESTRICT br,
} else {
row_quant[bx] = UnpackSigned(q) + predicted_quant;
}
if (by + acs.covered_blocks_y() > ysize ||
bx + acs.covered_blocks_x() > xsize) {
return PIK_FAILURE("AC strategy extends outside quant field");
}
for (size_t iy = 0; iy < acs.covered_blocks_y(); iy++) {
for (size_t ix = 0; ix < acs.covered_blocks_x(); ix++) {
row_quant[bx + iy * stride + ix] = row_quant[bx];
Expand Down
3 changes: 3 additions & 0 deletions pik/quant_weights.cc
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,9 @@ bool DecodeDequantControlField(BitReader* PIK_RESTRICT br,
for (size_t x = 0; x < dequant_cf->xsize(); ++x) {
br->FillBitBuffer();
row[x] = decoder.ReadSymbol(entropy, br);
if (row[x] >= kMaxQuantControlFieldValue) {
return PIK_FAILURE("dequant_cf value out of range");
}
}
}
PIK_RETURN_IF_ERROR(br->JumpToByteBoundary());
Expand Down