diff options
Diffstat (limited to 'java/TJBench.java')
| -rw-r--r-- | java/TJBench.java | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/java/TJBench.java b/java/TJBench.java index 7829e53c..cc3178ea 100644 --- a/java/TJBench.java +++ b/java/TJBench.java @@ -121,6 +121,8 @@ final class TJBench { int rindex = TJ.getRedOffset(pixelFormat); int gindex = TJ.getGreenOffset(pixelFormat); int bindex = TJ.getBlueOffset(pixelFormat); + if ((long)w[0] * (long)h[0] * (long)ps > (long)Integer.MAX_VALUE) + throw new Exception("Image is too large"); byte[] dstBuf = new byte[w[0] * h[0] * ps]; int pixels = w[0] * h[0], dstPtr = 0, rgbPtr = 0; @@ -175,8 +177,11 @@ final class TJBench { tjd = new TJDecompressor(); - if (dstBuf == null) + if (dstBuf == null) { + if ((long)pitch * (long)scaledh > (long)Integer.MAX_VALUE) + throw new Exception("Image is too large"); dstBuf = new byte[pitch * scaledh]; + } /* Set the destination buffer to gray so we know whether the decompressor attempted to write to it */ @@ -331,6 +336,8 @@ final class TJBench { String pfStr = PIXFORMATSTR[pf]; YUVImage yuvImage = null; + if ((long)pitch * (long)h > (long)Integer.MAX_VALUE) + throw new Exception("Image is too large"); tmpBuf = new byte[pitch * h]; if (quiet == 0) @@ -491,6 +498,8 @@ final class TJBench { int tw, th, ttilew, ttileh, tntilesw, tntilesh, tsubsamp; FileInputStream fis = new FileInputStream(fileName); + if (fis.getChannel().size() > (long)Integer.MAX_VALUE) + throw new Exception("Image is too large"); int srcSize = (int)fis.getChannel().size(); srcBuf = new byte[srcSize]; fis.read(srcBuf, 0, srcSize); |
