As indicated in the JBS bug, using a `PixelReader` to read a scaled image in 
HiDPI mode, for example an `@2x` image, to read more than one pixel will read 
data from the wrong location in the image, usually leading to an IOOBE.

The bug is in the `getPixelAccessor` method of Prism Image. The method 
correctly creates a new `Accessor` if one hasn't already been created, but then 
it unconditionally wraps the current `Accessor` in a `ScaledPixelAccessor` if 
the scale is > 1. So the second time this method is called, it created another 
`ScaledPixelAccessor` that wraps the first `ScaledPixelAccessor`, meaning that 
the indexes into the pixel array are multiplied by 4. This continues for each 
new call to this method.

The fix is to only wrap an `Accessor` in a `ScaledPixelAccessor` the first 
time, when it is created.

I added a test, which is run for both scaled and unscaled images, to ensure 
that we get the right value when reading a pixel, and that reading it a second 
time returns the same result. Without the fix, the new test will fail with 
IOOBE when the scale factor is two. Related to this, I initially commented out 
the wrapping in a  `ScaledPixelAccessor` entirely, just to see what would 
happen, and none of the existing tests caught it. The new test will catch this.

-------------

Commit messages:
 - 8258986: getColor throws IOOBE when PixelReader reads the same pixel twice

Changes: https://git.openjdk.java.net/jfx/pull/389/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jfx&pr=389&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8258986
  Stats: 160 lines in 4 files changed: 157 ins; 0 del; 3 mod
  Patch: https://git.openjdk.java.net/jfx/pull/389.diff
  Fetch: git fetch https://git.openjdk.java.net/jfx pull/389/head:pull/389

PR: https://git.openjdk.java.net/jfx/pull/389

Reply via email to