exifreader 4.47.0 → 4.48.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/README.md CHANGED
@@ -28,7 +28,7 @@ You can try it out on the
28
28
  | JPEG | **yes** | **yes** | **yes** | **yes** | **yes** | **some*** | **some**** | **yes** | **yes** |
29
29
  | JPEG XL*** | **yes** | no | **yes** | no | no | no | **some**** | ??? | **yes** |
30
30
  | TIFF | **yes** | **yes** | **yes** | **yes** | ??? | **some*** | **some**** | **yes** | N/A |
31
- | PNG | **yes** | **yes** | **yes** | **yes** | ??? | ??? | **some**** | no | **yes** |
31
+ | PNG | **yes** | **yes** | **yes** | **yes** | ??? | ??? | **some**** | **yes** | **yes** |
32
32
  | HEIC/HEIF | **yes** | no | **yes** | **yes** | ??? | ??? | **some**** | **yes** | no |
33
33
  | AVIF | **yes** | no | **yes** | **yes** | ??? | ??? | **some**** | **yes** | no |
34
34
  | WebP | **yes** | no | **yes** | **yes** | ??? | ??? | **some**** | **yes** | **yes** |
@@ -53,18 +53,6 @@ You can try it out on the
53
53
  If you're missing something that you think should be supported, file an issue
54
54
  with an attached example image and I'll see what I can do.
55
55
 
56
- **Notes for exif-js users**
57
-
58
- If you come here from the popular but now dead exif-js package, please let me
59
- know if you're missing anything from it and I will try to help you. Some notes:
60
-
61
- - ExifReader has a different API, hopefully better. :-)
62
- - XMP support in exif-js does not seem perfect. ExifReader should be a bit
63
- better on that part.
64
- - ExifReader works with strict mode.
65
- - I've been maintaining this package since 2012 and I have no plans to stop
66
- doing that anytime soon.
67
-
68
56
  Table of Contents
69
57
  -----------------
70
58
 
@@ -214,14 +202,25 @@ come straight from the image and can contain arbitrary text, including HTML-like
214
202
  markup. Never insert them into a page as HTML (for example through `innerHTML`)
215
203
  without escaping or sanitizing them first, otherwise a crafted image could lead
216
204
  to cross-site scripting. Use `textContent`, your framework's escaping, or a
217
- sanitizer such as DOMPurify when displaying metadata. The property names inside
218
- a tag value come from the image too, and a tag whose name is `__proto__` is kept
219
- under that name as a regular property, so it does not replace the prototype of
220
- the object holding it. A value parsed from an XMP `rdf:value` element that holds
221
- child elements other than a list is returned as an object without a prototype.
222
- Such an object has no inherited methods, and copying it into an object of your
223
- own with `Object.assign` or a deep merge helper without filtering the keys could
224
- let a crafted image replace that object's prototype.
205
+ sanitizer such as DOMPurify when displaying metadata.
206
+
207
+ The property names inside a tag value come from the image too, and a tag whose
208
+ name is `__proto__` is kept under that name as a regular property, so it does
209
+ not replace the prototype of the object holding it. A tag whose name comes from
210
+ the image and is the name of an `Object.prototype` method, such as
211
+ `hasOwnProperty`, `toString` or `constructor`, is returned under that name with
212
+ `_` appended (`hasOwnProperty_`), so it does not hide the method on the result
213
+ object or on a group object, and `includeTags` and `excludeTags` match it by
214
+ that returned name. The same applies to the property names inside an XMP tag
215
+ value (structure members, members of list items and children of `rdf:value`)
216
+ and to the keys of an XMP tag's `attributes`. A value parsed from an XMP
217
+ `rdf:value` element that holds child elements other than a list is returned as
218
+ an object without a prototype. An XMP qualifier in `attributes` that holds
219
+ child elements is returned as its element tree, with the element and attribute
220
+ names unchanged and kept in objects without a prototype. Such an object has no
221
+ inherited methods, and copying it into an object of your own with
222
+ `Object.assign` or a deep merge helper without filtering the keys could let a
223
+ crafted image replace that object's prototype.
225
224
 
226
225
  #### Grouping
227
226
 
@@ -394,6 +393,11 @@ make sure the remote server is either on the same origin (domain) as your script
394
393
  or that the server is passing correct CORS headers, specifically allowing the
395
394
  `Range` header.
396
395
 
396
+ For those inputs a fractional `length` is rounded down, and a `length` that is
397
+ not a finite non-negative number or `'auto'` (such as the string `'1024'`,
398
+ `NaN`, `Infinity` or a negative number) makes `load()` reject before anything
399
+ is read.
400
+
397
401
  #### Read only the metadata bytes (`length: 'auto'`)
398
402
 
399
403
  When you want to download or store just enough of an image to extract its
