From e72587a455c946e82a101ba68e85e13855303c62 Mon Sep 17 00:00:00 2001 From: Arnaud Lacombe Date: Mon, 23 Feb 2015 12:18:28 -0800 Subject: [PATCH] ExifImage: try to handle incorrect IFD format more gracefully Test image provided in https://github.com/gomfunkel/node-exif/pull/14. --- lib/exif/ExifImage.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/exif/ExifImage.js b/lib/exif/ExifImage.js index 31bc7f4..b2156c2 100644 --- a/lib/exif/ExifImage.js +++ b/lib/exif/ExifImage.js @@ -346,6 +346,9 @@ ExifImage.prototype.extractExifIFDEntries = function (data, offset, store, tags) { var entryCount = data.readUInt16(offset) + if (entryCount * 12 > data.length) + throw new Error("Invalid number of IFD entries") + for (var i = 0; i < entryCount; i++) { var start = offset + 2 + (i * 12) var entry = this.extractExifEntry(data, start, tags) @@ -385,6 +388,9 @@ ExifImage.prototype.extractExifEntry = function (data, entryOffset, tags) } type = ExifImage.TIFFTYPES[field.type] + if (type == undefined) + return false + type.size = type.len * type.count offset = entryOffset + 8