Skip to content

Commit afc39b3

Browse files
committed
PDFBOX-5991: prevent negative array size
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1925212 13f79535-47bb-0310-9956-ffa450edef68
1 parent 369ea23 commit afc39b3

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

fontbox/src/main/java/org/apache/fontbox/ttf/RandomAccessReadDataStream.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ class RandomAccessReadDataStream extends TTFDataStream
4949
RandomAccessReadDataStream(RandomAccessRead randomAccessRead) throws IOException
5050
{
5151
length = randomAccessRead.length();
52+
if (length > Integer.MAX_VALUE - 8) // https://www.baeldung.com/java-arrays-max-size
53+
{
54+
// PDFBOX-5991
55+
throw new IOException("Stream is too long, size: " + length);
56+
}
5257
data = new byte[(int) length];
5358
int remainingBytes = data.length;
5459
int amountRead;

0 commit comments

Comments
 (0)