This is an automated email from the ASF dual-hosted git repository.
tilman 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 b9f37b2 PDFBOX-6151: check symInRefSize; add override; remove final
when private
b9f37b2 is described below
commit b9f37b29b91c45a830b170a400c239fbd7ba3ca7
Author: Tilman Hausherr <[email protected]>
AuthorDate: Sat Jan 31 15:33:10 2026 +0100
PDFBOX-6151: check symInRefSize; add override; remove final when private
---
.../pdfbox/jbig2/segments/SymbolDictionary.java | 41 +++++++++++++---------
.../apache/pdfbox/jbig2/segments/TextRegion.java | 41 +++++++++++++---------
2 files changed, 50 insertions(+), 32 deletions(-)
diff --git
a/src/main/java/org/apache/pdfbox/jbig2/segments/SymbolDictionary.java
b/src/main/java/org/apache/pdfbox/jbig2/segments/SymbolDictionary.java
index 5837b7c..4ec5ef5 100644
--- a/src/main/java/org/apache/pdfbox/jbig2/segments/SymbolDictionary.java
+++ b/src/main/java/org/apache/pdfbox/jbig2/segments/SymbolDictionary.java
@@ -345,6 +345,7 @@ public class SymbolDictionary implements Dictionary
*
* @return List of decoded symbol bitmaps as an <code>ArrayList</code>
*/
+ @Override
public ArrayList<Bitmap> getDictionary()
throws IOException, IntegerMaxValueException,
InvalidHeaderValueException
{
@@ -519,7 +520,7 @@ public class SymbolDictionary implements Dictionary
}
- private final void decodeHeightClassBitmap(final Bitmap
heightClassCollectiveBitmap,
+ private void decodeHeightClassBitmap(final Bitmap
heightClassCollectiveBitmap,
final int heightClassFirstSymbol, final int heightClassHeight,
final int[] newSymbolsWidths)
throws IntegerMaxValueException, InvalidHeaderValueException,
IOException
@@ -542,7 +543,7 @@ public class SymbolDictionary implements Dictionary
}
}
- private final void decodeAggregate(final int symbolWidth, final int
heightClassHeight)
+ private void decodeAggregate(final int symbolWidth, final int
heightClassHeight)
throws IOException, InvalidHeaderValueException,
IntegerMaxValueException
{
// 6.5.8.2 1)
@@ -570,7 +571,7 @@ public class SymbolDictionary implements Dictionary
}
}
- private final long huffDecodeRefAggNInst() throws IOException,
InvalidHeaderValueException
+ private long huffDecodeRefAggNInst() throws IOException,
InvalidHeaderValueException
{
if (sdHuffAggInstanceSelection == 0)
{
@@ -602,7 +603,7 @@ public class SymbolDictionary implements Dictionary
return 0;
}
- private final void decodeThroughTextRegion(final int symbolWidth, final
int heightClassHeight,
+ private void decodeThroughTextRegion(final int symbolWidth, final int
heightClassHeight,
final long amountOfRefinementAggregationInstances)
throws IOException, IntegerMaxValueException,
InvalidHeaderValueException
{
@@ -637,14 +638,15 @@ public class SymbolDictionary implements Dictionary
addSymbol(textRegion);
}
- private final void decodeRefinedSymbol(final int symbolWidth, final int
heightClassHeight)
+ private void decodeRefinedSymbol(final int symbolWidth, final int
heightClassHeight)
throws IOException, InvalidHeaderValueException,
IntegerMaxValueException
{
final int id;
final int rdx;
final int rdy;
- // long symInRefSize = 0;
+ long symInRefSize = 0;
+ long streamPosition0 = 0;
if (isHuffmanEncoded)
{
/* 2) - 4) */
@@ -652,8 +654,10 @@ public class SymbolDictionary implements Dictionary
rdx = (int) StandardTables.getTable(15).decode(subInputStream);
rdy = (int) StandardTables.getTable(15).decode(subInputStream);
+ streamPosition0 = subInputStream.getStreamPosition();
+
/* 5) a) */
- /* symInRefSize =
*/StandardTables.getTable(1).decode(subInputStream);
+ symInRefSize = StandardTables.getTable(1).decode(subInputStream);
/* 5) b) - Skip over remaining bits */
subInputStream.skipBits();
@@ -676,10 +680,15 @@ public class SymbolDictionary implements Dictionary
{
subInputStream.skipBits();
// Make sure that the processed bytes are equal to the value read
in step 5 a)
+ if (subInputStream.getStreamPosition() != streamPosition0 +
symInRefSize)
+ {
+ throw new IOException("Refinement bitmap bytes expected: " +
symInRefSize +
+ ", bytes read: " + (subInputStream.getStreamPosition()
- streamPosition0));
+ }
}
}
- private final void decodeNewSymbols(final int symWidth, final int
hcHeight, final Bitmap ibo,
+ private void decodeNewSymbols(final int symWidth, final int hcHeight,
final Bitmap ibo,
final int rdx, final int rdy)
throws IOException, InvalidHeaderValueException,
IntegerMaxValueException
{
@@ -705,7 +714,7 @@ public class SymbolDictionary implements Dictionary
addSymbol(genericRefinementRegion);
}
- private final void decodeDirectlyThroughGenericRegion(final int symWidth,
final int hcHeight)
+ private void decodeDirectlyThroughGenericRegion(final int symWidth, final
int hcHeight)
throws IOException, IntegerMaxValueException,
InvalidHeaderValueException
{
if (genericRegion == null)
@@ -720,7 +729,7 @@ public class SymbolDictionary implements Dictionary
addSymbol(genericRegion);
}
- private final void addSymbol(final Region region)
+ private void addSymbol(final Region region)
throws IntegerMaxValueException, InvalidHeaderValueException,
IOException
{
final Bitmap symbol = region.getRegionBitmap();
@@ -728,7 +737,7 @@ public class SymbolDictionary implements Dictionary
sbSymbols.add(symbol);
}
- private final long decodeDifferenceWidth() throws IOException,
InvalidHeaderValueException
+ private long decodeDifferenceWidth() throws IOException,
InvalidHeaderValueException
{
if (isHuffmanEncoded)
{
@@ -760,7 +769,7 @@ public class SymbolDictionary implements Dictionary
return 0;
}
- private final long decodeHeightClassDeltaHeight()
+ private long decodeHeightClassDeltaHeight()
throws IOException, InvalidHeaderValueException
{
if (isHuffmanEncoded)
@@ -780,7 +789,7 @@ public class SymbolDictionary implements Dictionary
* @throws IOException
* @throws InvalidHeaderValueException
*/
- private final long decodeHeightClassDeltaHeightWithHuffman()
+ private long decodeHeightClassDeltaHeightWithHuffman()
throws IOException, InvalidHeaderValueException
{
switch (sdHuffDecodeHeightSelection)
@@ -800,7 +809,7 @@ public class SymbolDictionary implements Dictionary
return 0;
}
- private final Bitmap decodeHeightClassCollectiveBitmap(final long bmSize,
+ private Bitmap decodeHeightClassCollectiveBitmap(final long bmSize,
final int heightClassHeight, final int totalWidth) throws
IOException
{
if (bmSize == 0)
@@ -882,7 +891,7 @@ public class SymbolDictionary implements Dictionary
return exportFlags;
}
- private final long huffDecodeBmSize() throws IOException,
InvalidHeaderValueException
+ private long huffDecodeBmSize() throws IOException,
InvalidHeaderValueException
{
if (bmSizeTable == null)
{
@@ -932,7 +941,7 @@ public class SymbolDictionary implements Dictionary
* @throws InvalidHeaderValueException
* @throws IntegerMaxValueException
*/
- private final void setSymbolsArray()
+ private void setSymbolsArray()
throws IOException, InvalidHeaderValueException,
IntegerMaxValueException
{
if (importSymbols == null)
diff --git a/src/main/java/org/apache/pdfbox/jbig2/segments/TextRegion.java
b/src/main/java/org/apache/pdfbox/jbig2/segments/TextRegion.java
index 9fc0ea6..942b7df 100644
--- a/src/main/java/org/apache/pdfbox/jbig2/segments/TextRegion.java
+++ b/src/main/java/org/apache/pdfbox/jbig2/segments/TextRegion.java
@@ -320,6 +320,7 @@ public class TextRegion implements Region
}
}
+ @Override
public Bitmap getRegionBitmap()
throws IOException, IntegerMaxValueException,
InvalidHeaderValueException
{
@@ -390,7 +391,7 @@ public class TextRegion implements Region
}
}
- private final long decodeStripT() throws IOException,
InvalidHeaderValueException
+ private long decodeStripT() throws IOException, InvalidHeaderValueException
{
long stripT = 0;
@@ -506,7 +507,7 @@ public class TextRegion implements Region
}
}
- private final long decodeDT() throws IOException
+ private long decodeDT() throws IOException
{
/* 3) b) */
/* 6.4.6 */
@@ -530,7 +531,7 @@ public class TextRegion implements Region
return (dT * sbStrips);
}
- private final long decodeDfS() throws IOException,
InvalidHeaderValueException
+ private long decodeDfS() throws IOException, InvalidHeaderValueException
{
if (isHuffmanEncoded)
{
@@ -553,7 +554,7 @@ public class TextRegion implements Region
}
}
- private final long decodeIdS() throws IOException,
InvalidHeaderValueException
+ private long decodeIdS() throws IOException, InvalidHeaderValueException
{
if (isHuffmanEncoded)
{
@@ -584,7 +585,7 @@ public class TextRegion implements Region
}
}
- private final long decodeCurrentT() throws IOException
+ private long decodeCurrentT() throws IOException
{
if (sbStrips != 1)
{
@@ -601,7 +602,7 @@ public class TextRegion implements Region
return 0;
}
- private final long decodeID() throws IOException
+ private long decodeID() throws IOException
{
if (isHuffmanEncoded)
{
@@ -618,7 +619,7 @@ public class TextRegion implements Region
}
}
- private final long decodeRI() throws IOException
+ private long decodeRI() throws IOException
{
if (useRefinement)
{
@@ -634,7 +635,7 @@ public class TextRegion implements Region
return 0;
}
- private final Bitmap decodeIb(long r, long id)
+ private Bitmap decodeIb(long r, long id)
throws IOException, InvalidHeaderValueException,
IntegerMaxValueException
{
Bitmap ib;
@@ -652,10 +653,11 @@ public class TextRegion implements Region
final long rdy = decodeRdy();
/* 5) */
- /* long symInRefSize = 0; */
+ long symInRefSize = 0;
+ long streamPosition0 = subInputStream.getStreamPosition();
if (isHuffmanEncoded)
{
- /* symInRefSize = */decodeSymInRefSize();
+ symInRefSize = decodeSymInRefSize();
subInputStream.skipBits();
}
@@ -682,12 +684,17 @@ public class TextRegion implements Region
if (isHuffmanEncoded)
{
subInputStream.skipBits();
+ if (subInputStream.getStreamPosition() != streamPosition0 +
symInRefSize)
+ {
+ throw new IOException("Refinement bitmap bytes expected: "
+ symInRefSize +
+ ", bytes read: " +
(subInputStream.getStreamPosition() - streamPosition0));
+ }
}
}
return ib;
}
- private final long decodeRdw() throws IOException,
InvalidHeaderValueException
+ private long decodeRdw() throws IOException, InvalidHeaderValueException
{
if (isHuffmanEncoded)
{
@@ -728,7 +735,7 @@ public class TextRegion implements Region
}
}
- private final long decodeRdh() throws IOException,
InvalidHeaderValueException
+ private long decodeRdh() throws IOException, InvalidHeaderValueException
{
if (isHuffmanEncoded)
{
@@ -773,7 +780,7 @@ public class TextRegion implements Region
}
}
- private final long decodeRdx() throws IOException,
InvalidHeaderValueException
+ private long decodeRdx() throws IOException, InvalidHeaderValueException
{
if (isHuffmanEncoded)
{
@@ -822,7 +829,7 @@ public class TextRegion implements Region
}
}
- private final long decodeRdy() throws IOException,
InvalidHeaderValueException
+ private long decodeRdy() throws IOException, InvalidHeaderValueException
{
if (isHuffmanEncoded)
{
@@ -876,7 +883,7 @@ public class TextRegion implements Region
}
}
- private final long decodeSymInRefSize() throws IOException,
InvalidHeaderValueException
+ private long decodeSymInRefSize() throws IOException,
InvalidHeaderValueException
{
if (sbHuffRSize == 0)
{
@@ -930,7 +937,7 @@ public class TextRegion implements Region
}
- private final void blit(Bitmap ib, long t)
+ private void blit(Bitmap ib, long t)
{
if (isTransposed == 0 && (referenceCorner == 2 || referenceCorner ==
3))
{
@@ -1101,6 +1108,7 @@ public class TextRegion implements Region
}
+ @Override
public void init(SegmentHeader header, SubInputStream sis)
throws InvalidHeaderValueException, IntegerMaxValueException,
IOException
{
@@ -1175,6 +1183,7 @@ public class TextRegion implements Region
this.symbolCodeLength = sbSymCodeLen;
}
+ @Override
public RegionSegmentInformation getRegionInfo()
{
return regionInfo;