Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

patch for ArrayIndexOutOfBoundsException in BMP parser (may occur in case of malformed BMPs)

orbiterc7021c14bbfb
diff --git a/source/de/anomic/ymage/ymageBMPParser.java b/source/de/anomic/ymage/ymageBMPParser.java
index 4fd1205bf..bdee9c589 100644
--- a/source/de/anomic/ymage/ymageBMPParser.java
+++ b/source/de/anomic/ymage/ymageBMPParser.java
@@ -172,6 +172,7 @@ public class ymageBMPParser {
int b;
for (int rows = 0; rows < height; rows++) {
for (int columns = 0; columns < width; columns = columns + 8) {
+ if (offset + n >= s.length) return; // emergency break
b = (s[offset + n] & 0xff);
n++;
image.setRGB(columns, (height - rows - 1), colortable.colorindex[(b & 0x80) >> 7]);
@@ -192,6 +193,7 @@ public class ymageBMPParser {
int b;
for (int rows = 0; rows < height; rows++) {
for (int columns = 0; columns < width; columns = columns + 2) {
+ if (offset + n >= s.length) return; // emergency break
b = (s[offset + n] & 0xff);
n++;
image.setRGB(columns, (height - rows - 1), colortable.colorindex[(b & 0xf0) >> 4]);
@@ -205,6 +207,7 @@ public class ymageBMPParser {
int n = 0;
for (int rows = 0; rows < height; rows++) {
for (int columns = 0; columns < width; columns++) {
+ if (offset + n >= s.length) return; // emergency break
image.setRGB(columns, (height - rows - 1), colortable.colorindex[(s[offset + n] & 0xff)]);
n++;
}
@@ -216,6 +219,7 @@ public class ymageBMPParser {
int n = 0;
for (int rows = 0; rows < height; rows++) {
for (int columns = 0; columns < width; columns++) {
+ if (offset + n + 3 >= s.length) return; // emergency break
image.setRGB(columns, (height - rows - 1), 0xffffff & DWORD(s, offset + n));
n += 3;
}
@@ -227,6 +231,7 @@ public class ymageBMPParser {
int n = 0;
for (int rows = 0; rows < height; rows++) {
for (int columns = 0; columns < width; columns++) {
+ if (offset + n + 3 >= s.length) return; // emergency break
image.setRGB(columns, (height - rows - 1), 0xffffff & DWORD(s, offset + n));
n += 4;
}