exifreader 4.41.3 → 4.41.4

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/exif-reader.d.ts CHANGED
@@ -228,7 +228,14 @@ export interface ExpandedTags {
228
228
  png?: PngTags,
229
229
  exif?: ExifTags,
230
230
  iptc?: ExifTags,
231
- xmp?: { _raw: string } & XmpTags,
231
+ xmp?: {
232
+ /**
233
+ * The raw, unsanitized XMP packet exactly as it appears in the image.
234
+ * Treat it as untrusted: escape or sanitize it before inserting it into
235
+ * a page as HTML to avoid cross-site scripting.
236
+ */
237
+ _raw: string
238
+ } & XmpTags,
232
239
  icc?: IccTags,
233
240
  riff?: RiffTags,
234
241
  gif?: GifTags,
@@ -434,9 +441,37 @@ export function load(data: ArrayBuffer | SharedArrayBuffer | Buffer, options: Co
434
441
  export function load(data: ArrayBuffer | SharedArrayBuffer | Buffer, options: CommonOptions & FlatOnly & {length?: number, async?: false}): Tags;
435
442
  export function load(data: ArrayBuffer | SharedArrayBuffer | Buffer, options: CommonOptions & ExpandedOnly & {length?: number, async: true}): Promise<ExpandedTags>;
436
443
  export function load(data: ArrayBuffer | SharedArrayBuffer | Buffer, options: CommonOptions & FlatOnly & {length?: number, async: true}): Promise<Tags>;
444
+ /**
445
+ * Security: a string argument is treated as a URL or a local file path, so
446
+ * `load()` will make a network request or read from the file system. Never pass
447
+ * an untrusted or user-controlled string, since it enables server-side request
448
+ * forgery (SSRF) and reads of arbitrary local files. For untrusted image data,
449
+ * pass the bytes (`ArrayBuffer`, `Buffer`, or `File`) instead.
450
+ */
437
451
  export function load(data: string | File): Promise<Tags>;
452
+ /**
453
+ * Security: a string argument is treated as a URL or a local file path, so
454
+ * `load()` will make a network request or read from the file system. Never pass
455
+ * an untrusted or user-controlled string, since it enables server-side request
456
+ * forgery (SSRF) and reads of arbitrary local files. For untrusted image data,
457
+ * pass the bytes (`ArrayBuffer`, `Buffer`, or `File`) instead.
458
+ */
438
459
  export function load(data: string | File, options: CommonOptions & AutoLengthOptions): Promise<ExpandedTags>;
460
+ /**
461
+ * Security: a string argument is treated as a URL or a local file path, so
462
+ * `load()` will make a network request or read from the file system. Never pass
463
+ * an untrusted or user-controlled string, since it enables server-side request
464
+ * forgery (SSRF) and reads of arbitrary local files. For untrusted image data,
465
+ * pass the bytes (`ArrayBuffer`, `Buffer`, or `File`) instead.
466
+ */
439
467
  export function load(data: string | File, options: CommonOptions & ExpandedOnly & {length?: number, async?: boolean }): Promise<ExpandedTags>;
468
+ /**
469
+ * Security: a string argument is treated as a URL or a local file path, so
470
+ * `load()` will make a network request or read from the file system. Never pass
471
+ * an untrusted or user-controlled string, since it enables server-side request
472
+ * forgery (SSRF) and reads of arbitrary local files. For untrusted image data,
473
+ * pass the bytes (`ArrayBuffer`, `Buffer`, or `File`) instead.
474
+ */
440
475
  export function load(data: string | File, options: CommonOptions & FlatOnly & {length?: number, async?: boolean }): Promise<Tags>;
441
476
  export function loadView(data: DataView): Tags;
442
477
  export function loadView(data: DataView, options: CommonOptions & ExpandedOnly & {async?: false}): ExpandedTags;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "exifreader",
3
- "version": "4.41.3",
3
+ "version": "4.41.4",
4
4
  "description": "Library that parses Exif metadata in images.",
5
5
  "author": "Mattias Wallander <mattias@wallander.eu>",
6
6
  "repository": {
@@ -30,16 +30,17 @@
30
30
  "devDependencies": {
31
31
  "@babel/core": "^7.29.7",
32
32
  "@babel/preset-env": "^7.29.7",
33
+ "@cypress/webpack-preprocessor": "^7.1.1",
33
34
  "@eslint/js": "^9.39.5",
34
- "@types/node": "^26.1.1",
35
+ "@types/node": "^26.1.2",
35
36
  "babel-loader": "^10.0.0",
36
- "c8": "^11.0.0",
37
+ "c8": "^12.0.0",
37
38
  "chai": "^6.2.2",
38
39
  "cross-env": "^10.0.0",
39
- "cypress": "^15.18.1",
40
+ "cypress": "^15.19.0",
40
41
  "eslint": "^9.39.4",
41
42
  "eslint-plugin-cypress": "^6.4.1",
42
- "globals": "^17.7.0",
43
+ "globals": "^17.8.0",
43
44
  "husky": "^9.0.11",
44
45
  "linkedom": "^0.18.13",
45
46
  "mocha": "^11.7.6",
@@ -48,7 +49,7 @@
48
49
  "string-replace-loader": "^3.1.0",
49
50
  "terser-webpack-plugin": "^5.6.1",
50
51
  "typescript": "^7.0.2",
51
- "webpack": "5.108.4",
52
+ "webpack": "5.109.1",
52
53
  "webpack-cli": "^7.2.1",
53
54
  "webpack-dev-server": "^5.2.6"
54
55
  },
package/src/xmp-tags.js CHANGED
@@ -63,20 +63,28 @@ function extractCompleteChunks(dataView, chunks) {
63
63
  }
64
64
 
65
65
  function combineChunks(dataView, chunks) {
66
- const totalLength = chunks.reduce((size, chunk) => size + chunk.length, 0);
66
+ const slices = chunks.map((chunk) => getBoundedChunkBytes(dataView, chunk));
67
+ const totalLength = slices.reduce((size, slice) => size + slice.length, 0);
67
68
  const combinedChunks = new Uint8Array(totalLength);
68
69
  let offset = 0;
69
70
 
70
- for (let i = 0; i < chunks.length; i++) {
71
- const chunk = chunks[i];
72
- const slice = dataView.buffer.slice(chunk.dataOffset, chunk.dataOffset + chunk.length);
73
- combinedChunks.set(new Uint8Array(slice), offset);
74
- offset += chunk.length;
71
+ for (let i = 0; i < slices.length; i++) {
72
+ combinedChunks.set(slices[i], offset);
73
+ offset += slices[i].length;
75
74
  }
76
75
 
77
76
  return new DataView(combinedChunks.buffer);
78
77
  }
79
78
 
79
+ // A chunk length comes verbatim from the image and is not trusted. Bound it to
80
+ // the bytes actually present so a crafted length cannot force a huge allocation.
81
+ function getBoundedChunkBytes(dataView, chunk) {
82
+ const bufferLength = dataView.buffer.byteLength;
83
+ const start = Math.min(Math.max(chunk.dataOffset, 0), bufferLength);
84
+ const end = Math.min(start + Math.max(chunk.length, 0), bufferLength);
85
+ return new Uint8Array(dataView.buffer.slice(start, end));
86
+ }
87
+
80
88
  function readTags(tags, chunkDataView, domParser) {
81
89
  try {
82
90
  const {doc, raw} = getDocument(chunkDataView, domParser);