@@ -409,9 +413,10 @@ const tags = await ExifReader.load(url, {
409
413
 
410
414
  tags.metadataRange.end // exact byte count needed for the metadata
411
415
  tags.metadataRange.buffer // bytes [0, end), sliced from what we read.
412
- // Same kind as the input (ArrayBuffer or
413
- // Node Buffer). Save this to disk to keep
414
- // only the metadata-bearing prefix.
416
+ // Same kind as the input (ArrayBuffer,
417
+ // SharedArrayBuffer or Node Buffer). Save
418
+ // this to disk to keep only the
419
+ // metadata-bearing prefix.
415
420
  tags.metadataRange.fetched // bytes actually read. May be greater than
416
421
  // `end` because the loop reads in fixed-size
417
422
  // chunks and so may read a little past `end`.
@@ -431,10 +436,10 @@ Exif/XMP `iloc` entries point near the end of the file typically take two.
431
436
  - Local file path via Node `fs`
432
437
  - Browser `File` object via `File.slice`
433
438
 
434
- It is also accepted for in-memory inputs (`ArrayBuffer`, `Buffer`,
435
- `SharedArrayBuffer`, `DataView`) as a convenience. There is no IO loop to
436
- run in that case, but `metadataRange.buffer` is still attached as the
437
- trimmed slice of what you passed in.
439
+ It is also accepted for in-memory inputs (`ArrayBuffer`, `SharedArrayBuffer`
440
+ and Node.js `Buffer`) as a convenience. There is no IO loop to run in that
441
+ case, but `metadataRange.buffer` is still attached as the trimmed slice of
442
+ what you passed in.
438
443
 
439
444
  Requirements and caveats:
440
445
 
@@ -490,6 +495,10 @@ Block `type` reuses the filtering-group vocabulary (`exif`, `iptc`, `xmp`,
490
495
  `icc`, `mpf`, `jfif`, `file`, `png`, `riff`, `gif`), plus `mpfImage` for the
491
496
  sub-images of an MPF Multi-Picture JPEG. The same type may appear more than
492
497
  once (multi-chunk ICC, extended XMP), one entry per physical container.
498
+ ExifReader records at most 4,096 of the containers it finds while scanning
499
+ the file; in a file with more, the last one recorded keeps its own type and is
500
+ widened to cover all the rest, so `start`, `end` and the `0..end` slice still
501
+ cover every metadata byte. `mpfImage` blocks come on top of these.
493
502
 
494
503
  Typical workflow:
495
504
 
@@ -664,6 +673,11 @@ import {DOMParser, onErrorStopParsing} from '@xmldom/xmldom';
664
673
  const tags = ExifReader.load(fileBuffer, {domParser: new DOMParser({onError: onErrorStopParsing})});
665
674
  ```
666
675
 
676
+ Use `xmldom` 0.9.12 or later. ExifReader limits how deeply XMP elements can
677
+ nest and how many markup nodes a packet can have, and it checks those limits
678
+ the way `xmldom` 0.9 reads the markup. With 0.8, a crafted file can get past
679
+ them and make parsing slow.
680
+
667
681
  The `onError` option is needed to avoid a [seemingly infinite loop for some
668
682
  XMLs](https://github.com/xmldom/xmldom/issues/501). Unfortunately `linkedom` has
669
683
  the same problem but does not have this option and will therefore get stuck on
package/bin/build.js CHANGED
@@ -8,6 +8,7 @@ const os = require('os');
8
8
  const {execSync} = require('child_process');
9
9
  const dependentHasExifReaderConfig = require('./findDependentConfig');
10
10
  const {writeMarker, removeMarker} = require('./custom-build-marker');
11
+ const {unshareFile} = require('./unshare-file');
11
12
 
12
13
  const EXIFREADER_ROOT_DIR = path.join(__dirname, '..');
13
14
 
@@ -44,6 +45,8 @@ function runBuild(options) {
44
45
  const config = env.EXIFREADER_CUSTOM_BUILD ? JSON.parse(env.EXIFREADER_CUSTOM_BUILD) : dependentHasExifReaderConfig();
45
46
  const distDir = path.join(EXIFREADER_ROOT_DIR, 'dist');
46
47
  removeMarker(distDir);
48
+ unshareFile(path.join(distDir, 'exif-reader.js'));
49
+ unshareFile(path.join(distDir, 'exif-reader.js.map'));
47
50
 
48
51
  let tmpDir;
49
52
  try {
@@ -0,0 +1,29 @@
1
+ /* This Source Code Form is subject to the terms of the Mozilla Public
2
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
+
5
+ const fs = require('fs');
6
+
7
+ module.exports = {unshareFile};
8
+
9
+ /**
10
+ * Give a hardlinked file its own inode with the same content, so that writing
11
+ * to it no longer changes the other links. A file with one link, or a missing
12
+ * file, is left alone.
13
+ *
14
+ * @param {string} filePath The file to unshare.
15
+ */
16
+ function unshareFile(filePath) {
17
+ // Package managers can hardlink package files from a shared store, and webpack writes in place.
18
+ if (!fs.existsSync(filePath) || fs.statSync(filePath).nlink <= 1) {
19
+ return;
20
+ }
21
+ const tmpPath = `${filePath}.${process.pid}.tmp`;
22
+ try {
23
+ fs.copyFileSync(filePath, tmpPath);
24
+ fs.renameSync(tmpPath, filePath);
25
+ } catch (error) {
26
+ fs.rmSync(tmpPath, {force: true});
27
+ throw error;
28
+ }
29
+ }