Author: tilman
Date: Tue Jan 6 11:07:27 2026
New Revision: 1931149
Log:
PDFBOX-6141: avoid NegativeArraySizeException
Modified:
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/filter/Predictor.java
Modified:
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/filter/Predictor.java
==============================================================================
---
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/filter/Predictor.java
Tue Jan 6 11:02:20 2026 (r1931148)
+++
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/filter/Predictor.java
Tue Jan 6 11:07:27 2026 (r1931149)
@@ -231,8 +231,9 @@ public final class Predictor
* @param decodeParams Decode parameters for the stream
* @return An <code>OutputStream</code> is returned, which will write
decoded data
* into the given stream. If no predictor is specified, the original
stream is returned.
+ * @throws IOException
*/
- static OutputStream wrapPredictor(OutputStream out, COSDictionary
decodeParams)
+ static OutputStream wrapPredictor(OutputStream out, COSDictionary
decodeParams) throws IOException
{
int predictor = decodeParams.getInt(COSName.PREDICTOR);
if (predictor > 1)
@@ -276,6 +277,7 @@ public final class Predictor
private boolean predictorRead = false;
PredictorOutputStream(OutputStream out, int predictor, int colors, int
bitsPerComponent, int columns)
+ throws IOException
{
super(out);
this.predictor = predictor;
@@ -283,6 +285,10 @@ public final class Predictor
this.bitsPerComponent = bitsPerComponent;
this.columns = columns;
this.rowLength = calculateRowLength(colors, bitsPerComponent,
columns);
+ if (rowLength < 0)
+ {
+ throw new IOException("Calculated row length is negative: " +
rowLength);
+ }
this.predictorPerRow = predictor >= 10;
currentRow = new byte[rowLength];
lastRow = new byte[rowLength];