This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pdfbox-jbig2.git
The following commit(s) were added to refs/heads/master by this push:
new eeea7fb PDFBOX-6162: Fix IAID decoding by masking context index to
lower N bits and preventing integer overflow in shifts
eeea7fb is described below
commit eeea7fb822223253c6eba8f96c1e4752540f5ed0
Author: Maruan Sahyoun <[email protected]>
AuthorDate: Tue Apr 21 11:02:00 2026 +0200
PDFBOX-6162: Fix IAID decoding by masking context index to lower N bits and
preventing integer overflow in shifts
---
.../jbig2/decoder/arithmetic/ArithmeticIntegerDecoder.java | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git
a/src/main/java/org/apache/pdfbox/jbig2/decoder/arithmetic/ArithmeticIntegerDecoder.java
b/src/main/java/org/apache/pdfbox/jbig2/decoder/arithmetic/ArithmeticIntegerDecoder.java
index 8ef9b56..5ba42c3 100644
---
a/src/main/java/org/apache/pdfbox/jbig2/decoder/arithmetic/ArithmeticIntegerDecoder.java
+++
b/src/main/java/org/apache/pdfbox/jbig2/decoder/arithmetic/ArithmeticIntegerDecoder.java
@@ -170,16 +170,24 @@ public class ArithmeticIntegerDecoder
public int decodeIAID(CX cxIAID, long symCodeLen) throws IOException
{
// A.3 1)
- prev = 1;
+ long prev = 1;
+
// A.3 2)
+ // The spec says: "the rightmost SBSYMCODELEN + 1 bits of PREV are
used"
+ // But also: "The number of contexts required is 2^SBSYMCODELEN"
+ // The resolution: the leading 1 bit is not used for context
+ // identification—only the lower N bits are.
+
+ long mask = (1L << symCodeLen) - 1;
+
for (int i = 0; i < symCodeLen; i++)
{
- cxIAID.setIndex(prev);
+ cxIAID.setIndex((int) (prev & mask));
prev = (prev << 1) | decoder.decode(cxIAID);
}
// A.3 3) & 4)
- return (prev - (1 << symCodeLen));
+ return (int) (prev - (1L << symCodeLen));
}
}