8272462: Enhance image handling

Reviewed-by: yan
This commit is contained in:
Aleksei Voitylov 2021-12-16 20:37:07 +03:00
parent a8484d332d
commit ebeadc89d3
3 changed files with 20 additions and 1 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -956,6 +956,11 @@ public class GIFImageReader extends ImageReader {
}
}
if (tableIndex >= prefix.length) {
throw new IIOException("Code buffer limit reached,"
+ " no End of Image tag present, possibly data is corrupted. ");
}
int ti = tableIndex;
int oc = oldCode;

View File

@ -1082,6 +1082,13 @@ public class JPEGImageReader extends ImageReader {
throw new IIOException("Unsupported Image Type");
}
if ((long)width * height > Integer.MAX_VALUE - 2) {
// We are not able to properly decode image that has number
// of pixels greater than Integer.MAX_VALUE - 2
throw new IIOException("Can not read image of the size "
+ width + " by " + height);
}
image = getDestination(param, imageTypes, width, height);
imRas = image.getRaster();

View File

@ -1239,6 +1239,13 @@ public class PNGImageReader extends ImageReader {
int width = metadata.IHDR_width;
int height = metadata.IHDR_height;
if ((long)width * height > Integer.MAX_VALUE - 2) {
// We are not able to properly decode image that has number
// of pixels greater than Integer.MAX_VALUE - 2
throw new IIOException("Can not read image of the size "
+ width + " by " + height);
}
// Init default values
sourceXSubsampling = 1;
sourceYSubsampling = 1;