diff options
author | Sven Gothel <[email protected]> | 2013-09-04 16:24:02 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2013-09-04 16:24:02 +0200 |
commit | b02fb06099e36b678a54f9ce26d127042f95e44f (patch) | |
tree | 1337216fb768305a2082621611edc575e6c9d262 /src/jogl | |
parent | b33bdf41cf53f37203643a8551bf5d94b42a8fab (diff) |
PNGImage: Bounds check in getPixelRGBA8(..) and setPixelRGBA8(..)
Diffstat (limited to 'src/jogl')
-rw-r--r-- | src/jogl/classes/com/jogamp/opengl/util/texture/spi/PNGImage.java | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/PNGImage.java b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/PNGImage.java index 93d37029e..0f4559036 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/PNGImage.java +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/PNGImage.java @@ -87,6 +87,10 @@ public class PNGImage { /** Reverse read and store, implicitly flip image to GL orientation, see {@link #isGLOriented()}. */ private static final int getPixelRGBA8(ByteBuffer d, int dOff, int[] scanline, int lineOff, boolean hasAlpha) { + final int b = hasAlpha ? 4-1 : 3-1; + if( d.limit() <= dOff || dOff - b < 0 ) { + throw new IndexOutOfBoundsException("Buffer has unsufficient bytes left, needs ["+(dOff-b)+".."+dOff+"]: "+d); + } if(hasAlpha) { d.put(dOff--, (byte)scanline[lineOff + 3]); // A } @@ -98,6 +102,10 @@ public class PNGImage { /** Reverse write and store, implicitly flip image from current orientation, see {@link #isGLOriented()}. Handle reversed channels (BGR[A]). */ private int setPixelRGBA8(ImageLine line, int lineOff, ByteBuffer d, int dOff, boolean hasAlpha) { + final int b = hasAlpha ? 4-1 : 3-1; + if( d.limit() <= dOff + b ) { + throw new IndexOutOfBoundsException("Buffer has unsufficient bytes left, needs ["+dOff+".."+(dOff+b)+"]: "+d); + } if( reversedChannels ) { if(hasAlpha) { line.scanline[lineOff + 3] = d.get(dOff++); // A |