Skip to content

Commit f9f8f0e

Browse files
committed
Fix negative dataOffset
1 parent b9bc986 commit f9f8f0e

File tree

3 files changed

+6
-11
lines changed

3 files changed

+6
-11
lines changed

src/markers/exif.js

+6-11
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class IDFEntries {
195195
}
196196

197197
_decodeIDFEntries(buffer, tags, offset, log = false) {
198-
let pos = 2;
198+
let pos = 2 + offset;
199199

200200
const entries = {};
201201

@@ -205,7 +205,7 @@ class IDFEntries {
205205
const uint32 = (pos) =>
206206
this.bigEndian ? readUInt32BE(buffer, pos) : readUInt32LE(buffer, pos);
207207

208-
const numberOfEntries = uint16(0);
208+
const numberOfEntries = uint16(offset);
209209

210210
for (let i = 0; i < numberOfEntries; i++) {
211211
const tagAddress = buffer.slice(pos, pos + 2);
@@ -217,12 +217,10 @@ class IDFEntries {
217217
let dataValue = buffer.slice(pos + 8, pos + 12);
218218

219219
if (dataLength > 4) {
220-
const valueOffset = this.bigEndian
220+
const dataOffset = this.bigEndian
221221
? readUInt32BE(dataValue, 0)
222222
: readUInt32LE(dataValue, 0);
223223

224-
const dataOffset = valueOffset - offset;
225-
226224
dataValue = buffer.slice(dataOffset, dataOffset + dataLength);
227225
}
228226

@@ -251,23 +249,20 @@ class IDFEntries {
251249
return {};
252250
}
253251

254-
const firstIFDBuffer = buffer.slice(offsetToFirstIFD);
255-
const entries = this._decodeIDFEntries(firstIFDBuffer, tags.ifd, offsetToFirstIFD);
252+
const entries = this._decodeIDFEntries(buffer, tags.ifd, offsetToFirstIFD);
256253
const { exifIFDPointer, gpsInfoIFDPointer } = entries;
257254

258255
if (exifIFDPointer) {
259-
const exifIFDBuffer = buffer.slice(exifIFDPointer);
260256
entries.subExif = this._decodeIDFEntries(
261-
exifIFDBuffer,
257+
buffer,
262258
tags.ifd,
263259
exifIFDPointer,
264260
);
265261
}
266262

267263
if (gpsInfoIFDPointer) {
268264
const gps = gpsInfoIFDPointer;
269-
const gpsBuffer = buffer.slice(gps);
270-
entries.gpsInfo = this._decodeIDFEntries(gpsBuffer, tags.gps, gps, true);
265+
entries.gpsInfo = this._decodeIDFEntries(buffer, tags.gps, gps, true);
271266
}
272267

273268
stream.pos += parent.parent.length - 16;
93.3 KB
Binary file not shown.

tests/images/image-31.jpg

22.3 KB
Loading

0 commit comments

Comments
 (0)