exifreader 4.45.0 → 4.45.2
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/dist/exif-reader.js +1 -1
- package/dist/exif-reader.js.map +1 -1
- package/exif-reader.d.ts +4 -0
- package/package.json +5 -5
- package/src/dataview.js +4 -0
- package/src/exif-reader.js +6 -2
- package/src/icc-tag-names.js +10 -1
- package/src/icc-tags.js +52 -14
- package/src/image-header-iso-bmff-iloc.js +4 -0
- package/src/image-header-iso-bmff-utils.js +4 -0
- package/src/image-header-iso-bmff.js +4 -0
- package/src/load-auto.js +2 -1
- package/src/loadview-pipeline.js +3 -6
- package/src/png-text-tags.js +4 -1
- package/src/xmp-namespaces.js +4 -0
package/exif-reader.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
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
|
+
|
|
1
5
|
/// <reference types="node" />
|
|
2
6
|
/// <reference lib="es2017.sharedmemory" />
|
|
3
7
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "exifreader",
|
|
3
|
-
"version": "4.45.
|
|
3
|
+
"version": "4.45.2",
|
|
4
4
|
"description": "Library that parses Exif metadata in images.",
|
|
5
5
|
"author": "Mattias Wallander <mattias@wallander.eu>",
|
|
6
6
|
"repository": {
|
|
@@ -32,24 +32,24 @@
|
|
|
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.
|
|
35
|
+
"@types/node": "^26.5.1",
|
|
36
36
|
"babel-loader": "^10.0.0",
|
|
37
37
|
"c8": "^12.0.0",
|
|
38
38
|
"chai": "^6.2.2",
|
|
39
39
|
"cross-env": "^10.0.0",
|
|
40
|
-
"cypress": "^
|
|
40
|
+
"cypress": "^16.0.0",
|
|
41
41
|
"eslint": "^9.39.4",
|
|
42
42
|
"eslint-plugin-cypress": "^6.4.4",
|
|
43
43
|
"globals": "^17.12.0",
|
|
44
44
|
"husky": "^9.0.11",
|
|
45
45
|
"linkedom": "^0.18.13",
|
|
46
|
-
"mocha": "^12.0.
|
|
46
|
+
"mocha": "^12.0.1",
|
|
47
47
|
"npm-run-all2": "^9.0.3",
|
|
48
48
|
"rimraf": "^5.0.5",
|
|
49
49
|
"string-replace-loader": "^3.1.0",
|
|
50
50
|
"terser-webpack-plugin": "^5.6.1",
|
|
51
51
|
"typescript": "^7.0.2",
|
|
52
|
-
"webpack": "5.
|
|
52
|
+
"webpack": "5.111.0",
|
|
53
53
|
"webpack-cli": "^7.2.3",
|
|
54
54
|
"webpack-dev-server": "^5.2.6"
|
|
55
55
|
},
|
package/src/dataview.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
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
|
+
|
|
1
5
|
export default class DataView {
|
|
2
6
|
constructor(buffer) {
|
|
3
7
|
if (bufferTypeIsUnsupported(buffer)) {
|
package/src/exif-reader.js
CHANGED
|
@@ -648,7 +648,9 @@ export function loadView(
|
|
|
648
648
|
}
|
|
649
649
|
}
|
|
650
650
|
|
|
651
|
-
|
|
651
|
+
if (Constants.USE_EXIF) {
|
|
652
|
+
mergeSteps.push({type: 'gps'});
|
|
653
|
+
}
|
|
652
654
|
if (Constants.USE_EXIF || Constants.USE_XMP) {
|
|
653
655
|
mergeSteps.push({type: 'composite'});
|
|
654
656
|
}
|
|
@@ -672,7 +674,9 @@ export function loadView(
|
|
|
672
674
|
hasPngTextData,
|
|
673
675
|
filterTagsForParse,
|
|
674
676
|
filterTagsForReturn,
|
|
675
|
-
|
|
677
|
+
// A plain property here would keep the function alive for the bundler,
|
|
678
|
+
// so a build without Exif would still carry getGpsGroupFromExifTags.
|
|
679
|
+
getGpsGroupFromExifTags: Constants.USE_EXIF ? getGpsGroupFromExifTags : undefined,
|
|
676
680
|
// A plain property here would keep the import alive for the bundler, so
|
|
677
681
|
// a build with neither Exif nor XMP would still carry composite.js.
|
|
678
682
|
Composite: (Constants.USE_EXIF || Constants.USE_XMP) ? Composite : undefined,
|
package/src/icc-tag-names.js
CHANGED
|
@@ -119,8 +119,17 @@ function parseDate(dataView, offset) {
|
|
|
119
119
|
return new Date(Date.UTC(year, month, day, hours, minutes, seconds));
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
+
// Engines cap the number of arguments Function.prototype.apply can pass
|
|
123
|
+
// through, so a large slice is converted in fixed-size chunks.
|
|
124
|
+
const MAX_CHARS_PER_CALL = 8192;
|
|
125
|
+
|
|
122
126
|
export function sliceToString(slice) {
|
|
123
|
-
|
|
127
|
+
const bytes = new Uint8Array(slice);
|
|
128
|
+
const chunks = [];
|
|
129
|
+
for (let offset = 0; offset < bytes.length; offset += MAX_CHARS_PER_CALL) {
|
|
130
|
+
chunks.push(String.fromCharCode.apply(null, bytes.subarray(offset, offset + MAX_CHARS_PER_CALL)));
|
|
131
|
+
}
|
|
132
|
+
return chunks.join('');
|
|
124
133
|
}
|
|
125
134
|
|
|
126
135
|
function toCompany(value) {
|
package/src/icc-tags.js
CHANGED
|
@@ -16,8 +16,12 @@ const TAG_TYPE_MULTI_LOCALIZED_UNICODE_TYPE = 'mluc';
|
|
|
16
16
|
const TAG_TYPE_TEXT = 'text';
|
|
17
17
|
const TAG_TYPE_SIGNATURE = 'sig ';
|
|
18
18
|
const TAG_TABLE_SINGLE_TAG_DATA = 12;
|
|
19
|
+
const DESC_VALUE_SIZE_OFFSET_END = 12;
|
|
19
20
|
const MIN_MULTI_LOCALIZED_UNICODE_RECORD_SIZE = 12;
|
|
20
21
|
const MULTI_LOCALIZED_UNICODE_RECORDS_OFFSET = 16;
|
|
22
|
+
const MAX_MLUC_RECORDS = 1000;
|
|
23
|
+
const MAX_TAG_COUNT = 1000;
|
|
24
|
+
const MAX_DECODE_BYTES = 1024 * 1024;
|
|
21
25
|
|
|
22
26
|
// ICC profile data can be longer than application segment max length of ~64k.
|
|
23
27
|
// so it can be split into multiple APP2 segments. Each segment includes
|
|
@@ -37,7 +41,10 @@ function readCompressedIcc(dataView, iccData, decompressConfig) {
|
|
|
37
41
|
return {};
|
|
38
42
|
}
|
|
39
43
|
const byteOffset = dataView.byteOffset || 0;
|
|
40
|
-
const
|
|
44
|
+
const slice = dataView.buffer.slice(byteOffset + iccData[0].offset, byteOffset + iccData[0].offset + iccData[0].length);
|
|
45
|
+
// On the Node Buffer wrapper, slice() returns a Buffer, which DataView
|
|
46
|
+
// rejects. Uint8Array copies a Buffer and leaves an ArrayBuffer as is.
|
|
47
|
+
const compressedDataView = new DataView(new Uint8Array(slice).buffer);
|
|
41
48
|
return decompress(compressedDataView, iccData[0].compressionMethod, 'utf-8', 'dataview', decompressConfig)
|
|
42
49
|
.then(parseTags)
|
|
43
50
|
.catch(() => ({}));
|
|
@@ -58,9 +65,10 @@ function readIcc(dataView, iccData) {
|
|
|
58
65
|
|
|
59
66
|
const iccBinaryData = new Uint8Array(totalIccProfileLength);
|
|
60
67
|
let offset = 0;
|
|
68
|
+
const chunksByNumber = getChunksByNumber(iccData);
|
|
61
69
|
|
|
62
70
|
for (let chunkNumber = 1; chunkNumber <= iccData.length; chunkNumber++) {
|
|
63
|
-
const iccDataChunk =
|
|
71
|
+
const iccDataChunk = chunksByNumber[chunkNumber];
|
|
64
72
|
if (!iccDataChunk) {
|
|
65
73
|
throw new Error(`ICC chunk ${chunkNumber} not found`);
|
|
66
74
|
}
|
|
@@ -85,6 +93,18 @@ function getBuffer(dataView) {
|
|
|
85
93
|
return dataView.buffer;
|
|
86
94
|
}
|
|
87
95
|
|
|
96
|
+
// A crafted file can repeat a chunk number. The first descriptor with that
|
|
97
|
+
// number is the one used.
|
|
98
|
+
function getChunksByNumber(iccData) {
|
|
99
|
+
const chunksByNumber = Object.create(null);
|
|
100
|
+
for (let i = 0; i < iccData.length; i++) {
|
|
101
|
+
if (chunksByNumber[iccData[i].chunkNumber] === undefined) {
|
|
102
|
+
chunksByNumber[iccData[i].chunkNumber] = iccData[i];
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return chunksByNumber;
|
|
106
|
+
}
|
|
107
|
+
|
|
88
108
|
function iccDoesNotHaveTagCount(dataView) {
|
|
89
109
|
return dataView.byteLength < (ICC_TAG_COUNT_OFFSET + 4);
|
|
90
110
|
}
|
|
@@ -94,7 +114,6 @@ function doesNotHaveTagData(dataView, tagHeaderOffset) {
|
|
|
94
114
|
}
|
|
95
115
|
|
|
96
116
|
export function parseTags(dataView) {
|
|
97
|
-
const MAX_MLUC_RECORDS = 1000;
|
|
98
117
|
const buffer = dataView.buffer;
|
|
99
118
|
|
|
100
119
|
const length = dataView.getUint32();
|
|
@@ -134,11 +153,11 @@ export function parseTags(dataView) {
|
|
|
134
153
|
return tags;
|
|
135
154
|
}
|
|
136
155
|
|
|
137
|
-
const tagCount = dataView.getUint32(
|
|
156
|
+
const tagCount = Math.min(dataView.getUint32(ICC_TAG_COUNT_OFFSET), MAX_TAG_COUNT);
|
|
138
157
|
let tagHeaderOffset = 132;
|
|
139
|
-
// Budget for
|
|
140
|
-
// the
|
|
141
|
-
|
|
158
|
+
// Budget for everything decoded from tag data (desc, text and mluc) across
|
|
159
|
+
// the whole profile, bounded by its size and a constant far above real text.
|
|
160
|
+
const decodeBudget = {remaining: Math.min(dataView.byteLength, MAX_DECODE_BYTES)};
|
|
142
161
|
|
|
143
162
|
for (let i = 0; i < tagCount; i++) {
|
|
144
163
|
if (doesNotHaveTagData(dataView, tagHeaderOffset)) {
|
|
@@ -156,15 +175,23 @@ export function parseTags(dataView) {
|
|
|
156
175
|
const tagType = getStringFromDataView(dataView, tagOffset, 4);
|
|
157
176
|
|
|
158
177
|
if (tagType === TAG_TYPE_DESC) {
|
|
178
|
+
if (tagOffset + DESC_VALUE_SIZE_OFFSET_END > dataView.byteLength) {
|
|
179
|
+
// Tag data is invalid, lets return what we managed to parse
|
|
180
|
+
return tags;
|
|
181
|
+
}
|
|
159
182
|
const tagValueSize = dataView.getUint32(tagOffset + 8);
|
|
160
183
|
if (tagValueSize > tagSize) {
|
|
161
184
|
// Tag data is invalid, lets return what we managed to parse
|
|
162
185
|
return tags;
|
|
163
186
|
}
|
|
164
187
|
|
|
165
|
-
const val =
|
|
188
|
+
const val = readBoundedString(dataView, tagOffset + 12, tagValueSize - 1, decodeBudget);
|
|
166
189
|
addTag(tags, tagSignature, val);
|
|
167
190
|
} else if (tagType === TAG_TYPE_MULTI_LOCALIZED_UNICODE_TYPE) {
|
|
191
|
+
if (tagOffset + MULTI_LOCALIZED_UNICODE_RECORDS_OFFSET > dataView.byteLength) {
|
|
192
|
+
// Tag data is invalid, lets return what we managed to parse
|
|
193
|
+
return tags;
|
|
194
|
+
}
|
|
168
195
|
const numRecords = dataView.getUint32(tagOffset + 8);
|
|
169
196
|
const recordSize = dataView.getUint32(tagOffset + 12);
|
|
170
197
|
if (recordSize < MIN_MULTI_LOCALIZED_UNICODE_RECORD_SIZE) {
|
|
@@ -179,11 +206,15 @@ export function parseTags(dataView) {
|
|
|
179
206
|
if (recordsSize > availableRecordsSize) {
|
|
180
207
|
return tags;
|
|
181
208
|
}
|
|
209
|
+
if (recordsSize > decodeBudget.remaining) {
|
|
210
|
+
return tags;
|
|
211
|
+
}
|
|
212
|
+
decodeBudget.remaining -= recordsSize;
|
|
182
213
|
// Records may legitimately share or overlap their text within a
|
|
183
214
|
// tag, so clamp each read to the tag bounds and draw from a
|
|
184
215
|
// profile-wide text budget rather than assuming non-overlapping
|
|
185
|
-
// storage. This caps the total decoded text
|
|
186
|
-
//
|
|
216
|
+
// storage. This caps the total decoded text without truncating
|
|
217
|
+
// real profiles.
|
|
187
218
|
const tagTextEnd = Math.min(tagSize, dataView.byteLength - tagOffset);
|
|
188
219
|
let offset = tagOffset + MULTI_LOCALIZED_UNICODE_RECORDS_OFFSET;
|
|
189
220
|
const val = [];
|
|
@@ -194,8 +225,8 @@ export function parseTags(dataView) {
|
|
|
194
225
|
const textOffset = dataView.getUint32(offset + 8);
|
|
195
226
|
|
|
196
227
|
const availableInTag = Math.max(0, tagTextEnd - textOffset);
|
|
197
|
-
const boundedTextLength = Math.min(textLength, availableInTag,
|
|
198
|
-
|
|
228
|
+
const boundedTextLength = Math.min(textLength, availableInTag, decodeBudget.remaining);
|
|
229
|
+
decodeBudget.remaining -= boundedTextLength;
|
|
199
230
|
const text = getUnicodeStringFromDataView(dataView, tagOffset + textOffset, boundedTextLength);
|
|
200
231
|
val.push({languageCode, countryCode, text});
|
|
201
232
|
offset += recordSize;
|
|
@@ -210,8 +241,9 @@ export function parseTags(dataView) {
|
|
|
210
241
|
addTag(tags, tagSignature, valObj);
|
|
211
242
|
}
|
|
212
243
|
} else if (tagType === TAG_TYPE_TEXT) {
|
|
213
|
-
const val =
|
|
214
|
-
|
|
244
|
+
const val = readBoundedString(dataView, tagOffset + 8, tagSize - 8, decodeBudget);
|
|
245
|
+
const nulIndex = val.indexOf('\0');
|
|
246
|
+
addTag(tags, tagSignature, nulIndex === -1 ? val : val.slice(0, nulIndex));
|
|
215
247
|
} else if (tagType === TAG_TYPE_SIGNATURE) {
|
|
216
248
|
const val = sliceToString(buffer.slice(tagOffset + 8, tagOffset + 12));
|
|
217
249
|
addTag(tags, tagSignature, val);
|
|
@@ -222,6 +254,12 @@ export function parseTags(dataView) {
|
|
|
222
254
|
return tags;
|
|
223
255
|
}
|
|
224
256
|
|
|
257
|
+
function readBoundedString(dataView, start, requestedLength, budget) {
|
|
258
|
+
const length = Math.max(0, Math.min(requestedLength, dataView.byteLength - start, budget.remaining));
|
|
259
|
+
budget.remaining -= length;
|
|
260
|
+
return sliceToString(dataView.buffer.slice(start, start + length));
|
|
261
|
+
}
|
|
262
|
+
|
|
225
263
|
function addTag(tags, tagSignature, value) {
|
|
226
264
|
if (iccTags[tagSignature]) {
|
|
227
265
|
tags[iccTags[tagSignature].name] = {value, description: value};
|
|
@@ -1,3 +1,7 @@
|
|
|
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
|
+
|
|
1
5
|
import {get64BitValue} from './image-header-iso-bmff-utils.js';
|
|
2
6
|
|
|
3
7
|
// Absolute backstop on the number of extent objects a single iloc box may
|
|
@@ -1,3 +1,7 @@
|
|
|
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
|
+
|
|
1
5
|
export function get64BitValue(dataView, offset) {
|
|
2
6
|
// It's a bit tricky to handle 64 bit numbers in JavaScript. Let's
|
|
3
7
|
// wait until there are real-world examples where it is necessary.
|
|
@@ -1,3 +1,7 @@
|
|
|
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
|
+
|
|
1
5
|
import Constants from './constants.js';
|
|
2
6
|
import {getNullTerminatedStringFromDataView, getStringFromDataView, pushMetadataBlock} from './utils.js';
|
|
3
7
|
// import {get64BitValue} from './image-header-iso-bmff-utils.js';
|
package/src/load-auto.js
CHANGED
|
@@ -284,7 +284,8 @@ function sliceInputBuffer(data, end) {
|
|
|
284
284
|
return data.slice(0, end);
|
|
285
285
|
}
|
|
286
286
|
if (ArrayBuffer.isView(data)) {
|
|
287
|
-
|
|
287
|
+
const viewEnd = Math.max(0, Math.min(end, data.byteLength));
|
|
288
|
+
return data.buffer.slice(data.byteOffset, data.byteOffset + viewEnd);
|
|
288
289
|
}
|
|
289
290
|
return data;
|
|
290
291
|
}
|
package/src/loadview-pipeline.js
CHANGED
|
@@ -222,7 +222,7 @@ export function applyMergeStep({
|
|
|
222
222
|
return tags;
|
|
223
223
|
}
|
|
224
224
|
|
|
225
|
-
if (step.type === 'gps') {
|
|
225
|
+
if (Constants.USE_EXIF && step.type === 'gps') {
|
|
226
226
|
if (
|
|
227
227
|
expanded
|
|
228
228
|
&& tagFilter.shouldReturnGroup('gps')
|
|
@@ -282,14 +282,11 @@ export function applyMergeStep({
|
|
|
282
282
|
return tags;
|
|
283
283
|
}
|
|
284
284
|
|
|
285
|
-
const parsedThumbnailIfdTags =
|
|
285
|
+
const parsedThumbnailIfdTags = deps.filterTagsForParse(
|
|
286
286
|
'thumbnail',
|
|
287
287
|
thumbnailIfdTags,
|
|
288
288
|
tagFilter
|
|
289
|
-
)
|
|
290
|
-
if (parsedThumbnailIfdTags) {
|
|
291
|
-
parsedGroups.thumbnail = parsedThumbnailIfdTags;
|
|
292
|
-
}
|
|
289
|
+
);
|
|
293
290
|
|
|
294
291
|
const thumbnail = Constants.USE_EXIF
|
|
295
292
|
&& Constants.USE_THUMBNAIL
|
package/src/png-text-tags.js
CHANGED
|
@@ -119,7 +119,10 @@ function getNameAndValue(dataView, offset, length, type, async, decompressConfig
|
|
|
119
119
|
parsingState = moveToNextState(type, parsingState);
|
|
120
120
|
continue;
|
|
121
121
|
} else if (parsingState === STATE_TEXT) {
|
|
122
|
-
|
|
122
|
+
const slice = dataView.buffer.slice(byteOffset + offset + i, byteOffset + offset + length);
|
|
123
|
+
// On the Node Buffer wrapper, slice() returns a Buffer, which DataView
|
|
124
|
+
// rejects. Uint8Array copies a Buffer and leaves an ArrayBuffer as is.
|
|
125
|
+
valueChars = new DataView(new Uint8Array(slice).buffer);
|
|
123
126
|
break;
|
|
124
127
|
}
|
|
125
128
|
const byte = dataView.getUint8(offset + i);
|
package/src/xmp-namespaces.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
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
|
+
|
|
1
5
|
export function isMissingNamespaceError(error) {
|
|
2
6
|
const missingNamespaceStrings = [
|
|
3
7
|
// @xmldom/xmldom
|