exifreader 4.48.1 → 4.50.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 +38 -32
- package/bin/cli.js +4 -1
- package/dist/exif-reader.js +1 -1
- package/dist/exif-reader.js.map +1 -1
- package/package.json +20 -1
- package/src/dom-parser.js +3 -2
- package/src/exif-reader.js +241 -166
- package/src/file-loaders.js +11 -14
- package/src/image-header-iso-bmff.js +261 -39
- package/src/image-header-jxl.js +6 -6
- package/src/iptc-tag-names.js +35 -17
- package/src/iso-bmff-file-tags.js +86 -0
- package/src/loadview-pipeline.js +106 -28
- package/src/node-require.js +84 -0
- package/src/png-text-tags.js +88 -49
- package/src/tag-decoder.js +3 -3
- package/src/tag-names-0th-ifd.js +51 -42
- package/src/tag-names-common.js +19 -15
- package/src/tag-names-exif-ifd.js +7 -7
- package/src/tag-names-utils.js +24 -3
- package/src/tags-helpers.js +20 -0
- package/src/utils.js +66 -4
- package/src/xmp-tag-names.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "exifreader",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.50.0",
|
|
4
4
|
"description": "Library that parses Exif metadata in images.",
|
|
5
5
|
"author": "Mattias Wallander <mattias@wallander.eu>",
|
|
6
6
|
"repository": {
|
|
@@ -21,6 +21,23 @@
|
|
|
21
21
|
"webpack.config.js"
|
|
22
22
|
],
|
|
23
23
|
"types": "./exif-reader.d.ts",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./exif-reader.d.ts",
|
|
27
|
+
"browser": "./src/exif-reader.js",
|
|
28
|
+
"node": "./dist/exif-reader.js",
|
|
29
|
+
"module": "./src/exif-reader.js",
|
|
30
|
+
"import": "./dist/exif-reader.js",
|
|
31
|
+
"require": "./dist/exif-reader.js",
|
|
32
|
+
"default": "./dist/exif-reader.js"
|
|
33
|
+
},
|
|
34
|
+
"./package.json": "./package.json",
|
|
35
|
+
"./src/exif-reader": "./src/exif-reader.js",
|
|
36
|
+
"./dist/exif-reader": "./dist/exif-reader.js",
|
|
37
|
+
"./src/composable/*": null,
|
|
38
|
+
"./src/*": "./src/*",
|
|
39
|
+
"./dist/*": "./dist/*"
|
|
40
|
+
},
|
|
24
41
|
"bin": {
|
|
25
42
|
"exifreader": "bin/cli.js"
|
|
26
43
|
},
|
|
@@ -69,6 +86,8 @@
|
|
|
69
86
|
"test:e2e:chrome": "cypress run",
|
|
70
87
|
"test:e2e:firefox": "cypress run --browser firefox",
|
|
71
88
|
"test:types": "tsc --noEmit --project test/types",
|
|
89
|
+
"test:packaging:install": "npm install --prefix test/packaging/tools --no-package-lock --no-audit --no-fund --ignore-scripts",
|
|
90
|
+
"test:packaging": "node test/packaging/resolver-matrix.mjs",
|
|
72
91
|
"test:all": "npm-run-all2 lint test:types coverage test:e2e:chrome test:integration test:build test:build:custom",
|
|
73
92
|
"pre-commit": "npm-run-all2 lint test:types coverage test:build",
|
|
74
93
|
"postinstall": "node bin/build.js --only-with-config",
|
package/src/dom-parser.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
3
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
4
4
|
|
|
5
|
+
import NodeRequire from './node-require.js';
|
|
6
|
+
|
|
5
7
|
export default {
|
|
6
8
|
get
|
|
7
9
|
};
|
|
@@ -15,8 +17,7 @@ function get(domParser) {
|
|
|
15
17
|
return new DOMParser();
|
|
16
18
|
}
|
|
17
19
|
try {
|
|
18
|
-
|
|
19
|
-
const {DOMParser, onErrorStopParsing} = __non_webpack_require__('@xmldom/xmldom');
|
|
20
|
+
const {DOMParser, onErrorStopParsing} = NodeRequire.optionalPackage('@xmldom/xmldom');
|
|
20
21
|
return new DOMParser({onError: onErrorStopParsing});
|
|
21
22
|
} catch (error) {
|
|
22
23
|
return undefined;
|
package/src/exif-reader.js
CHANGED
|
@@ -17,10 +17,11 @@ import ByteOrder from './byte-order.js';
|
|
|
17
17
|
import {getTiffHeaderOffset} from './image-header-iso-bmff.js';
|
|
18
18
|
import ImageHeader from './image-header.js';
|
|
19
19
|
import Tags from './tags.js';
|
|
20
|
-
import {getValueBudget, addDecompressedValueAllowance} from './tags-helpers.js';
|
|
20
|
+
import {getValueBudget, addDecompressedValueAllowance, takeEmbeddedExifThumbnail} from './tags-helpers.js';
|
|
21
21
|
import MpfTags from './mpf-tags.js';
|
|
22
22
|
import FileTags from './file-tags.js';
|
|
23
23
|
import JxlFileTags from './jxl-file-tags.js';
|
|
24
|
+
import IsoBmffFileTags from './iso-bmff-file-tags.js';
|
|
24
25
|
import JfifTags from './jfif-tags.js';
|
|
25
26
|
import IptcTags from './iptc-tags.js';
|
|
26
27
|
import XmpTags from './xmp-tags.js';
|
|
@@ -36,13 +37,19 @@ import GifFileTags from './gif-file-tags.js';
|
|
|
36
37
|
import Thumbnail from './thumbnail.js';
|
|
37
38
|
import Composite from './composite.js';
|
|
38
39
|
import {createTagFilter} from './tag-filter.js';
|
|
39
|
-
import {buildTagsFromMergeSteps, isThenable} from './loadview-pipeline.js';
|
|
40
|
+
import {buildTagsFromMergeSteps, isThenable, EXIF_CARRIED_GROUP_ORDER} from './loadview-pipeline.js';
|
|
40
41
|
import exifErrors from './errors.js';
|
|
41
42
|
|
|
42
43
|
// Brob XMP is bounded by the file size, as brob Exif is, plus room for one JPEG
|
|
43
44
|
// standard XMP segment so that a small file can still carry a typical packet.
|
|
44
45
|
const BROB_XMP_SIZE_PER_INPUT_SIZE = 4;
|
|
45
46
|
const BROB_XMP_SIZE_ALLOWANCE = 64 * 1024;
|
|
47
|
+
// An embedded thumbnail is sliced from a decoded or decompressed view that can be
|
|
48
|
+
// far larger than the file. A real JPEG thumbnail shrinks only a little when
|
|
49
|
+
// compressed, so bound the embedded thumbnails of a file by twice its size in
|
|
50
|
+
// total, plus room for a typical thumbnail.
|
|
51
|
+
const EMBEDDED_THUMBNAIL_SIZE_PER_INPUT_SIZE = 2;
|
|
52
|
+
const EMBEDDED_THUMBNAIL_SIZE_ALLOWANCE = 64 * 1024;
|
|
46
53
|
|
|
47
54
|
export default {
|
|
48
55
|
load,
|
|
@@ -110,6 +117,7 @@ export function loadView(
|
|
|
110
117
|
let thumbnailIfdTags = undefined;
|
|
111
118
|
let valueBudget = undefined;
|
|
112
119
|
let embeddedXmpStepForFlat = undefined;
|
|
120
|
+
let decompressedApplicationNotesSize = 0;
|
|
113
121
|
|
|
114
122
|
const {
|
|
115
123
|
fileType,
|
|
@@ -128,6 +136,8 @@ export function loadView(
|
|
|
128
136
|
brobExifChunk,
|
|
129
137
|
brobXmpChunk,
|
|
130
138
|
jxlCodestreamOffset,
|
|
139
|
+
imageDimensionsOffset,
|
|
140
|
+
pixelInformationOffset,
|
|
131
141
|
metadataBlocks,
|
|
132
142
|
metadataTruncated,
|
|
133
143
|
exifDataView,
|
|
@@ -211,51 +221,27 @@ export function loadView(
|
|
|
211
221
|
const parsedExifTags = filterTagsForParse('exif', readTags, tagFilter);
|
|
212
222
|
parsedGroups.exif = parsedExifTags;
|
|
213
223
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
);
|
|
227
|
-
const parsedIptcTags =
|
|
228
|
-
filterTagsForParse('iptc', readIptcTags, tagFilter);
|
|
229
|
-
parsedGroups.iptc = parsedIptcTags;
|
|
230
|
-
|
|
231
|
-
if (tagFilter.shouldReturnGroup('iptc')) {
|
|
232
|
-
mergeSteps.push({
|
|
233
|
-
type: 'mergeGroupAssign',
|
|
234
|
-
groupKey: 'iptc',
|
|
235
|
-
parsedTags: parsedIptcTags,
|
|
236
|
-
});
|
|
224
|
+
const carriedGroups = readExifCarriedGroups(
|
|
225
|
+
parsedExifTags,
|
|
226
|
+
exifDataView || dataView,
|
|
227
|
+
tiffHeaderOffset,
|
|
228
|
+
byteOrder,
|
|
229
|
+
valueBudget,
|
|
230
|
+
{decompressed: false, hasIptcBlock: iptcDataOffset !== undefined}
|
|
231
|
+
);
|
|
232
|
+
for (let i = 0; i < EXIF_CARRIED_GROUP_ORDER.length; i++) {
|
|
233
|
+
const groupKey = EXIF_CARRIED_GROUP_ORDER[i];
|
|
234
|
+
if (carriedGroups[groupKey] === undefined) {
|
|
235
|
+
continue;
|
|
237
236
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
&& isNumberArray(parsedExifTags['ApplicationNotes'].value)
|
|
244
|
-
&& !hasXmpData(xmpChunks)
|
|
245
|
-
&& tagFilter.shouldParseGroup('xmp')
|
|
246
|
-
) {
|
|
247
|
-
const readXmpTags = XmpTags.read(
|
|
248
|
-
getByteString(parsedExifTags['ApplicationNotes'].value),
|
|
249
|
-
undefined,
|
|
250
|
-
domParser
|
|
251
|
-
);
|
|
252
|
-
const parsedXmpTags = filterTagsForParse('xmp', readXmpTags, tagFilter);
|
|
253
|
-
parsedGroups.xmp = parsedXmpTags;
|
|
254
|
-
|
|
255
|
-
if (tagFilter.shouldReturnGroup('xmp')) {
|
|
237
|
+
parsedGroups[groupKey] = carriedGroups[groupKey];
|
|
238
|
+
if (!tagFilter.shouldReturnGroup(groupKey)) {
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
if (groupKey === 'xmp') {
|
|
256
242
|
const step = {
|
|
257
243
|
type: 'mergeXmpGroupAssign',
|
|
258
|
-
parsedTags:
|
|
244
|
+
parsedTags: carriedGroups.xmp,
|
|
259
245
|
};
|
|
260
246
|
|
|
261
247
|
if (expanded) {
|
|
@@ -263,110 +249,15 @@ export function loadView(
|
|
|
263
249
|
} else {
|
|
264
250
|
embeddedXmpStepForFlat = step;
|
|
265
251
|
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
if (
|
|
270
|
-
Constants.USE_PHOTOSHOP
|
|
271
|
-
&& parsedExifTags['ImageSourceData']
|
|
272
|
-
&& parsedExifTags['PhotoshopSettings']
|
|
273
|
-
&& Array.isArray(parsedExifTags['PhotoshopSettings'].value)
|
|
274
|
-
&& tagFilter.shouldParseGroup('photoshop')
|
|
275
|
-
) {
|
|
276
|
-
const readPhotoshopTags = PhotoshopTags.read(
|
|
277
|
-
parsedExifTags['PhotoshopSettings'].value,
|
|
278
|
-
includeUnknown,
|
|
279
|
-
tagFilter
|
|
280
|
-
);
|
|
281
|
-
const parsedPhotoshopTags =
|
|
282
|
-
filterTagsForParse('photoshop', readPhotoshopTags, tagFilter);
|
|
283
|
-
parsedGroups.photoshop = parsedPhotoshopTags;
|
|
284
|
-
|
|
285
|
-
if (tagFilter.shouldReturnGroup('photoshop')) {
|
|
252
|
+
} else {
|
|
286
253
|
mergeSteps.push({
|
|
287
254
|
type: 'mergeGroupAssign',
|
|
288
|
-
groupKey
|
|
289
|
-
parsedTags:
|
|
255
|
+
groupKey,
|
|
256
|
+
parsedTags: carriedGroups[groupKey],
|
|
290
257
|
});
|
|
291
258
|
}
|
|
292
259
|
}
|
|
293
260
|
|
|
294
|
-
if (
|
|
295
|
-
Constants.USE_ICC
|
|
296
|
-
&& parsedExifTags['ICC_Profile']
|
|
297
|
-
&& !hasIccData(iccChunks)
|
|
298
|
-
&& tagFilter.shouldParseGroup('icc')
|
|
299
|
-
) {
|
|
300
|
-
const readIccTags = IccTags.read(
|
|
301
|
-
parsedExifTags['ICC_Profile'].value,
|
|
302
|
-
[{
|
|
303
|
-
offset: 0,
|
|
304
|
-
length: parsedExifTags['ICC_Profile'].value.length,
|
|
305
|
-
chunkNumber: 1,
|
|
306
|
-
chunksTotal: 1
|
|
307
|
-
}]
|
|
308
|
-
);
|
|
309
|
-
const parsedIccTags = filterTagsForParse('icc', readIccTags, tagFilter);
|
|
310
|
-
parsedGroups.icc = parsedIccTags;
|
|
311
|
-
|
|
312
|
-
if (tagFilter.shouldReturnGroup('icc')) {
|
|
313
|
-
mergeSteps.push({
|
|
314
|
-
type: 'mergeGroupAssign',
|
|
315
|
-
groupKey: 'icc',
|
|
316
|
-
parsedTags: parsedIccTags,
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
if (
|
|
322
|
-
Constants.USE_MAKER_NOTES
|
|
323
|
-
&& parsedExifTags['MakerNote']
|
|
324
|
-
&& tagFilter.shouldParseGroup('makerNotes')
|
|
325
|
-
) {
|
|
326
|
-
if (hasCanonData(parsedExifTags)) {
|
|
327
|
-
const readCanonTags = CanonTags.read(
|
|
328
|
-
exifDataView || dataView,
|
|
329
|
-
tiffHeaderOffset,
|
|
330
|
-
parsedExifTags['MakerNote'].__offset,
|
|
331
|
-
byteOrder,
|
|
332
|
-
includeUnknown,
|
|
333
|
-
computed,
|
|
334
|
-
tagFilter,
|
|
335
|
-
valueBudget
|
|
336
|
-
);
|
|
337
|
-
parsedGroups.makerNotes = readCanonTags;
|
|
338
|
-
if (tagFilter.shouldReturnGroup('makerNotes')) {
|
|
339
|
-
mergeSteps.push({
|
|
340
|
-
type: 'mergeGroupAssign',
|
|
341
|
-
groupKey: 'makerNotes',
|
|
342
|
-
parsedTags: readCanonTags,
|
|
343
|
-
});
|
|
344
|
-
}
|
|
345
|
-
} else if (hasPentaxType1Data(parsedExifTags)) {
|
|
346
|
-
const readPentaxTags = PentaxTags.read(
|
|
347
|
-
exifDataView || dataView,
|
|
348
|
-
tiffHeaderOffset,
|
|
349
|
-
parsedExifTags['MakerNote'].__offset,
|
|
350
|
-
includeUnknown,
|
|
351
|
-
computed,
|
|
352
|
-
tagFilter,
|
|
353
|
-
valueBudget
|
|
354
|
-
);
|
|
355
|
-
parsedGroups.makerNotes = readPentaxTags;
|
|
356
|
-
if (tagFilter.shouldReturnGroup('makerNotes')) {
|
|
357
|
-
mergeSteps.push({
|
|
358
|
-
type: 'mergeGroupAssign',
|
|
359
|
-
groupKey: 'makerNotes',
|
|
360
|
-
parsedTags: readPentaxTags,
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
if (parsedExifTags['MakerNote']) {
|
|
367
|
-
delete parsedExifTags['MakerNote'].__offset;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
261
|
if (tagFilter.shouldReturnGroup('exif')) {
|
|
371
262
|
mergeSteps.push({
|
|
372
263
|
type: 'mergeGroupAssign',
|
|
@@ -421,6 +312,8 @@ export function loadView(
|
|
|
421
312
|
}
|
|
422
313
|
}
|
|
423
314
|
|
|
315
|
+
const readEmbeddedExifThumbnail = getEmbeddedExifThumbnailReader(tagFilter, dataView);
|
|
316
|
+
|
|
424
317
|
if (
|
|
425
318
|
Constants.USE_JXL
|
|
426
319
|
&& Constants.USE_EXIF
|
|
@@ -435,7 +328,7 @@ export function loadView(
|
|
|
435
328
|
.then((decompressedDataView) => {
|
|
436
329
|
const brobTiffHeaderOffset = getTiffHeaderOffset(decompressedDataView, 0);
|
|
437
330
|
addDecompressedValueAllowance(valueBudget, decompressedDataView.byteLength);
|
|
438
|
-
const {tags: readTags} = Tags.read(
|
|
331
|
+
const {tags: readTags, byteOrder: brobByteOrder} = Tags.read(
|
|
439
332
|
decompressedDataView,
|
|
440
333
|
brobTiffHeaderOffset,
|
|
441
334
|
includeUnknown,
|
|
@@ -443,16 +336,24 @@ export function loadView(
|
|
|
443
336
|
tagFilter,
|
|
444
337
|
valueBudget
|
|
445
338
|
);
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
339
|
+
const thumbnail = takeEmbeddedExifThumbnail(
|
|
340
|
+
readTags,
|
|
341
|
+
decompressedDataView,
|
|
342
|
+
brobTiffHeaderOffset,
|
|
343
|
+
readEmbeddedExifThumbnail
|
|
344
|
+
);
|
|
345
|
+
const carriedGroups = readEmbeddedExifCarriedGroups(
|
|
346
|
+
decompressedDataView,
|
|
347
|
+
readTags,
|
|
348
|
+
brobTiffHeaderOffset,
|
|
349
|
+
brobByteOrder,
|
|
350
|
+
valueBudget,
|
|
351
|
+
{decompressed: true, hasIptcBlock: false}
|
|
352
|
+
);
|
|
353
|
+
deferredResults.brobExif = {exifTags: readTags, carriedGroups, thumbnail};
|
|
453
354
|
})
|
|
454
355
|
.catch(() => {
|
|
455
|
-
deferredResults.brobExif =
|
|
356
|
+
deferredResults.brobExif = undefined;
|
|
456
357
|
})
|
|
457
358
|
);
|
|
458
359
|
mergeSteps.push({
|
|
@@ -473,7 +374,7 @@ export function loadView(
|
|
|
473
374
|
deferredPromises.push(
|
|
474
375
|
decompress(compressedXmpData, COMPRESSION_METHOD_BROTLI, undefined, 'dataview', decompressConfig)
|
|
475
376
|
.then((decompressedDataView) => {
|
|
476
|
-
if (exceedsBrobXmpSizeBound(decompressedDataView, dataView)) {
|
|
377
|
+
if (exceedsBrobXmpSizeBound(decompressedDataView.byteLength, dataView)) {
|
|
477
378
|
deferredResults.brobXmp = {};
|
|
478
379
|
return;
|
|
479
380
|
}
|
|
@@ -576,7 +477,7 @@ export function loadView(
|
|
|
576
477
|
|| tagFilter.shouldParseGroup('iptc')
|
|
577
478
|
)
|
|
578
479
|
) {
|
|
579
|
-
const {readTags, embeddedExifTags, embeddedIptcTags, embeddedExifThumbnail, readTagsPromise} = PngTextTags.read(
|
|
480
|
+
const {readTags, embeddedExifTags, embeddedIptcTags, embeddedExifThumbnail, exifCarriedGroups, readTagsPromise} = PngTextTags.read(
|
|
580
481
|
dataView,
|
|
581
482
|
pngTextChunks,
|
|
582
483
|
async,
|
|
@@ -585,7 +486,8 @@ export function loadView(
|
|
|
585
486
|
tagFilter,
|
|
586
487
|
decompressConfig,
|
|
587
488
|
valueBudget,
|
|
588
|
-
|
|
489
|
+
readEmbeddedExifThumbnail,
|
|
490
|
+
readEmbeddedExifCarriedGroups
|
|
589
491
|
);
|
|
590
492
|
pngTextIsAsync = !!readTagsPromise;
|
|
591
493
|
|
|
@@ -595,6 +497,7 @@ export function loadView(
|
|
|
595
497
|
embeddedExifTags,
|
|
596
498
|
embeddedIptcTags,
|
|
597
499
|
embeddedExifThumbnail,
|
|
500
|
+
exifCarriedGroups,
|
|
598
501
|
});
|
|
599
502
|
|
|
600
503
|
if (readTagsPromise) {
|
|
@@ -679,6 +582,24 @@ export function loadView(
|
|
|
679
582
|
}
|
|
680
583
|
}
|
|
681
584
|
|
|
585
|
+
if (
|
|
586
|
+
(Constants.USE_HEIC || Constants.USE_AVIF)
|
|
587
|
+
&& (imageDimensionsOffset !== undefined || pixelInformationOffset !== undefined)
|
|
588
|
+
&& tagFilter.shouldParseGroup('file')
|
|
589
|
+
) {
|
|
590
|
+
const readTags = IsoBmffFileTags.read(dataView, imageDimensionsOffset, pixelInformationOffset);
|
|
591
|
+
const parsedIsoBmffFileTags = filterTagsForParse('file', readTags, tagFilter);
|
|
592
|
+
parsedGroups.file = parsedIsoBmffFileTags;
|
|
593
|
+
|
|
594
|
+
if (tagFilter.shouldReturnGroup('file')) {
|
|
595
|
+
mergeSteps.push({
|
|
596
|
+
type: 'mergeGroupAssign',
|
|
597
|
+
groupKey: 'file',
|
|
598
|
+
parsedTags: parsedIsoBmffFileTags,
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
|
|
682
603
|
if (Constants.USE_EXIF) {
|
|
683
604
|
mergeSteps.push({type: 'gps'});
|
|
684
605
|
}
|
|
@@ -764,6 +685,140 @@ export function loadView(
|
|
|
764
685
|
}
|
|
765
686
|
return !(Array.isArray(file) && file.length === 1 && file[0] === 'FileType');
|
|
766
687
|
}
|
|
688
|
+
|
|
689
|
+
// Drops MakerNote.__offset once the maker note has been read, even when a
|
|
690
|
+
// reader throws.
|
|
691
|
+
function readExifCarriedGroups(parsedExifTags, exifTiffDataView, exifTiffHeaderOffset, exifByteOrder, exifValueBudget, source) {
|
|
692
|
+
const groups = {};
|
|
693
|
+
|
|
694
|
+
try {
|
|
695
|
+
if (
|
|
696
|
+
Constants.USE_IPTC
|
|
697
|
+
&& parsedExifTags['IPTC-NAA']
|
|
698
|
+
&& !source.hasIptcBlock
|
|
699
|
+
&& tagFilter.shouldParseGroup('iptc')
|
|
700
|
+
) {
|
|
701
|
+
const readIptcTags = IptcTags.read(
|
|
702
|
+
parsedExifTags['IPTC-NAA'].value,
|
|
703
|
+
0,
|
|
704
|
+
includeUnknown,
|
|
705
|
+
tagFilter,
|
|
706
|
+
exifValueBudget
|
|
707
|
+
);
|
|
708
|
+
groups.iptc = filterTagsForParse('iptc', readIptcTags, tagFilter);
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
if (
|
|
712
|
+
Constants.USE_XMP
|
|
713
|
+
&& parsedExifTags['ApplicationNotes']
|
|
714
|
+
&& isNumberArray(parsedExifTags['ApplicationNotes'].value)
|
|
715
|
+
&& !hasXmpData(xmpChunks)
|
|
716
|
+
&& tagFilter.shouldParseGroup('xmp')
|
|
717
|
+
&& (!source.decompressed || takeDecompressedApplicationNotesAllowance(parsedExifTags['ApplicationNotes'].value.length))
|
|
718
|
+
) {
|
|
719
|
+
const readXmpTags = XmpTags.read(
|
|
720
|
+
getByteString(parsedExifTags['ApplicationNotes'].value),
|
|
721
|
+
undefined,
|
|
722
|
+
domParser
|
|
723
|
+
);
|
|
724
|
+
groups.xmp = filterTagsForParse('xmp', readXmpTags, tagFilter);
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
if (
|
|
728
|
+
Constants.USE_PHOTOSHOP
|
|
729
|
+
&& parsedExifTags['ImageSourceData']
|
|
730
|
+
&& parsedExifTags['PhotoshopSettings']
|
|
731
|
+
&& Array.isArray(parsedExifTags['PhotoshopSettings'].value)
|
|
732
|
+
&& tagFilter.shouldParseGroup('photoshop')
|
|
733
|
+
) {
|
|
734
|
+
const readPhotoshopTags = PhotoshopTags.read(
|
|
735
|
+
parsedExifTags['PhotoshopSettings'].value,
|
|
736
|
+
includeUnknown,
|
|
737
|
+
tagFilter
|
|
738
|
+
);
|
|
739
|
+
groups.photoshop = filterTagsForParse('photoshop', readPhotoshopTags, tagFilter);
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
if (
|
|
743
|
+
Constants.USE_ICC
|
|
744
|
+
&& parsedExifTags['ICC_Profile']
|
|
745
|
+
&& !hasIccData(iccChunks)
|
|
746
|
+
&& tagFilter.shouldParseGroup('icc')
|
|
747
|
+
) {
|
|
748
|
+
const readIccTags = IccTags.read(
|
|
749
|
+
parsedExifTags['ICC_Profile'].value,
|
|
750
|
+
[{
|
|
751
|
+
offset: 0,
|
|
752
|
+
length: parsedExifTags['ICC_Profile'].value.length,
|
|
753
|
+
chunkNumber: 1,
|
|
754
|
+
chunksTotal: 1
|
|
755
|
+
}]
|
|
756
|
+
);
|
|
757
|
+
groups.icc = filterTagsForParse('icc', readIccTags, tagFilter);
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
if (
|
|
761
|
+
Constants.USE_MAKER_NOTES
|
|
762
|
+
&& parsedExifTags['MakerNote']
|
|
763
|
+
&& tagFilter.shouldParseGroup('makerNotes')
|
|
764
|
+
) {
|
|
765
|
+
if (hasCanonData(parsedExifTags)) {
|
|
766
|
+
groups.makerNotes = CanonTags.read(
|
|
767
|
+
exifTiffDataView,
|
|
768
|
+
exifTiffHeaderOffset,
|
|
769
|
+
parsedExifTags['MakerNote'].__offset,
|
|
770
|
+
exifByteOrder,
|
|
771
|
+
includeUnknown,
|
|
772
|
+
computed,
|
|
773
|
+
tagFilter,
|
|
774
|
+
exifValueBudget
|
|
775
|
+
);
|
|
776
|
+
} else if (hasPentaxType1Data(parsedExifTags)) {
|
|
777
|
+
groups.makerNotes = PentaxTags.read(
|
|
778
|
+
exifTiffDataView,
|
|
779
|
+
exifTiffHeaderOffset,
|
|
780
|
+
parsedExifTags['MakerNote'].__offset,
|
|
781
|
+
includeUnknown,
|
|
782
|
+
computed,
|
|
783
|
+
tagFilter,
|
|
784
|
+
exifValueBudget
|
|
785
|
+
);
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
} finally {
|
|
789
|
+
if (parsedExifTags['MakerNote']) {
|
|
790
|
+
delete parsedExifTags['MakerNote'].__offset;
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
return groups;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
// The brob XMP bound covers the decompressed Exif blocks of a file together,
|
|
798
|
+
// so that several cannot each pass it.
|
|
799
|
+
function takeDecompressedApplicationNotesAllowance(byteLength) {
|
|
800
|
+
if (exceedsBrobXmpSizeBound(decompressedApplicationNotesSize + byteLength, dataView)) {
|
|
801
|
+
return false;
|
|
802
|
+
}
|
|
803
|
+
decompressedApplicationNotesSize += byteLength;
|
|
804
|
+
return true;
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
// A maker note that throws must drop the groups, not the Exif tags already read.
|
|
808
|
+
function readEmbeddedExifCarriedGroups(exifTiffDataView, readTags, exifTiffHeaderOffset, exifByteOrder, exifValueBudget, source) {
|
|
809
|
+
try {
|
|
810
|
+
return readExifCarriedGroups(
|
|
811
|
+
filterTagsForParse('exif', readTags, tagFilter),
|
|
812
|
+
exifTiffDataView,
|
|
813
|
+
exifTiffHeaderOffset,
|
|
814
|
+
exifByteOrder,
|
|
815
|
+
exifValueBudget,
|
|
816
|
+
source
|
|
817
|
+
);
|
|
818
|
+
} catch (error) {
|
|
819
|
+
return {};
|
|
820
|
+
}
|
|
821
|
+
}
|
|
767
822
|
}
|
|
768
823
|
|
|
769
824
|
// A caller-supplied DataView can be a window into a larger buffer. Extractors
|
|
@@ -793,9 +848,8 @@ function isDataViewLike(dataView) {
|
|
|
793
848
|
}
|
|
794
849
|
|
|
795
850
|
function getBrobDataView(dataView, brobChunk) {
|
|
796
|
-
// The box length is untrusted
|
|
797
|
-
//
|
|
798
|
-
// parser never reports a dataOffset past the end of the view.
|
|
851
|
+
// The box length is untrusted, so bound the view by the bytes present. The
|
|
852
|
+
// JXL header parser never reports a dataOffset past the end of the view.
|
|
799
853
|
const length = Math.max(0, Math.min(brobChunk.length, dataView.byteLength - brobChunk.dataOffset));
|
|
800
854
|
if (isDataViewLike(dataView)) {
|
|
801
855
|
return new DataView(dataView.buffer, dataView.byteOffset + brobChunk.dataOffset, length);
|
|
@@ -808,9 +862,8 @@ function getBrobDataView(dataView, brobChunk) {
|
|
|
808
862
|
return new DataView(bytes.buffer);
|
|
809
863
|
}
|
|
810
864
|
|
|
811
|
-
function exceedsBrobXmpSizeBound(
|
|
812
|
-
return
|
|
813
|
-
> BROB_XMP_SIZE_PER_INPUT_SIZE * inputDataView.byteLength + BROB_XMP_SIZE_ALLOWANCE;
|
|
865
|
+
function exceedsBrobXmpSizeBound(byteLength, inputDataView) {
|
|
866
|
+
return byteLength > BROB_XMP_SIZE_PER_INPUT_SIZE * inputDataView.byteLength + BROB_XMP_SIZE_ALLOWANCE;
|
|
814
867
|
}
|
|
815
868
|
|
|
816
869
|
function readExifTagsSafely(dataView, tiffHeaderOffset, includeUnknown, computed, tagFilter) {
|
|
@@ -831,7 +884,7 @@ function readExifTagsSafely(dataView, tiffHeaderOffset, includeUnknown, computed
|
|
|
831
884
|
}
|
|
832
885
|
}
|
|
833
886
|
|
|
834
|
-
function
|
|
887
|
+
function getEmbeddedExifThumbnailReader(tagFilter, inputDataView) {
|
|
835
888
|
if (
|
|
836
889
|
!Constants.USE_EXIF
|
|
837
890
|
|| !Constants.USE_THUMBNAIL
|
|
@@ -839,11 +892,27 @@ function getPngTextThumbnailReader(tagFilter) {
|
|
|
839
892
|
) {
|
|
840
893
|
return undefined;
|
|
841
894
|
}
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
filterTagsForParse('thumbnail', thumbnailIfdTags, tagFilter)
|
|
845
|
-
|
|
846
|
-
|
|
895
|
+
let copiedThumbnailSize = 0;
|
|
896
|
+
return (dataView, thumbnailIfdTags, tiffHeaderOffset) => {
|
|
897
|
+
const parsedThumbnailIfdTags = filterTagsForParse('thumbnail', thumbnailIfdTags, tagFilter);
|
|
898
|
+
const lengthTag = parsedThumbnailIfdTags.JPEGInterchangeFormatLength;
|
|
899
|
+
const sizeBound =
|
|
900
|
+
EMBEDDED_THUMBNAIL_SIZE_PER_INPUT_SIZE * inputDataView.byteLength + EMBEDDED_THUMBNAIL_SIZE_ALLOWANCE;
|
|
901
|
+
if (!hasLengthWithin(lengthTag, sizeBound - copiedThumbnailSize)) {
|
|
902
|
+
return parsedThumbnailIfdTags;
|
|
903
|
+
}
|
|
904
|
+
const thumbnail = Thumbnail.get(dataView, parsedThumbnailIfdTags, tiffHeaderOffset);
|
|
905
|
+
if (thumbnail.image) {
|
|
906
|
+
copiedThumbnailSize += lengthTag.value;
|
|
907
|
+
}
|
|
908
|
+
return thumbnail;
|
|
909
|
+
};
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
function hasLengthWithin(lengthTag, maxLength) {
|
|
913
|
+
return !!lengthTag
|
|
914
|
+
&& typeof lengthTag.value === 'number'
|
|
915
|
+
&& lengthTag.value <= maxLength;
|
|
847
916
|
}
|
|
848
917
|
|
|
849
918
|
function filterTagsForParse(groupKey, readTags, tagFilter) {
|
|
@@ -912,6 +981,8 @@ function hasPotentialMetaData({
|
|
|
912
981
|
vp8xChunkOffset,
|
|
913
982
|
gifHeaderOffset,
|
|
914
983
|
jxlCodestreamOffset,
|
|
984
|
+
imageDimensionsOffset,
|
|
985
|
+
pixelInformationOffset,
|
|
915
986
|
}) {
|
|
916
987
|
return !!fileType
|
|
917
988
|
|| (
|
|
@@ -969,6 +1040,10 @@ function hasPotentialMetaData({
|
|
|
969
1040
|
|| (
|
|
970
1041
|
Constants.USE_JXL
|
|
971
1042
|
&& jxlCodestreamOffset !== undefined
|
|
1043
|
+
)
|
|
1044
|
+
|| (
|
|
1045
|
+
(Constants.USE_HEIC || Constants.USE_AVIF)
|
|
1046
|
+
&& (imageDimensionsOffset !== undefined || pixelInformationOffset !== undefined)
|
|
972
1047
|
);
|
|
973
1048
|
}
|
|
974
1049
|
|
package/src/file-loaders.js
CHANGED
|
@@ -6,9 +6,10 @@
|
|
|
6
6
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
7
7
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
8
8
|
*/
|
|
9
|
-
/* global Buffer
|
|
9
|
+
/* global Buffer */
|
|
10
10
|
|
|
11
11
|
import {dataUriToBuffer} from './utils.js';
|
|
12
|
+
import NodeRequire from './node-require.js';
|
|
12
13
|
|
|
13
14
|
export const HTTP_STATUS_OK = 200;
|
|
14
15
|
export const HTTP_STATUS_SUCCESS_MAX = 299;
|
|
@@ -271,6 +272,9 @@ export function nodeGetRange(url, {start = 0, end, maxBytes} = {}) {
|
|
|
271
272
|
}
|
|
272
273
|
|
|
273
274
|
const get = requireNodeGet(url);
|
|
275
|
+
if (!get) {
|
|
276
|
+
return reject(new Error('Node http support is not available.'));
|
|
277
|
+
}
|
|
274
278
|
get(url, options, (response) => {
|
|
275
279
|
if ((response.statusCode >= HTTP_STATUS_OK) && (response.statusCode <= HTTP_STATUS_SUCCESS_MAX)) {
|
|
276
280
|
const totalSize = totalSizeFromNodeResponse(response);
|
|
@@ -358,10 +362,8 @@ function totalSizeFromRangeHeaders(contentRange, contentLength) {
|
|
|
358
362
|
}
|
|
359
363
|
|
|
360
364
|
function requireNodeGet(url) {
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
}
|
|
364
|
-
return __non_webpack_require__('http').get;
|
|
365
|
+
const http = NodeRequire.builtin(/^https:\/\//.test(url) ? 'https' : 'http');
|
|
366
|
+
return http && http.get;
|
|
365
367
|
}
|
|
366
368
|
|
|
367
369
|
/**
|
|
@@ -376,7 +378,10 @@ function requireNodeGet(url) {
|
|
|
376
378
|
*/
|
|
377
379
|
export function readLocalFileRange(filename, {start = 0, end, totalSize} = {}) {
|
|
378
380
|
return new Promise((resolve, reject) => {
|
|
379
|
-
const fs =
|
|
381
|
+
const fs = NodeRequire.builtin('fs');
|
|
382
|
+
if (!fs) {
|
|
383
|
+
return reject(new Error('Node file system support is not available.'));
|
|
384
|
+
}
|
|
380
385
|
fs.open(filename, (openErr, fd) => {
|
|
381
386
|
if (openErr) {
|
|
382
387
|
return reject(openErr);
|
|
@@ -417,14 +422,6 @@ function finishLocalRead(filename, closeErr, buffer, total, resolve) {
|
|
|
417
422
|
resolve({buffer, totalSize: total});
|
|
418
423
|
}
|
|
419
424
|
|
|
420
|
-
function requireNodeFs() {
|
|
421
|
-
try {
|
|
422
|
-
return __non_webpack_require__('fs');
|
|
423
|
-
} catch (error) {
|
|
424
|
-
return undefined;
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
|
|
428
425
|
/**
|
|
429
426
|
* Range-aware browser `File` reader. Uses `file.slice(start, end)` plus
|
|
430
427
|
* `FileReader.readAsArrayBuffer`.
|