exifreader 4.51.0 → 4.52.0

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/README.md CHANGED
@@ -326,6 +326,12 @@ Note that XMP and ICC tags are parsed from full metadata blocks, so ExifReader
326
326
  cannot skip parsing individual XMP/ICC tags based on selectors. The returned
327
327
  output is still filtered.
328
328
 
329
+ Filtering removes parsed tags only, not the raw data they were parsed from.
330
+ Some tags hold such data, for example `xmp._raw` (with `expanded: true`), the
331
+ Exif `ApplicationNotes` and `IPTC-NAA` tags, the MPF `Images`, PNG text tags
332
+ and `Thumbnail`. When filtering for privacy, list the tags you want in
333
+ `includeTags` (by name, not `true`) instead of excluding the ones you do not.
334
+
329
335
  #### Unknown tags
330
336
 
331
337
  Tags that are unknown, either because they have been excluded by making a custom
@@ -600,11 +606,24 @@ functions take a `Uint8Array` of compressed data and should return a
600
606
  `Uint8Array` or `ArrayBuffer` with the decompressed data (or a `Promise` that
601
607
  resolves to one).
602
608
 
609
+ Each function also receives a second argument, `{maxOutputLength}`: the most
610
+ bytes it may produce for this block. That is one more than what is left of the
611
+ `maxDecompressedSize` total for this `load()` call, so that a result cut off
612
+ there still shows the block went over, and at most 1 GiB. The function has to
613
+ stop there itself, since ExifReader can only check the result after the
614
+ function returns.
615
+ A function that stops by throwing an error whose `code` is
616
+ `'ERR_BUFFER_TOO_LARGE'`, as Node's `zlib` does, counts as going over the total
617
+ (see [Limiting decompressed metadata size](#limiting-decompressed-metadata-size));
618
+ any other error skips that block. Wrap a library function in an arrow
619
+ function that passes on only what it understands instead of passing the library
620
+ function itself, since its own second parameter may mean something else.
621
+
603
622
  ```javascript
604
623
  const tags = await ExifReader.load(file, {
605
624
  async: true,
606
625
  decompress: {
607
- brotli: async (compressedData) => myBrotliDecompress(compressedData),
626
+ brotli: async (compressedData, {maxOutputLength}) => myBrotliDecompress(compressedData, maxOutputLength),
608
627
  }
609
628
  });
610
629
  ```
@@ -613,6 +632,20 @@ If a custom function is provided for a compression type, it takes priority over
613
632
  the built-in Compression Streams API. If not provided, the library falls back to
614
633
  the Compression Streams API when available.
615
634
 
635
+ In Node, `zlib` takes the limit directly:
636
+
637
+ ```javascript
638
+ import zlib from 'node:zlib';
639
+
640
+ const tags = await ExifReader.load(file, {
641
+ async: true,
642
+ decompress: {
643
+ deflate: (data, {maxOutputLength}) => zlib.inflateSync(data, {maxOutputLength}),
644
+ brotli: (data, {maxOutputLength}) => zlib.brotliDecompressSync(data, {maxOutputLength}),
645
+ }
646
+ });
647
+ ```
648
+
616
649
  A lightweight browser-compatible Brotli decompression library is
617
650
  [brotli-dec-wasm](https://www.npmjs.com/package/brotli-dec-wasm), though it is
618
651
  not widely used. A more popular alternative is
@@ -631,6 +664,9 @@ const tags = await ExifReader.load(file, {
631
664
  });
632
665
  ```
633
666
 
667
+ As written, this example does not pass `maxOutputLength` on, so a crafted file
668
+ can make it allocate beyond the limit before ExifReader sees the result.
669
+
634
670
  #### Limiting decompressed metadata size
635
671
 
636
672
  To avoid excessive memory use from pathological compressed inputs, ExifReader
@@ -653,10 +689,11 @@ If a compressed block would take the total beyond the limit, that block and
653
689
  every later compressed block are skipped, one warning is logged via
654
690
  `console.warn`, and the rest of the tags are returned as usual. Blocks that
655
691
  are decompressed at the same time, such as several PNG text chunks, can all be
656
- skipped when together they go beyond the limit. The limit applies to the
657
- built-in Compression Streams paths and to any result returned by a custom
658
- `brotli`/`deflate` function. With `length: 'auto'`, each read attempt parses
659
- the bytes fetched so far and has its own total.
692
+ skipped when together they go beyond the limit. The built-in Compression
693
+ Streams paths stop at the limit. A custom `brotli`/`deflate` function receives
694
+ its limit as `maxOutputLength` and has to stop there itself, because
695
+ ExifReader can only check its result after it returns. With `length: 'auto'`,
696
+ each read attempt parses the bytes fetched so far and has its own total.
660
697
 
661
698
  With `async: true`, ExifReader decompresses at most the first 255 compressed
662
699
  PNG text chunks (zTXt and compressed iTXt) of a file and skips later ones.
package/bin/build.js CHANGED
@@ -62,7 +62,7 @@ function runBuild(options) {
62
62
  env.NODE_PATH = env.NODE_PATH ? buildModules + path.delimiter + env.NODE_PATH : buildModules;
63
63
  }
64
64
 
65
- execSync(`npx -p ${getPackage('webpack-cli')} -p ${getPackage('webpack')} webpack`, {stdio: 'inherit', env});
65
+ execSync(`npx --ignore-scripts -p ${getPackage('webpack-cli')} -p ${getPackage('webpack')} webpack`, {stdio: 'inherit', env});
66
66
  if (config) {
67
67
  writeMarker(distDir, config, require(path.join(EXIFREADER_ROOT_DIR, 'package.json')).version);
68
68
  }
@@ -97,7 +97,7 @@ function installCustomBuildDependencies(tmpDir) {
97
97
  // npm init only creates a package.json to anchor the install to tmpDir, so
98
98
  // silence its package.json dump (stderr is kept for real errors).
99
99
  execSync('npm init -y', {cwd: tmpDir, stdio: ['ignore', 'ignore', 'inherit']});
100
- execSync(`npm install --production --loglevel=error --no-optional --no-package-lock --no-save ${packages.join(' ')}`, {cwd: tmpDir, stdio: 'inherit'});
100
+ execSync(`npm install --production --loglevel=error --no-optional --no-package-lock --no-save --ignore-scripts ${packages.join(' ')}`, {cwd: tmpDir, stdio: 'inherit'});
101
101
  console.log('Done.'); // eslint-disable-line no-console
102
102
  }
103
103