Skip to content

Commit

Permalink
Avoid crashes due to broken map data
Browse files Browse the repository at this point in the history
  • Loading branch information
Hypfer committed Mar 23, 2019
1 parent 053fa00 commit e136443
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions lib/Tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,10 +454,16 @@ const Tools = {
if (err) {
callback(err);
} else {
callback(null, {
mapData: Tools.PARSE_PPM_MAP(unzippedFile),
log: log,
})
var parsedMapData = Tools.PARSE_PPM_MAP(unzippedFile);

if(parsedMapData.map.length === 0) {
callback(new Error("No usable map data found"));
} else {
callback(null, {
mapData: parsedMapData,
log: log,
})
}
}
});
}
Expand Down Expand Up @@ -526,15 +532,13 @@ const Tools = {
PARSE_PPM_MAP: function (buf) {
const map = [];

if (buf.length === CORRECT_PPM_MAP_FILE_SIZE) {
for (let i = 17, j = 0; i <= buf.length - 16; i += 3, j++) {
let r = buf.readUInt8(i);
let g = buf.readUInt8(i + 1);
let b = buf.readUInt8(i + 2);
for (let i = 17, j = 0; i <= buf.length - 16; i += 3, j++) {
let r = buf.readUInt8(i);
let g = buf.readUInt8(i + 1);
let b = buf.readUInt8(i + 2);

if (!(r === 125 && g === 125 && b === 125)) {
map.push([j + j * 3, r, g, b])
}
if (!(r === 125 && g === 125 && b === 125)) {
map.push([j + j * 3, r, g, b])
}
}

Expand Down

0 comments on commit e136443

Please sign in to comment.