exifreader 4.44.0 → 4.44.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "exifreader",
3
- "version": "4.44.0",
3
+ "version": "4.44.1",
4
4
  "description": "Library that parses Exif metadata in images.",
5
5
  "author": "Mattias Wallander <mattias@wallander.eu>",
6
6
  "repository": {
@@ -30,27 +30,27 @@
30
30
  "devDependencies": {
31
31
  "@babel/core": "^7.29.7",
32
32
  "@babel/preset-env": "^7.29.7",
33
- "@cypress/webpack-preprocessor": "^7.1.2",
33
+ "@cypress/webpack-preprocessor": "^8.0.0",
34
34
  "@eslint/js": "^9.39.5",
35
- "@types/node": "^26.2.0",
35
+ "@types/node": "^26.4.0",
36
36
  "babel-loader": "^10.0.0",
37
37
  "c8": "^12.0.0",
38
38
  "chai": "^6.2.2",
39
39
  "cross-env": "^10.0.0",
40
- "cypress": "^15.20.1",
40
+ "cypress": "^15.21.1",
41
41
  "eslint": "^9.39.4",
42
42
  "eslint-plugin-cypress": "^6.4.4",
43
- "globals": "^17.11.0",
43
+ "globals": "^17.12.0",
44
44
  "husky": "^9.0.11",
45
45
  "linkedom": "^0.18.13",
46
- "mocha": "^11.8.0",
46
+ "mocha": "^12.0.0",
47
47
  "npm-run-all2": "^9.0.3",
48
48
  "rimraf": "^5.0.5",
49
49
  "string-replace-loader": "^3.1.0",
50
50
  "terser-webpack-plugin": "^5.6.1",
51
51
  "typescript": "^7.0.2",
52
- "webpack": "5.109.2",
53
- "webpack-cli": "^7.2.2",
52
+ "webpack": "5.110.2",
53
+ "webpack-cli": "^7.2.3",
54
54
  "webpack-dev-server": "^5.2.6"
55
55
  },
56
56
  "scripts": {
@@ -85,7 +85,8 @@
85
85
  "text"
86
86
  ],
87
87
  "exclude": [
88
- "test/**"
88
+ "test/**",
89
+ ".mocharc.cjs"
89
90
  ]
90
91
  },
