Skip to content

Commit 13751f5

Browse files
Fix/shorten rice golomb k bounds (#1335)
* Shorten: Reject out-of-range k in getRiceGolombCode k values outside [0, 31] cause undefined behavior: a left shift by 32 on int32_t (UB in C++) when bitsAvailable reaches 32 after a buffer refill. Guard against this at the top of getRiceGolombCode and return false (invalid file) for any k outside the valid range. * Shorten: Reject out-of-range k in getRiceGolombCode k values outside [0, 31] cause undefined behavior: a left shift by 32 on int32_t (UB in C++) when bitsAvailable reaches 32 after a buffer refill. Guard against this at the top of getRiceGolombCode and return false (invalid file) for any k outside the valid range.
1 parent 4da5ac2 commit 13751f5

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

taglib/shorten/shortenfile.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ namespace {
104104

105105
bool VariableLengthInput::getRiceGolombCode(int32_t &i32, int32_t k)
106106
{
107+
// k must be in [0, 31]: values outside this range would cause shift-by-32
108+
// (UB for int32_t) or negative shifts, and are invalid for this format.
109+
if(k < 0 || k > 31)
110+
return false;
111+
107112
static constexpr uint32_t sMaskTable[] = {
108113
0x0,
109114
0x1, 0x3, 0x7, 0xf,

0 commit comments

Comments
 (0)