exifreader 4.50.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 +57 -14
- package/bin/build.js +2 -2
- package/dist/exif-reader.js +1 -1
- package/dist/exif-reader.js.map +1 -1
- package/exif-reader.d.ts +25 -11
- package/package.json +5 -5
- package/src/canon-tags.js +11 -2
- package/src/composite.js +2 -2
- package/src/exif-reader.js +92 -33
- package/src/file-loaders.js +28 -12
- package/src/icc-tags.js +1 -3
- package/src/ifd-types.js +14 -0
- package/src/image-header-iso-bmff.js +19 -30
- package/src/image-header-jpeg.js +9 -10
- package/src/image-header-jxl.js +4 -5
- package/src/image-header-png.js +3 -4
- package/src/image-header-tiff.js +4 -8
- package/src/image-header-webp.js +3 -4
- package/src/jfif-tags.js +1 -1
- package/src/load-auto.js +2 -2
- package/src/loadview-pipeline.js +0 -4
- package/src/mpf-tags.js +12 -3
- package/src/pentax-tags.js +11 -2
- package/src/png-text-tags.js +22 -18
- package/src/tag-names-common.js +8 -6
- package/src/tag-names.js +27 -16
- package/src/tags-helpers.js +41 -32
- package/src/tags.js +13 -8
- package/src/thumbnail.js +1 -1
- package/src/utils.js +135 -27
- package/src/xmp-tags.js +4 -6
- package/webpack.config.js +1 -1
- package/src/dataview.js +0 -51
package/README.md
CHANGED
|
@@ -183,7 +183,8 @@ local file path and will make a network request or read from the file system.
|
|
|
183
183
|
Never pass an untrusted or user-controlled string to `load()`. Doing so lets an
|
|
184
184
|
attacker make the process fetch arbitrary URLs (server-side request forgery) or
|
|
185
185
|
open arbitrary local files. For untrusted image data, always pass the bytes
|
|
186
|
-
themselves (an `ArrayBuffer`, a
|
|
186
|
+
themselves (an `ArrayBuffer`, a typed array such as `Uint8Array` or `Buffer`, or
|
|
187
|
+
a browser `File`), never a string.
|
|
187
188
|
|
|
188
189
|
**Tip:** To read metadata from an `HTMLImageElement`, wait for its `load` event
|
|
189
190
|
and call `ExifReader.load(image.src)`. The browser should reuse the cached file.
|
|
@@ -197,6 +198,7 @@ const tags = ExifReader.load(fileBuffer);
|
|
|
197
198
|
Where `fileBuffer` is one of
|
|
198
199
|
|
|
199
200
|
* `ArrayBuffer` or `SharedArrayBuffer` (browser, Node.js)
|
|
201
|
+
* any typed array such as `Uint8Array`, or a `DataView` (browser, Node.js)
|
|
200
202
|
* `Buffer` (Node.js)
|
|
201
203
|
|
|
202
204
|
See the [examples site](https://mattiasw.github.io/ExifReader/) for more
|
|
@@ -324,6 +326,12 @@ Note that XMP and ICC tags are parsed from full metadata blocks, so ExifReader
|
|
|
324
326
|
cannot skip parsing individual XMP/ICC tags based on selectors. The returned
|
|
325
327
|
output is still filtered.
|
|
326
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
|
+
|
|
327
335
|
#### Unknown tags
|
|
328
336
|
|
|
329
337
|
Tags that are unknown, either because they have been excluded by making a custom
|
|
@@ -390,8 +398,9 @@ does not fit inside the part you read, no ICC tags are returned for it. Use
|
|
|
390
398
|
yourself.
|
|
391
399
|
|
|
392
400
|
Note that this option only works when ExifReader handles the loading of the
|
|
393
|
-
file. If e.g. an already loaded ArrayBuffer or Buffer is passed
|
|
394
|
-
the whole file will already have been loaded into memory and
|
|
401
|
+
file. If e.g. an already loaded ArrayBuffer, typed array or Buffer is passed
|
|
402
|
+
into ExifReader, the whole file will already have been loaded into memory and
|
|
403
|
+
it's too late.
|
|
395
404
|
More specifically the length option will work for 1. local files when running
|
|
396
405
|
through Node.js, 2. remote files when passing a URL, and 3. browser File objects
|
|
397
406
|
(e.g., from form file fields). For remote files accessed through a web browser,
|
|
@@ -420,8 +429,11 @@ const tags = await ExifReader.load(url, {
|
|
|
420
429
|
tags.metadataRange.end // exact byte count needed for the metadata
|
|
421
430
|
tags.metadataRange.buffer // bytes [0, end), sliced from what we read.
|
|
422
431
|
// Same kind as the input (ArrayBuffer,
|
|
423
|
-
// SharedArrayBuffer or Node Buffer).
|
|
424
|
-
//
|
|
432
|
+
// SharedArrayBuffer or Node Buffer). For a
|
|
433
|
+
// typed array or DataView input it is an
|
|
434
|
+
// ArrayBuffer (a SharedArrayBuffer when the
|
|
435
|
+
// view is over one) holding only the view's
|
|
436
|
+
// bytes. Save this to disk to keep only the
|
|
425
437
|
// metadata-bearing prefix.
|
|
426
438
|
tags.metadataRange.fetched // bytes actually read. May be greater than
|
|
427
439
|
// `end` because the loop reads in fixed-size
|
|
@@ -442,10 +454,10 @@ Exif/XMP `iloc` entries point near the end of the file typically take two.
|
|
|
442
454
|
- Local file path via Node `fs`
|
|
443
455
|
- Browser `File` object via `File.slice`
|
|
444
456
|
|
|
445
|
-
It is also accepted for in-memory inputs (`ArrayBuffer`, `SharedArrayBuffer
|
|
446
|
-
|
|
447
|
-
case, but `metadataRange.buffer` is still attached
|
|
448
|
-
what you passed in.
|
|
457
|
+
It is also accepted for in-memory inputs (`ArrayBuffer`, `SharedArrayBuffer`,
|
|
458
|
+
Node.js `Buffer`, any other typed array and `DataView`) as a convenience. There
|
|
459
|
+
is no IO loop to run in that case, but `metadataRange.buffer` is still attached
|
|
460
|
+
as the trimmed slice of what you passed in.
|
|
449
461
|
|
|
450
462
|
Requirements and caveats:
|
|
451
463
|
|
|
@@ -594,11 +606,24 @@ functions take a `Uint8Array` of compressed data and should return a
|
|
|
594
606
|
`Uint8Array` or `ArrayBuffer` with the decompressed data (or a `Promise` that
|
|
595
607
|
resolves to one).
|
|
596
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
|
+
|
|
597
622
|
```javascript
|
|
598
623
|
const tags = await ExifReader.load(file, {
|
|
599
624
|
async: true,
|
|
600
625
|
decompress: {
|
|
601
|
-
brotli: async (compressedData) => myBrotliDecompress(compressedData),
|
|
626
|
+
brotli: async (compressedData, {maxOutputLength}) => myBrotliDecompress(compressedData, maxOutputLength),
|
|
602
627
|
}
|
|
603
628
|
});
|
|
604
629
|
```
|
|
@@ -607,6 +632,20 @@ If a custom function is provided for a compression type, it takes priority over
|
|
|
607
632
|
the built-in Compression Streams API. If not provided, the library falls back to
|
|
608
633
|
the Compression Streams API when available.
|
|
609
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
|
+
|
|
610
649
|
A lightweight browser-compatible Brotli decompression library is
|
|
611
650
|
[brotli-dec-wasm](https://www.npmjs.com/package/brotli-dec-wasm), though it is
|
|
612
651
|
not widely used. A more popular alternative is
|
|
@@ -625,6 +664,9 @@ const tags = await ExifReader.load(file, {
|
|
|
625
664
|
});
|
|
626
665
|
```
|
|
627
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
|
+
|
|
628
670
|
#### Limiting decompressed metadata size
|
|
629
671
|
|
|
630
672
|
To avoid excessive memory use from pathological compressed inputs, ExifReader
|
|
@@ -647,10 +689,11 @@ If a compressed block would take the total beyond the limit, that block and
|
|
|
647
689
|
every later compressed block are skipped, one warning is logged via
|
|
648
690
|
`console.warn`, and the rest of the tags are returned as usual. Blocks that
|
|
649
691
|
are decompressed at the same time, such as several PNG text chunks, can all be
|
|
650
|
-
skipped when together they go beyond the limit. The
|
|
651
|
-
|
|
652
|
-
`
|
|
653
|
-
|
|
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.
|
|
654
697
|
|
|
655
698
|
With `async: true`, ExifReader decompresses at most the first 255 compressed
|
|
656
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
|
|