--- old/src/java.desktop/share/classes/com/sun/imageio/plugins/png/PNGImageReader.java 2017-11-16 14:01:33.187418000 +0530 +++ new/src/java.desktop/share/classes/com/sun/imageio/plugins/png/PNGImageReader.java 2017-11-16 14:01:32.567107999 +0530 @@ -1359,14 +1359,18 @@ this.pixelStream = new DataInputStream(is); /* - * NB: the PNG spec declares that valid range for width + * PNG spec declares that valid range for width * and height is [1, 2^31-1], so here we may fail to allocate * a buffer for destination image due to memory limitation. * - * However, the recovery strategy for this case should be - * defined on the level of application, so we will not - * try to estimate the required amount of the memory and/or - * handle OOM in any way. + * If the read operation triggers OutOfMemoryError, the same + * will be wrapped in an IIOException at PNGImageReader.read + * method. + * + * The recovery strategy for this case should be defined at + * the level of application, so we will not try to estimate + * the required amount of the memory and/or handle OOM in + * any way. */ theImage = getDestination(param, getImageTypes(0), @@ -1671,7 +1675,16 @@ throw new IndexOutOfBoundsException("imageIndex != 0!"); } - readImage(param); + try { + readImage(param); + } catch (IOException | + IllegalStateException | + IllegalArgumentException e) + { + throw e; + } catch (Throwable e) { + throw new IIOException("Caught exception during read: ", e); + } return theImage; }