91
92
  "browserslist": [
@@ -230,6 +230,7 @@ export function loadView(
230
230
  Constants.USE_TIFF
231
231
  && Constants.USE_XMP
232
232
  && parsedExifTags['ApplicationNotes']
233
+ && Array.isArray(parsedExifTags['ApplicationNotes'].value)
233
234
  && !hasXmpData(xmpChunks)
234
235
  && tagFilter.shouldParseGroup('xmp')
235
236
  ) {
@@ -259,6 +260,7 @@ export function loadView(
259
260
  Constants.USE_PHOTOSHOP
260
261
  && parsedExifTags['ImageSourceData']
261
262
  && parsedExifTags['PhotoshopSettings']
263
+ && Array.isArray(parsedExifTags['PhotoshopSettings'].value)
262
264
  && tagFilter.shouldParseGroup('photoshop')
263
265
  ) {
264
266
  const readPhotoshopTags = PhotoshopTags.read(
@@ -412,11 +414,7 @@ export function loadView(
412
414
  && tagFilter.shouldParseGroup('exif')
413
415
  && async
414
416
  ) {
415
- const compressedExifData = new DataView(
416
- dataView.buffer,
417
- dataView.byteOffset + brobExifChunk.dataOffset,
418
- brobExifChunk.length
419
- );
417
+ const compressedExifData = getBrobDataView(dataView, brobExifChunk);
420
418
  deferredPromises.push(
421
419
  decompress(compressedExifData, COMPRESSION_METHOD_BROTLI, undefined, 'dataview', decompressConfig)
422
420
  .then((decompressedDataView) => {
@@ -451,11 +449,7 @@ export function loadView(
451
449
  && tagFilter.shouldParseGroup('xmp')
452
450
  && async
453
451
  ) {
454
- const compressedXmpData = new DataView(
455
- dataView.buffer,
456
- dataView.byteOffset + brobXmpChunk.dataOffset,
457
- brobXmpChunk.length
458
- );
452
+ const compressedXmpData = getBrobDataView(dataView, brobXmpChunk);
459
453
  deferredPromises.push(
460
454
  decompress(compressedXmpData, COMPRESSION_METHOD_BROTLI, undefined, 'dataview', decompressConfig)
461
455
  .then((decompressedDataView) => {
@@ -476,8 +470,7 @@ export function loadView(
476
470
  }
477
471
 
478
472
  if (
479
- (Constants.USE_JPEG || Constants.USE_WEBP)
480
- && Constants.USE_ICC
473
+ Constants.USE_ICC
481
474
  && hasIccData(iccChunks)
482
475
  && tagFilter.shouldParseGroup('icc')
483
476
  ) {
@@ -735,6 +728,14 @@ export function loadView(
735
728
  }
736
729
  }
737
730
 
731
+ function getBrobDataView(dataView, brobChunk) {
732
+ // The box length is untrusted and comes through negative for a box shorter
733
+ // than its header, so bound the view by the bytes present. The JXL header
734
+ // parser never reports a dataOffset past the end of the view.
735
+ const length = Math.max(0, Math.min(brobChunk.length, dataView.byteLength - brobChunk.dataOffset));
736
+ return new DataView(dataView.buffer, dataView.byteOffset + brobChunk.dataOffset, length);
737
+ }
738
+
738
739
  function readExifTagsSafely(dataView, tiffHeaderOffset, includeUnknown, computed, tagFilter) {
739
740
  try {
740
741
  return Tags.read(dataView, tiffHeaderOffset, includeUnknown, computed, tagFilter);
@@ -839,8 +840,7 @@ function hasPotentialMetaData({
839
840
  && hasXmpData(xmpChunks)
840
841
  )
841
842
  || (
842
- (Constants.USE_JPEG || Constants.USE_WEBP)
843
- && Constants.USE_ICC
843
+ Constants.USE_ICC
844
844
  && hasIccData(iccChunks)
845
845
  )
846
846
  || (
@@ -936,7 +936,8 @@ function hasCanonData(tags) {
936
936
 
937
937
  function hasPentaxType1Data(tags) {
938
938
  const PENTAX_ID_STRING = 'PENTAX ';
939
- return tags['MakerNote'].value.length > PENTAX_ID_STRING.length
939
+ return Array.isArray(tags['MakerNote'].value)
940
+ && tags['MakerNote'].value.length > PENTAX_ID_STRING.length
940
941
  && getStringValueFromArray(tags['MakerNote'].value.slice(0, PENTAX_ID_STRING.length)) === PENTAX_ID_STRING
941
942
  && tags['MakerNote'].__offset;
942
943
  }
package/src/file-tags.js CHANGED
@@ -21,7 +21,8 @@ function read(dataView, fileDataOffset) {
21
21
  }
22
22
 
23
23
  function getLength(dataView, fileDataOffset) {
24
- return Types.getShortAt(dataView, fileDataOffset);
24
+ // The declared length is untrusted, so bound it by the bytes present.
25
+ return Math.min(Types.getShortAt(dataView, fileDataOffset), dataView.byteLength - fileDataOffset);
25
26
  }
26
27
 
27
28
  function getDataPrecision(dataView, fileDataOffset, length) {
@@ -247,7 +247,10 @@ function isSOF2Marker(dataView, appMarkerPosition) {
247
247
  function isApp2ICCMarker(dataView, appMarkerPosition) {
248
248
  const markerIdLength = APP2_ICC_IDENTIFIER.length;
249
249
 
250
+ // The ICC branch reads the two chunk bytes that follow the identifier, so a
251
+ // segment without them must not be recognized here.
250
252
  return (dataView.getUint16(appMarkerPosition) === APP2_MARKER)
253
+ && (appMarkerPosition + ICC_TOTAL_CHUNKS_OFFSET < dataView.byteLength)
251
254
  && (getStringFromDataView(dataView, appMarkerPosition + APP_ID_OFFSET, markerIdLength) === APP2_ICC_IDENTIFIER);
252
255
  }
253
256
 
@@ -314,7 +317,10 @@ function isApp13PhotoshopMarker(dataView, appMarkerPosition) {
314
317
  const resourceIdentifierOffset = appMarkerPosition + APP_ID_OFFSET
315
318
  + markerIdLength + 1;
316
319
 
317
- return (dataView.getUint16(appMarkerPosition) === APP13_MARKER)
320
+ // The null byte and the 8BIM identifier lie past the bytes the marker walk
321
+ // guarantees, so a segment without them must not be recognized here.
322
+ return (resourceIdentifierOffset + resourceIdentifierLength <= dataView.byteLength)
323
+ && (dataView.getUint16(appMarkerPosition) === APP13_MARKER)
318
324
  && (getStringFromDataView(dataView, appMarkerPosition + APP_ID_OFFSET, markerIdLength) === APP13_IPTC_IDENTIFIER)
319
325
  && (dataView.getUint8(appMarkerPosition + APP_ID_OFFSET + markerIdLength) === 0x00)
320
326
  && (getStringFromDataView(dataView, resourceIdentifierOffset, resourceIdentifierLength) === APP13_RESOURCE_BLOCK_IDENTIFIER);
package/src/jfif-tags.js CHANGED
@@ -38,7 +38,8 @@ function read(dataView, jfifDataOffset) {
38
38
  }
39
39
 
40
40
  function getLength(dataView, jfifDataOffset) {
41
- return Types.getShortAt(dataView, jfifDataOffset);
41
+ // The declared length is untrusted, so bound it by the bytes present.
42
+ return Math.min(Types.getShortAt(dataView, jfifDataOffset), dataView.byteLength - jfifDataOffset);
42
43
  }
43
44
 
44
45
  function getVersion(dataView, jfifDataOffset, length) {
@@ -22,25 +22,28 @@ const TAG_NAME_MIN_SIZE = 2;
22
22
  const RESOURCE_BLOCK_MIN_HEADER_SIZE = SIGNATURE_SIZE + TAG_ID_SIZE + TAG_NAME_MIN_SIZE + RESOURCE_LENGTH_SIZE;
23
23
 
24
24
  function read(bytes, includeUnknown, tagFilter = NOOP_TAG_FILTER) {
25
+ if (!Array.isArray(bytes)) {
26
+ return {};
27
+ }
25
28
  const dataView = getDataView(new Uint8Array(bytes).buffer);
26
29
  const tags = {};
27
30
  let offset = 0;
28
31
 
29
- while (offset + RESOURCE_BLOCK_MIN_HEADER_SIZE <= bytes.length) {
32
+ while (offset + RESOURCE_BLOCK_MIN_HEADER_SIZE <= dataView.byteLength) {
30
33
  const signature = getStringFromDataView(dataView, offset, SIGNATURE_SIZE);
31
34
  offset += SIGNATURE_SIZE;
32
35
  const tagId = Types.getShortAt(dataView, offset);
33
36
  offset += TAG_ID_SIZE;
34
37
  const {tagName, tagNameSize} = getTagName(dataView, offset);
35
38
  offset += tagNameSize;
36
- if (offset + RESOURCE_LENGTH_SIZE > bytes.length) {
39
+ if (offset + RESOURCE_LENGTH_SIZE > dataView.byteLength) {
37
40
  break;
38
41
  }
39
42
  const declaredResourceSize = Types.getLongAt(dataView, offset);
40
43
  offset += RESOURCE_LENGTH_SIZE;
41
44
  // The declared size comes from the file and is not trusted, so bound
42
45
  // it by the bytes that are actually present.
43
- const resourceSize = Math.min(declaredResourceSize, bytes.length - offset);
46
+ const resourceSize = Math.min(declaredResourceSize, dataView.byteLength - offset);
44
47
  if (signature === SIGNATURE) {
45
48
  const resolvedTagName = getTagNameForFiltering(tagId, tagName, includeUnknown);
46
49
  if (!tagFilter.shouldParseTag('photoshop', resolvedTagName, tagId)) {
@@ -147,7 +147,7 @@ function getNameAndValue(dataView, offset, length, type, async, decompressConfig
147
147
 
148
148
  function getCompressionMethod({type, dataView, offset}) {
149
149
  if (type === TYPE_ITXT) {
150
- if (dataView.getUint8(offset) === COMPRESSION_FLAG_COMPRESSED) {
150
+ if (offset + 1 < dataView.byteLength && dataView.getUint8(offset) === COMPRESSION_FLAG_COMPRESSED) {
151
151
  return dataView.getUint8(offset + 1);
152
152
  }
153
153
  } else if (type === TYPE_ZTXT) {