exifreader 4.46.0 → 4.48.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 +100 -34
- package/bin/TagFilterPlugin.js +23 -14
- package/bin/analyze.js +345 -0
- package/bin/build.js +13 -2
- package/bin/cli.js +449 -23
- package/bin/custom-build-marker.js +78 -0
- package/bin/unshare-file.js +29 -0
- package/bin/verify-build.js +147 -0
- package/dist/exif-reader.js +1 -1
- package/dist/exif-reader.js.map +1 -1
- package/package.json +3 -3
- package/src/canon-tags.js +4 -2
- package/src/composite.js +94 -47
- package/src/exif-reader.js +81 -16
- package/src/file-loaders.js +204 -30
- package/src/image-header-iso-bmff-iloc.js +5 -2
- package/src/image-header-iso-bmff.js +41 -10
- package/src/image-header-jpeg.js +9 -2
- package/src/image-header-png.js +33 -21
- package/src/iptc-tags.js +46 -11
- package/src/load-auto.js +6 -3
- package/src/loadview-pipeline.js +111 -61
- package/src/mpf-tags.js +10 -3
- package/src/pentax-tags.js +49 -23
- package/src/photoshop-tag-names.js +6 -2
- package/src/photoshop-tags.js +15 -22
- package/src/png-text-tags.js +237 -77
- package/src/tag-decoder.js +10 -10
- package/src/tag-filter-config.js +2 -0
- package/src/tag-filter.js +2 -0
- package/src/tag-names-0th-ifd.js +13 -1
- package/src/tags-helpers.js +220 -44
- package/src/tags.js +22 -4
- package/src/types.js +0 -5
- package/src/utils.js +260 -32
- package/src/xml.js +19 -2
- package/src/xmp-element-depth.js +226 -0
- package/src/xmp-namespaces.js +22 -7
- package/src/xmp-tags.js +285 -165
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "exifreader",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.48.0",
|
|
4
4
|
"description": "Library that parses Exif metadata in images.",
|
|
5
5
|
"author": "Mattias Wallander <mattias@wallander.eu>",
|
|
6
6
|
"repository": {
|
|
@@ -25,14 +25,14 @@
|
|
|
25
25
|
"exifreader": "bin/cli.js"
|
|
26
26
|
},
|
|
27
27
|
"optionalDependencies": {
|
|
28
|
-
"@xmldom/xmldom": "^0.9.
|
|
28
|
+
"@xmldom/xmldom": "^0.9.12"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@babel/core": "^7.29.7",
|
|
32
32
|
"@babel/preset-env": "^7.29.7",
|
|
33
33
|
"@cypress/webpack-preprocessor": "^8.0.0",
|
|
34
34
|
"@eslint/js": "^9.39.5",
|
|
35
|
-
"@types/node": "^26.6.
|
|
35
|
+
"@types/node": "^26.6.3",
|
|
36
36
|
"babel-loader": "^10.0.0",
|
|
37
37
|
"c8": "^12.0.0",
|
|
38
38
|
"chai": "^6.2.2",
|
package/src/canon-tags.js
CHANGED
|
@@ -29,7 +29,8 @@ function read(
|
|
|
29
29
|
byteOrder,
|
|
30
30
|
includeUnknown,
|
|
31
31
|
computed = false,
|
|
32
|
-
tagFilter = undefined
|
|
32
|
+
tagFilter = undefined,
|
|
33
|
+
valueBudget = undefined
|
|
33
34
|
) {
|
|
34
35
|
let tags = readIfd(
|
|
35
36
|
dataView,
|
|
@@ -40,7 +41,8 @@ function read(
|
|
|
40
41
|
includeUnknown,
|
|
41
42
|
computed,
|
|
42
43
|
tagFilter,
|
|
43
|
-
'makerNotes'
|
|
44
|
+
'makerNotes',
|
|
45
|
+
valueBudget
|
|
44
46
|
);
|
|
45
47
|
|
|
46
48
|
if (tags['ShotInfo']) {
|
package/src/composite.js
CHANGED
|
@@ -26,14 +26,13 @@ function get(tags, expanded) {
|
|
|
26
26
|
const compositeTags = {};
|
|
27
27
|
let hasCompositeTags = false;
|
|
28
28
|
|
|
29
|
-
const focalLength = getTagValue(tags, 'exif', 'FocalLength', expanded);
|
|
30
|
-
const focalPlaneXResolution = getTagValue(tags, 'exif', 'FocalPlaneXResolution', expanded);
|
|
31
|
-
const focalPlaneYResolution = getTagValue(tags, 'exif', 'FocalPlaneYResolution', expanded);
|
|
32
|
-
const focalPlaneResolutionUnit = getTagValue(tags, 'exif', 'FocalPlaneResolutionUnit', expanded);
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|| getFocalLengthIn35mmFilmValue(focalPlaneXResolution, focalPlaneYResolution, focalPlaneResolutionUnit, imageWidth, imageHeight, focalLength);
|
|
29
|
+
const focalLength = getPositiveRational(getTagValue(tags, 'exif', 'FocalLength', expanded));
|
|
30
|
+
const focalPlaneXResolution = getPositiveRational(getTagValue(tags, 'exif', 'FocalPlaneXResolution', expanded));
|
|
31
|
+
const focalPlaneYResolution = getPositiveRational(getTagValue(tags, 'exif', 'FocalPlaneYResolution', expanded));
|
|
32
|
+
const focalPlaneResolutionUnit = getPositiveNumber(getTagValue(tags, 'exif', 'FocalPlaneResolutionUnit', expanded));
|
|
33
|
+
const pixelDimensions = getPixelDimensions(tags, expanded);
|
|
34
|
+
const focalLengthIn35mmFilm = getPositiveNumber(getTagValue(tags, 'exif', 'FocalLengthIn35mmFilm', expanded))
|
|
35
|
+
|| getFocalLengthIn35mmFilmValue(focalPlaneXResolution, focalPlaneYResolution, focalPlaneResolutionUnit, pixelDimensions.width, pixelDimensions.height, focalLength);
|
|
37
36
|
|
|
38
37
|
if (focalLengthIn35mmFilm) {
|
|
39
38
|
compositeTags.FocalLength35efl = {
|
|
@@ -72,14 +71,70 @@ function getTagValue(tags, group, tagName, expanded) {
|
|
|
72
71
|
return undefined;
|
|
73
72
|
}
|
|
74
73
|
|
|
74
|
+
/**
|
|
75
|
+
* Converts an Exif `[numerator, denominator]` array, an XMP `'n/d'` string,
|
|
76
|
+
* or a plain number or numeric string to a number.
|
|
77
|
+
*
|
|
78
|
+
* @returns {number|undefined} The number, or undefined when it, or either part
|
|
79
|
+
* of a rational, is not finite and positive.
|
|
80
|
+
*/
|
|
81
|
+
function getPositiveRational(value) {
|
|
82
|
+
if (typeof value === 'string') {
|
|
83
|
+
// The limit keeps a long run of slashes from allocating one part per slash.
|
|
84
|
+
const parts = value.split('/', 3);
|
|
85
|
+
if (parts.length === 1) {
|
|
86
|
+
return getPositiveNumber(value);
|
|
87
|
+
}
|
|
88
|
+
return getPositiveQuotient(parts);
|
|
89
|
+
}
|
|
90
|
+
if (Array.isArray(value)) {
|
|
91
|
+
return getPositiveQuotient(value);
|
|
92
|
+
}
|
|
93
|
+
return getPositiveNumber(value);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @returns {number|undefined} The value as a number when it is a number or a
|
|
98
|
+
* numeric string that is finite and positive, otherwise undefined.
|
|
99
|
+
*/
|
|
100
|
+
function getPositiveNumber(value) {
|
|
101
|
+
let number;
|
|
102
|
+
if (typeof value === 'number') {
|
|
103
|
+
number = value;
|
|
104
|
+
} else if (typeof value === 'string') {
|
|
105
|
+
number = Number(value);
|
|
106
|
+
}
|
|
107
|
+
return number > 0 && number < Infinity ? number : undefined;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function getPositiveQuotient(parts) {
|
|
111
|
+
if (parts.length !== 2) {
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
return getPositiveNumber(getPositiveNumber(parts[0]) / getPositiveNumber(parts[1]));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function getPixelDimensions(tags, expanded) {
|
|
118
|
+
const pixelXDimension = getPositiveNumber(getTagValue(tags, 'exif', 'PixelXDimension', expanded));
|
|
119
|
+
const pixelYDimension = getPositiveNumber(getTagValue(tags, 'exif', 'PixelYDimension', expanded));
|
|
120
|
+
if (pixelXDimension && pixelYDimension) {
|
|
121
|
+
return {width: pixelXDimension, height: pixelYDimension};
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
width: getPositiveNumber(getTagValue(tags, 'file', 'Image Width', expanded)),
|
|
125
|
+
height: getPositiveNumber(getTagValue(tags, 'file', 'Image Height', expanded))
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
75
129
|
/**
|
|
76
130
|
* Calculates the 35mm equivalent focal length from camera sensor data.
|
|
77
131
|
*
|
|
78
132
|
* This function determines how the field of view of a camera's sensor compares to a
|
|
79
133
|
* standard 35mm film frame (36mm × 24mm). The conversion involves:
|
|
80
134
|
*
|
|
81
|
-
* 1. **Sensor dimensions**:
|
|
82
|
-
*
|
|
135
|
+
* 1. **Sensor dimensions**: The original image size in pixels (PixelXDimension and
|
|
136
|
+
* PixelYDimension, or the file's size when absent) divided by the focal plane
|
|
137
|
+
* resolution (pixels per unit length)
|
|
83
138
|
* 2. **Crop factor**: The ratio between the sensor diagonal and the standard
|
|
84
139
|
* 35mm diagonal (43.27mm)
|
|
85
140
|
* 3. **Equivalent focal length**: Actual focal length multiplied by the crop factor
|
|
@@ -88,53 +143,47 @@ function getTagValue(tags, group, tagName, expanded) {
|
|
|
88
143
|
* field of view of a 75mm lens on a 35mm camera. This doesn't change the actual
|
|
89
144
|
* focal length or depth of field characteristics, only the angle of view.
|
|
90
145
|
*/
|
|
91
|
-
function getFocalLengthIn35mmFilmValue(focalPlaneXResolution, focalPlaneYResolution, focalPlaneResolutionUnit,
|
|
146
|
+
function getFocalLengthIn35mmFilmValue(focalPlaneXResolution, focalPlaneYResolution, focalPlaneResolutionUnit, pixelWidth, pixelHeight, focalLength) {
|
|
92
147
|
// Standard 35mm film diagonal is 43.27mm (calculated from 36mm x 24mm frame)
|
|
93
148
|
const DIAGONAL_35mm = 43.27;
|
|
94
149
|
|
|
95
|
-
if (focalPlaneXResolution && focalPlaneYResolution && focalPlaneResolutionUnit &&
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return undefined;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const focalPlaneXResolutionMm = focalPlaneXResolution[0] / focalPlaneXResolution[1] * resolutionUnitFactor;
|
|
113
|
-
const focalPlaneYResolutionMm = focalPlaneYResolution[0] / focalPlaneYResolution[1] * resolutionUnitFactor;
|
|
114
|
-
|
|
115
|
-
const sensorWidthMm = imageWidth / focalPlaneXResolutionMm;
|
|
116
|
-
const sensorHeightMm = imageHeight / focalPlaneYResolutionMm;
|
|
117
|
-
|
|
118
|
-
const sensorDiagonal = Math.sqrt(sensorWidthMm ** 2 + sensorHeightMm ** 2);
|
|
119
|
-
const focalLength35mm = (focalLength[0] / focalLength[1]) * (DIAGONAL_35mm / sensorDiagonal);
|
|
120
|
-
return focalLength35mm;
|
|
121
|
-
} catch (error) {
|
|
122
|
-
// Ignore.
|
|
150
|
+
if (focalPlaneXResolution && focalPlaneYResolution && focalPlaneResolutionUnit && pixelWidth && pixelHeight && focalLength) {
|
|
151
|
+
let resolutionUnitFactor;
|
|
152
|
+
switch (focalPlaneResolutionUnit) {
|
|
153
|
+
case FOCAL_PLANE_RESOLUTION_UNIT.INCHES:
|
|
154
|
+
resolutionUnitFactor = UNIT_FACTORS.INCHES_TO_MM;
|
|
155
|
+
break;
|
|
156
|
+
case FOCAL_PLANE_RESOLUTION_UNIT.CENTIMETERS:
|
|
157
|
+
resolutionUnitFactor = UNIT_FACTORS.CM_TO_MM;
|
|
158
|
+
break;
|
|
159
|
+
case FOCAL_PLANE_RESOLUTION_UNIT.MILLIMETERS:
|
|
160
|
+
resolutionUnitFactor = UNIT_FACTORS.MM_TO_MM;
|
|
161
|
+
break;
|
|
162
|
+
default:
|
|
163
|
+
return undefined;
|
|
123
164
|
}
|
|
165
|
+
|
|
166
|
+
const focalPlaneXResolutionMm = focalPlaneXResolution / resolutionUnitFactor;
|
|
167
|
+
const focalPlaneYResolutionMm = focalPlaneYResolution / resolutionUnitFactor;
|
|
168
|
+
|
|
169
|
+
const sensorWidthMm = pixelWidth / focalPlaneXResolutionMm;
|
|
170
|
+
const sensorHeightMm = pixelHeight / focalPlaneYResolutionMm;
|
|
171
|
+
|
|
172
|
+
const sensorDiagonal = Math.sqrt(sensorWidthMm ** 2 + sensorHeightMm ** 2);
|
|
173
|
+
const focalLength35mm = focalLength * (DIAGONAL_35mm / sensorDiagonal);
|
|
174
|
+
return getPositiveNumber(focalLength35mm);
|
|
124
175
|
}
|
|
125
176
|
return undefined;
|
|
126
177
|
}
|
|
127
178
|
|
|
128
179
|
function getScaleFactorTo35mmEquivalent(focalLength, focalLengthIn35mmFilm) {
|
|
129
180
|
if (focalLength && focalLengthIn35mmFilm) {
|
|
130
|
-
|
|
131
|
-
|
|
181
|
+
const value = getPositiveNumber(focalLengthIn35mmFilm / focalLength);
|
|
182
|
+
if (value) {
|
|
132
183
|
return {
|
|
133
184
|
value,
|
|
134
185
|
description: value.toFixed(1),
|
|
135
186
|
};
|
|
136
|
-
} catch (error) {
|
|
137
|
-
// Ignore.
|
|
138
187
|
}
|
|
139
188
|
}
|
|
140
189
|
return undefined;
|
|
@@ -144,14 +193,12 @@ function getFieldOfView(focalLengthIn35mmFilm) {
|
|
|
144
193
|
const FULL_FRAME_SENSOR_WIDTH_MM = 36;
|
|
145
194
|
|
|
146
195
|
if (focalLengthIn35mmFilm) {
|
|
147
|
-
|
|
148
|
-
|
|
196
|
+
const value = getPositiveNumber(2 * Math.atan(FULL_FRAME_SENSOR_WIDTH_MM / (2 * focalLengthIn35mmFilm)) * (180 / Math.PI));
|
|
197
|
+
if (value) {
|
|
149
198
|
return {
|
|
150
199
|
value,
|
|
151
200
|
description: value.toFixed(1) + ' deg',
|
|
152
201
|
};
|
|
153
|
-
} catch (error) {
|
|
154
|
-
// Ignore.
|
|
155
202
|
}
|
|
156
203
|
}
|
|
157
204
|
return undefined;
|
package/src/exif-reader.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
/* global Buffer */
|
|
10
10
|
|
|
11
|
-
import {objectAssign, decompress, COMPRESSION_METHOD_BROTLI, getDataView, getStringValueFromArray, assertPromiseSupport} from './utils.js';
|
|
11
|
+
import {objectAssign, decompress, withDecompressBudget, COMPRESSION_METHOD_BROTLI, getDataView, getByteString, getStringValueFromArray, assertPromiseSupport, setProperty} from './utils.js';
|
|
12
12
|
import {isFilePathOrURL, isBrowserFileObject, loadFile, loadFileObject} from './file-loaders.js';
|
|
13
13
|
import {makeLoadAuto, validateAutoOptions} from './load-auto.js';
|
|
14
14
|
import Constants from './constants.js';
|
|
@@ -17,6 +17,7 @@ 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
21
|
import MpfTags from './mpf-tags.js';
|
|
21
22
|
import FileTags from './file-tags.js';
|
|
22
23
|
import JxlFileTags from './jxl-file-tags.js';
|
|
@@ -38,6 +39,11 @@ import {createTagFilter} from './tag-filter.js';
|
|
|
38
39
|
import {buildTagsFromMergeSteps, isThenable} from './loadview-pipeline.js';
|
|
39
40
|
import exifErrors from './errors.js';
|
|
40
41
|
|
|
42
|
+
// Brob XMP is bounded by the file size, as brob Exif is, plus room for one JPEG
|
|
43
|
+
// standard XMP segment so that a small file can still carry a typical packet.
|
|
44
|
+
const BROB_XMP_SIZE_PER_INPUT_SIZE = 4;
|
|
45
|
+
const BROB_XMP_SIZE_ALLOWANCE = 64 * 1024;
|
|
46
|
+
|
|
41
47
|
export default {
|
|
42
48
|
load,
|
|
43
49
|
loadView,
|
|
@@ -93,6 +99,7 @@ export function loadView(
|
|
|
93
99
|
} = {}
|
|
94
100
|
) {
|
|
95
101
|
dataView = getSelfContainedDataView(dataView);
|
|
102
|
+
decompressConfig = withDecompressBudget(decompressConfig);
|
|
96
103
|
|
|
97
104
|
const tagFilter = createTagFilter({includeTags, excludeTags});
|
|
98
105
|
const parsedGroups = Object.create(null);
|
|
@@ -101,6 +108,7 @@ export function loadView(
|
|
|
101
108
|
const deferredPromises = [];
|
|
102
109
|
let pngTextIsAsync = false;
|
|
103
110
|
let thumbnailIfdTags = undefined;
|
|
111
|
+
let valueBudget = undefined;
|
|
104
112
|
let embeddedXmpStepForFlat = undefined;
|
|
105
113
|
|
|
106
114
|
const {
|
|
@@ -187,13 +195,14 @@ export function loadView(
|
|
|
187
195
|
&& tiffHeaderOffset !== undefined
|
|
188
196
|
&& tagFilter.shouldParseGroup('exif')
|
|
189
197
|
) {
|
|
190
|
-
const {tags: readTags, byteOrder} = readExifTagsSafely(
|
|
198
|
+
const {tags: readTags, byteOrder, valueBudget: exifValueBudget} = readExifTagsSafely(
|
|
191
199
|
exifDataView || dataView,
|
|
192
200
|
tiffHeaderOffset,
|
|
193
201
|
includeUnknown,
|
|
194
202
|
computed,
|
|
195
203
|
tagFilter
|
|
196
204
|
);
|
|
205
|
+
valueBudget = exifValueBudget;
|
|
197
206
|
if (readTags.Thumbnail) {
|
|
198
207
|
thumbnailIfdTags = readTags.Thumbnail;
|
|
199
208
|
delete readTags.Thumbnail;
|
|
@@ -212,7 +221,8 @@ export function loadView(
|
|
|
212
221
|
parsedExifTags['IPTC-NAA'].value,
|
|
213
222
|
0,
|
|
214
223
|
includeUnknown,
|
|
215
|
-
tagFilter
|
|
224
|
+
tagFilter,
|
|
225
|
+
valueBudget
|
|
216
226
|
);
|
|
217
227
|
const parsedIptcTags =
|
|
218
228
|
filterTagsForParse('iptc', readIptcTags, tagFilter);
|
|
@@ -235,7 +245,7 @@ export function loadView(
|
|
|
235
245
|
&& tagFilter.shouldParseGroup('xmp')
|
|
236
246
|
) {
|
|
237
247
|
const readXmpTags = XmpTags.read(
|
|
238
|
-
|
|
248
|
+
getByteString(parsedExifTags['ApplicationNotes'].value),
|
|
239
249
|
undefined,
|
|
240
250
|
domParser
|
|
241
251
|
);
|
|
@@ -321,7 +331,8 @@ export function loadView(
|
|
|
321
331
|
byteOrder,
|
|
322
332
|
includeUnknown,
|
|
323
333
|
computed,
|
|
324
|
-
tagFilter
|
|
334
|
+
tagFilter,
|
|
335
|
+
valueBudget
|
|
325
336
|
);
|
|
326
337
|
parsedGroups.makerNotes = readCanonTags;
|
|
327
338
|
if (tagFilter.shouldReturnGroup('makerNotes')) {
|
|
@@ -338,7 +349,8 @@ export function loadView(
|
|
|
338
349
|
parsedExifTags['MakerNote'].__offset,
|
|
339
350
|
includeUnknown,
|
|
340
351
|
computed,
|
|
341
|
-
tagFilter
|
|
352
|
+
tagFilter,
|
|
353
|
+
valueBudget
|
|
342
354
|
);
|
|
343
355
|
parsedGroups.makerNotes = readPentaxTags;
|
|
344
356
|
if (tagFilter.shouldReturnGroup('makerNotes')) {
|
|
@@ -369,13 +381,17 @@ export function loadView(
|
|
|
369
381
|
}
|
|
370
382
|
}
|
|
371
383
|
|
|
384
|
+
if (valueBudget === undefined && dataView !== undefined) {
|
|
385
|
+
valueBudget = getValueBudget(dataView);
|
|
386
|
+
}
|
|
387
|
+
|
|
372
388
|
if (
|
|
373
389
|
Constants.USE_JPEG
|
|
374
390
|
&& Constants.USE_IPTC
|
|
375
391
|
&& iptcDataOffset !== undefined
|
|
376
392
|
&& tagFilter.shouldParseGroup('iptc')
|
|
377
393
|
) {
|
|
378
|
-
const readTags = IptcTags.read(dataView, iptcDataOffset, includeUnknown, tagFilter);
|
|
394
|
+
const readTags = IptcTags.read(dataView, iptcDataOffset, includeUnknown, tagFilter, valueBudget);
|
|
379
395
|
const parsedIptcTags = filterTagsForParse('iptc', readTags, tagFilter);
|
|
380
396
|
parsedGroups.iptc = parsedIptcTags;
|
|
381
397
|
|
|
@@ -418,16 +434,21 @@ export function loadView(
|
|
|
418
434
|
decompress(compressedExifData, COMPRESSION_METHOD_BROTLI, undefined, 'dataview', decompressConfig)
|
|
419
435
|
.then((decompressedDataView) => {
|
|
420
436
|
const brobTiffHeaderOffset = getTiffHeaderOffset(decompressedDataView, 0);
|
|
437
|
+
addDecompressedValueAllowance(valueBudget, decompressedDataView.byteLength);
|
|
421
438
|
const {tags: readTags} = Tags.read(
|
|
422
439
|
decompressedDataView,
|
|
423
440
|
brobTiffHeaderOffset,
|
|
424
441
|
includeUnknown,
|
|
425
442
|
computed,
|
|
426
|
-
tagFilter
|
|
443
|
+
tagFilter,
|
|
444
|
+
valueBudget
|
|
427
445
|
);
|
|
428
446
|
if (readTags.Thumbnail) {
|
|
429
447
|
delete readTags.Thumbnail;
|
|
430
448
|
}
|
|
449
|
+
if (readTags.MakerNote) {
|
|
450
|
+
delete readTags.MakerNote.__offset;
|
|
451
|
+
}
|
|
431
452
|
deferredResults.brobExif = readTags;
|
|
432
453
|
})
|
|
433
454
|
.catch(() => {
|
|
@@ -452,6 +473,10 @@ export function loadView(
|
|
|
452
473
|
deferredPromises.push(
|
|
453
474
|
decompress(compressedXmpData, COMPRESSION_METHOD_BROTLI, undefined, 'dataview', decompressConfig)
|
|
454
475
|
.then((decompressedDataView) => {
|
|
476
|
+
if (exceedsBrobXmpSizeBound(decompressedDataView, dataView)) {
|
|
477
|
+
deferredResults.brobXmp = {};
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
455
480
|
deferredResults.brobXmp = XmpTags.read(
|
|
456
481
|
decompressedDataView,
|
|
457
482
|
[{dataOffset: 0, length: decompressedDataView.byteLength}],
|
|
@@ -509,7 +534,8 @@ export function loadView(
|
|
|
509
534
|
mpfDataOffset,
|
|
510
535
|
includeUnknown,
|
|
511
536
|
computed,
|
|
512
|
-
tagFilter
|
|
537
|
+
tagFilter,
|
|
538
|
+
valueBudget
|
|
513
539
|
);
|
|
514
540
|
const parsedMpfTags = filterTagsForParse('mpf', readMpfTags, tagFilter);
|
|
515
541
|
parsedGroups.mpf = parsedMpfTags;
|
|
@@ -550,20 +576,25 @@ export function loadView(
|
|
|
550
576
|
|| tagFilter.shouldParseGroup('iptc')
|
|
551
577
|
)
|
|
552
578
|
) {
|
|
553
|
-
const {readTags, readTagsPromise} = PngTextTags.read(
|
|
579
|
+
const {readTags, embeddedExifTags, embeddedIptcTags, embeddedExifThumbnail, readTagsPromise} = PngTextTags.read(
|
|
554
580
|
dataView,
|
|
555
581
|
pngTextChunks,
|
|
556
582
|
async,
|
|
557
583
|
includeUnknown,
|
|
558
584
|
computed,
|
|
559
585
|
tagFilter,
|
|
560
|
-
decompressConfig
|
|
586
|
+
decompressConfig,
|
|
587
|
+
valueBudget,
|
|
588
|
+
getPngTextThumbnailReader(tagFilter)
|
|
561
589
|
);
|
|
562
590
|
pngTextIsAsync = !!readTagsPromise;
|
|
563
591
|
|
|
564
592
|
mergeSteps.push({
|
|
565
593
|
type: 'processPngTextReadTags',
|
|
566
594
|
readTags,
|
|
595
|
+
embeddedExifTags,
|
|
596
|
+
embeddedIptcTags,
|
|
597
|
+
embeddedExifThumbnail,
|
|
567
598
|
});
|
|
568
599
|
|
|
569
600
|
if (readTagsPromise) {
|
|
@@ -766,19 +797,53 @@ function getBrobDataView(dataView, brobChunk) {
|
|
|
766
797
|
// than its header, so bound the view by the bytes present. The JXL header
|
|
767
798
|
// parser never reports a dataOffset past the end of the view.
|
|
768
799
|
const length = Math.max(0, Math.min(brobChunk.length, dataView.byteLength - brobChunk.dataOffset));
|
|
769
|
-
|
|
800
|
+
if (isDataViewLike(dataView)) {
|
|
801
|
+
return new DataView(dataView.buffer, dataView.byteOffset + brobChunk.dataOffset, length);
|
|
802
|
+
}
|
|
803
|
+
// The Node Buffer wrapper has no ArrayBuffer to view, so copy the bytes out.
|
|
804
|
+
const bytes = new Uint8Array(length);
|
|
805
|
+
for (let i = 0; i < length; i++) {
|
|
806
|
+
bytes[i] = dataView.getUint8(brobChunk.dataOffset + i);
|
|
807
|
+
}
|
|
808
|
+
return new DataView(bytes.buffer);
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
function exceedsBrobXmpSizeBound(decompressedDataView, inputDataView) {
|
|
812
|
+
return decompressedDataView.byteLength
|
|
813
|
+
> BROB_XMP_SIZE_PER_INPUT_SIZE * inputDataView.byteLength + BROB_XMP_SIZE_ALLOWANCE;
|
|
770
814
|
}
|
|
771
815
|
|
|
772
816
|
function readExifTagsSafely(dataView, tiffHeaderOffset, includeUnknown, computed, tagFilter) {
|
|
817
|
+
// Created outside the try so values decoded before a throw still count
|
|
818
|
+
// against the budget that the maker note and MPF reads draw from. The data
|
|
819
|
+
// view is only missing in unit tests that fake the tag readers.
|
|
820
|
+
const valueBudget = dataView === undefined ? undefined : getValueBudget(dataView);
|
|
773
821
|
try {
|
|
774
|
-
|
|
822
|
+
const {tags, byteOrder} = Tags.read(dataView, tiffHeaderOffset, includeUnknown, computed, tagFilter, valueBudget);
|
|
823
|
+
return {tags, byteOrder, valueBudget};
|
|
775
824
|
} catch (error) {
|
|
776
825
|
// A malformed TIFF header (an out-of-bounds offset or an invalid byte
|
|
777
826
|
// order marker, e.g. from a HEIC/AVIF iloc that does not point at real
|
|
778
827
|
// Exif) must not abort the whole parse. Skip Exif instead, but keep the
|
|
779
|
-
// same {tags, byteOrder} shape so callers can destructure
|
|
780
|
-
|
|
828
|
+
// same {tags, byteOrder, valueBudget} shape so callers can destructure
|
|
829
|
+
// safely.
|
|
830
|
+
return {tags: {}, byteOrder: ByteOrder.BIG_ENDIAN, valueBudget};
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
function getPngTextThumbnailReader(tagFilter) {
|
|
835
|
+
if (
|
|
836
|
+
!Constants.USE_EXIF
|
|
837
|
+
|| !Constants.USE_THUMBNAIL
|
|
838
|
+
|| !tagFilter.shouldReturnTag('thumbnail', 'Thumbnail')
|
|
839
|
+
) {
|
|
840
|
+
return undefined;
|
|
781
841
|
}
|
|
842
|
+
return (dataView, thumbnailIfdTags, tiffHeaderOffset) => Thumbnail.get(
|
|
843
|
+
dataView,
|
|
844
|
+
filterTagsForParse('thumbnail', thumbnailIfdTags, tagFilter),
|
|
845
|
+
tiffHeaderOffset
|
|
846
|
+
);
|
|
782
847
|
}
|
|
783
848
|
|
|
784
849
|
function filterTagsForParse(groupKey, readTags, tagFilter) {
|
|
@@ -809,7 +874,7 @@ function filterTags(groupKey, readTags, matchesTag) {
|
|
|
809
874
|
const tagId = getTagId(tagValue);
|
|
810
875
|
|
|
811
876
|
if (matchesTag(groupKey, tagName, tagId)) {
|
|
812
|
-
filteredTags
|
|
877
|
+
setProperty(filteredTags, tagName, tagValue);
|
|
813
878
|
}
|
|
814
879
|
}
|
|
815
880
|
|