Bounds checks in NativeImage
are incorrect, and it uses UNSAFE to directly access memory, so misusing it can cause the JRE to completely crash instead of throwing an exception. As far as I am aware, this bug is not currently being triggered by any vanilla code that calls NativeImage
.
NativeImage should check that x
and y
are both >= 0
.
The checks for x <= width
should be x < width
and the checks for y <= height
should be y < height
.
Affected methods:
NativeImage.getPixelRGBA(int, int)
NativeImage.setPixelRGBA(int, int, int)
NativeImage.getLuminanceOrAlpha(int, int)
Note: These methods do not check for negative x
or y
values either.
Comments 2
These were found by examination of the code. The bound checks are off-by-one (e.g. checking <= width instead of < width). It affects the game since at any time it can cause the JVM to crash completely without the usual exception and stacktrace (since it's a native crash not a Java crash). Not to mention it's highly unsafe and could be a security vulnerability if a read somehow extends past the NativeImage buffer and reads sensitive data next to it in the native heap.
What exactly is your issue? Why are the bounds checks incorrect? How does that affect the vanilla game?