Index: src/main/java/common/java/awt/image/Raster.java =================================================================== --- src/main/java/common/java/awt/image/Raster.java (revision 504575) +++ src/main/java/common/java/awt/image/Raster.java (working copy) @@ -601,6 +601,19 @@ // awt.284=Overflow Y coordinate of Raster throw new RasterFormatException(Messages.getString("awt.284")); //$NON-NLS-1$ } + + if (sampleModel instanceof ComponentSampleModel) { + validateDataBuffer(dataBuffer, aRegion.width, aRegion.height, + ((ComponentSampleModel) sampleModel).getScanlineStride()); + } else if (sampleModel instanceof MultiPixelPackedSampleModel) { + validateDataBuffer(dataBuffer, aRegion.width, aRegion.height, + ((MultiPixelPackedSampleModel) sampleModel) + .getScanlineStride()); + } else if (sampleModel instanceof SinglePixelPackedSampleModel) { + validateDataBuffer(dataBuffer, aRegion.width, aRegion.height, + ((SinglePixelPackedSampleModel) sampleModel) + .getScanlineStride()); + } this.sampleModel = sampleModel; this.dataBuffer = dataBuffer; @@ -839,6 +852,13 @@ return width; } + private static void validateDataBuffer(final DataBuffer dataBuffer, final int w, + final int h, final int scanlineStride) { + if (dataBuffer.getSize() < (scanlineStride * (h - 1) + w - 1)) { + // awt.296=dataBuffer is too small + throw new RasterFormatException(Messages.getString("awt.296")); //$NON-NLS-1$ + } + } } Index: src/main/java/common/org/apache/harmony/awt/internal/nls/messages.properties =================================================================== --- src/main/java/common/org/apache/harmony/awt/internal/nls/messages.properties (revision 504575) +++ src/main/java/common/org/apache/harmony/awt/internal/nls/messages.properties (working copy) @@ -484,6 +484,7 @@ awt.292=Source and destination images do not have the same height! awt.294=pixel is null awt.295=data is null +awt.296=dataBuffer is too small awt.err.00=file dialog {0} error! awt.err.01=error: {0}