Skip to content

Commit 8368b9e

Browse files
committed
Area Viewer: Fix read errors for maps with truncated explored bitmaps
1 parent fc5e224 commit 8368b9e

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/org/infinity/resource/are/viewer/AreaViewer.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3633,14 +3633,18 @@ private static GraphicsResource generateExploredMap(AreResource are, WedResource
36333633
final int[] pixels = ((DataBufferInt)image.getRaster().getDataBuffer()).getData();
36343634
final int colUnexplored = 0xff000000;
36353635
final int colExplored = 0;
3636-
for (int y = 0; y < cellsHeight; y++) {
3637-
for (int x = 0; x < cellsWidth; x++) {
3636+
boolean isValidOffset = data.limit() > 0;
3637+
for (int y = 0; y < cellsHeight && isValidOffset; y++) {
3638+
for (int x = 0; x < cellsWidth && isValidOffset; x++) {
36383639
final int ofs = x + y * cellsWidthRaw;
3639-
final int bytePos = ofs / 8;
3640+
final int bytePos = ofs >> 3;
36403641
final int bitPos = ofs & 7;
3641-
final boolean isExplored = ((data.get(bytePos) >> bitPos) & 1) != 0;
3642-
final int ofsPixel = x + y * cellsWidth;
3643-
pixels[ofsPixel] = isExplored ? colExplored : colUnexplored;
3642+
isValidOffset = bytePos < data.limit();
3643+
if (isValidOffset) {
3644+
final boolean isExplored = ((data.get(bytePos) >> bitPos) & 1) != 0;
3645+
final int ofsPixel = x + y * cellsWidth;
3646+
pixels[ofsPixel] = isExplored ? colExplored : colUnexplored;
3647+
}
36443648
}
36453649
}
36463650

0 commit comments

Comments
 (0)