Skip to content

Commit 2044ce3

Browse files
committed
PDFBOX-6141: avoid NegativeArraySizeException
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1931150 13f79535-47bb-0310-9956-ffa450edef68
1 parent 595d382 commit 2044ce3

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

pdfbox/src/main/java/org/apache/pdfbox/filter/Predictor.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,9 @@ static int calcSetBitSeq(int by, int startBit, int bitSize, int val)
231231
* @param decodeParams Decode parameters for the stream
232232
* @return An <code>OutputStream</code> is returned, which will write decoded data
233233
* into the given stream. If no predictor is specified, the original stream is returned.
234+
* @throws IOException
234235
*/
235-
static OutputStream wrapPredictor(OutputStream out, COSDictionary decodeParams)
236+
static OutputStream wrapPredictor(OutputStream out, COSDictionary decodeParams) throws IOException
236237
{
237238
int predictor = decodeParams.getInt(COSName.PREDICTOR);
238239
if (predictor > 1)
@@ -276,13 +277,18 @@ private static final class PredictorOutputStream extends FilterOutputStream
276277
private boolean predictorRead = false;
277278

278279
PredictorOutputStream(OutputStream out, int predictor, int colors, int bitsPerComponent, int columns)
280+
throws IOException
279281
{
280282
super(out);
281283
this.predictor = predictor;
282284
this.colors = colors;
283285
this.bitsPerComponent = bitsPerComponent;
284286
this.columns = columns;
285287
this.rowLength = calculateRowLength(colors, bitsPerComponent, columns);
288+
if (rowLength < 0)
289+
{
290+
throw new IOException("Calculated row length is negative: " + rowLength);
291+
}
286292
this.predictorPerRow = predictor >= 10;
287293
currentRow = new byte[rowLength];
288294
lastRow = new byte[rowLength];

0 commit comments

Comments
 (0)