exifreader 4.52.0 → 4.54.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
@@ -709,10 +709,18 @@ parser needs to have a `parseFromString` method with the same API as the
709
709
  [`parseFromString` from the DOMParser Web
710
710
  API](https://developer.mozilla.org/en-US/docs/Web/API/DOMParser/parseFromString).
711
711
 
712
- Two libraries have been tested,
713
- [`xmldom`](https://www.npmjs.com/package/@xmldom/xmldom) and
714
- [`linkedom`](https://www.npmjs.com/package/linkedom), but more might work if
715
- they follow the spec.
712
+ Use [`xmldom`](https://www.npmjs.com/package/@xmldom/xmldom) 0.9.12 or later.
713
+ ExifReader limits how deeply XMP elements can nest and how many markup nodes a
714
+ packet can have, and it checks those limits the way `xmldom` reads markup.
715
+ Older versions of `xmldom` read some markup differently, well-formed markup
716
+ included, so with them a crafted file can get past the limits and make parsing
717
+ slow.
718
+
719
+ [`linkedom`](https://www.npmjs.com/package/linkedom) also parses XMP correctly,
720
+ but use it only for files you trust. ExifReader's limits do not hold with it: a
721
+ crafted 1 MB file can block parsing for about a minute, and a larger one for
722
+ longer. `linkedom` can also get stuck on some XML (see below). Other parsers
723
+ may work if they follow the spec, with the same caveat.
716
724
 
717
725
  Here is an example using `xmldom`:
718
726
 
@@ -722,11 +730,6 @@ import {DOMParser, onErrorStopParsing} from '@xmldom/xmldom';
722
730
  const tags = ExifReader.load(fileBuffer, {domParser: new DOMParser({onError: onErrorStopParsing})});
723
731
  ```
724
732
 
725
- Use `xmldom` 0.9.12 or later. ExifReader limits how deeply XMP elements can
726
- nest and how many markup nodes a packet can have, and it checks those limits
727
- the way `xmldom` 0.9 reads the markup. With 0.8, a crafted file can get past
728
- them and make parsing slow.
729
-
730
733
  The `onError` option is needed to avoid a [seemingly infinite loop for some
731
734
  XMLs](https://github.com/xmldom/xmldom/issues/501). Unfortunately `linkedom` has
732
735
  the same problem but does not have this option and will therefore get stuck on
@@ -734,6 +737,19 @@ these XMLs. If this happens to you, switch to `xmldom` and pass in the `onError`
734
737
  option. (NOTE: The native `DOMParser` that a web browser uses does not seem to
735
738
  have this issue.)
736
739
 
740
+ ExifReader skips an XMP packet that has a DOCTYPE or another markup
741
+ declaration, since a parser such as a browser's native `DOMParser` can expand
742
+ the entities declared in a DOCTYPE into markup the limits do not see.
743
+
744
+ If you pass no `domParser` and there is no global `DOMParser`, ExifReader tries
745
+ to load `@xmldom/xmldom` itself. It then skips XMP, with a warning, if the copy
746
+ it finds is older than 0.9.12 or its version cannot be read. That copy can be
747
+ the one at the top of your `node_modules` instead of ExifReader's own, for
748
+ example when ExifReader is installed without optional dependencies, or when an
749
+ npm override, a Yarn resolution or a pnpm override pins `@xmldom/xmldom` below
750
+ 0.9.12. Install `@xmldom/xmldom` 0.9.12 or later, or pass a parser in the
751
+ `domParser` option.
752
+
737
753
  #### Using React Native
738
754
 
739
755
  Import ExifReader like this:
@@ -966,12 +982,17 @@ given, so pass them the same one as the build: a project that builds with
966
982
  configuration is found and `--check` exits with 0.
967
983
 
968
984
  **Deprecated: automatic rebuild on install.** Older versions rebuilt the library
969
- automatically through an npm `postinstall` script, so a plain install or `npm
970
- rebuild exifreader` (or `yarn rebuild exifreader` with yarn 2+, or `yarn add
971
- exifreader` with yarn 1) produced the custom bundle. This still works in v4 but
972
- is deprecated and will be removed in v5, because npm is phasing out automatic
973
- install scripts. Use `npx exifreader build` instead, which also avoids the yarn
974
- 2+ `node_modules` and `nodeLinker` caveats.
985
+ automatically through an npm `postinstall` script, so a plain install or
986
+ `npm rebuild exifreader` (or `yarn add exifreader` with yarn 1) produced the
987
+ custom bundle. This still works in v4 but is deprecated and will be removed in
988
+ v5, because npm is phasing out automatic install scripts. Yarn 4.14 and later
989
+ disable dependency build scripts by default (an install prints
990
+ `YN0004 ... all build scripts have been disabled`), so there the install-time
991
+ build only runs if you enable build scripts, with Yarn's `enableScripts` setting
992
+ or the `built` flag in `dependenciesMeta`. Use `npx exifreader build` (or
993
+ `yarn exifreader build` with Yarn) instead, which does not depend on build
994
+ scripts. With Yarn 2+ it needs a `node_modules` install
995
+ (`nodeLinker: node-modules` in `.yarnrc.yml`), not Plug'n'Play.
975
996
 
976
997
  If you are using `vite`, you will need to [clear the dependency cache](https://vitejs.dev/guide/dep-pre-bundling.html#file-system-cache)
977
998
  after a rebuild.