exifreader 4.45.0 → 4.45.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/dist/exif-reader.js +1 -1
- package/dist/exif-reader.js.map +1 -1
- package/package.json +5 -5
- package/src/icc-tags.js +23 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "exifreader",
|
|
3
|
-
"version": "4.45.
|
|
3
|
+
"version": "4.45.1",
|
|
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/icc-tags.js
CHANGED
|
@@ -18,6 +18,9 @@ const TAG_TYPE_SIGNATURE = 'sig ';
|
|
|
18
18
|
const TAG_TABLE_SINGLE_TAG_DATA = 12;
|
|
19
19
|
const MIN_MULTI_LOCALIZED_UNICODE_RECORD_SIZE = 12;
|
|
20
20
|
const MULTI_LOCALIZED_UNICODE_RECORDS_OFFSET = 16;
|
|
21
|
+
const MAX_MLUC_RECORDS = 1000;
|
|
22
|
+
const MAX_TAG_COUNT = 1000;
|
|
23
|
+
const MAX_DECODE_BYTES = 1024 * 1024;
|
|
21
24
|
|
|
22
25
|
// ICC profile data can be longer than application segment max length of ~64k.
|
|
23
26
|
// so it can be split into multiple APP2 segments. Each segment includes
|
|
@@ -94,7 +97,6 @@ function doesNotHaveTagData(dataView, tagHeaderOffset) {
|
|
|
94
97
|
}
|
|
95
98
|
|
|
96
99
|
export function parseTags(dataView) {
|
|
97
|
-
const MAX_MLUC_RECORDS = 1000;
|
|
98
100
|
const buffer = dataView.buffer;
|
|
99
101
|
|
|
100
102
|
const length = dataView.getUint32();
|
|
@@ -134,11 +136,11 @@ export function parseTags(dataView) {
|
|
|
134
136
|
return tags;
|
|
135
137
|
}
|
|
136
138
|
|
|
137
|
-
const tagCount = dataView.getUint32(
|
|
139
|
+
const tagCount = Math.min(dataView.getUint32(ICC_TAG_COUNT_OFFSET), MAX_TAG_COUNT);
|
|
138
140
|
let tagHeaderOffset = 132;
|
|
139
|
-
// Budget for
|
|
140
|
-
// the
|
|
141
|
-
|
|
141
|
+
// Budget for everything decoded from tag data (desc, text and mluc) across
|
|
142
|
+
// the whole profile, bounded by its size and a constant far above real text.
|
|
143
|
+
const decodeBudget = {remaining: Math.min(dataView.byteLength, MAX_DECODE_BYTES)};
|
|
142
144
|
|
|
143
145
|
for (let i = 0; i < tagCount; i++) {
|
|
144
146
|
if (doesNotHaveTagData(dataView, tagHeaderOffset)) {
|
|
@@ -162,7 +164,7 @@ export function parseTags(dataView) {
|
|
|
162
164
|
return tags;
|
|
163
165
|
}
|
|
164
166
|
|
|
165
|
-
const val =
|
|
167
|
+
const val = readBoundedString(dataView, tagOffset + 12, tagValueSize - 1, decodeBudget);
|
|
166
168
|
addTag(tags, tagSignature, val);
|
|
167
169
|
} else if (tagType === TAG_TYPE_MULTI_LOCALIZED_UNICODE_TYPE) {
|
|
168
170
|
const numRecords = dataView.getUint32(tagOffset + 8);
|
|
@@ -179,11 +181,15 @@ export function parseTags(dataView) {
|
|
|
179
181
|
if (recordsSize > availableRecordsSize) {
|
|
180
182
|
return tags;
|
|
181
183
|
}
|
|
184
|
+
if (recordsSize > decodeBudget.remaining) {
|
|
185
|
+
return tags;
|
|
186
|
+
}
|
|
187
|
+
decodeBudget.remaining -= recordsSize;
|
|
182
188
|
// Records may legitimately share or overlap their text within a
|
|
183
189
|
// tag, so clamp each read to the tag bounds and draw from a
|
|
184
190
|
// profile-wide text budget rather than assuming non-overlapping
|
|
185
|
-
// storage. This caps the total decoded text
|
|
186
|
-
//
|
|
191
|
+
// storage. This caps the total decoded text without truncating
|
|
192
|
+
// real profiles.
|
|
187
193
|
const tagTextEnd = Math.min(tagSize, dataView.byteLength - tagOffset);
|
|
188
194
|
let offset = tagOffset + MULTI_LOCALIZED_UNICODE_RECORDS_OFFSET;
|
|
189
195
|
const val = [];
|
|
@@ -194,8 +200,8 @@ export function parseTags(dataView) {
|
|
|
194
200
|
const textOffset = dataView.getUint32(offset + 8);
|
|
195
201
|
|
|
196
202
|
const availableInTag = Math.max(0, tagTextEnd - textOffset);
|
|
197
|
-
const boundedTextLength = Math.min(textLength, availableInTag,
|
|
198
|
-
|
|
203
|
+
const boundedTextLength = Math.min(textLength, availableInTag, decodeBudget.remaining);
|
|
204
|
+
decodeBudget.remaining -= boundedTextLength;
|
|
199
205
|
const text = getUnicodeStringFromDataView(dataView, tagOffset + textOffset, boundedTextLength);
|
|
200
206
|
val.push({languageCode, countryCode, text});
|
|
201
207
|
offset += recordSize;
|
|
@@ -210,7 +216,7 @@ export function parseTags(dataView) {
|
|
|
210
216
|
addTag(tags, tagSignature, valObj);
|
|
211
217
|
}
|
|
212
218
|
} else if (tagType === TAG_TYPE_TEXT) {
|
|
213
|
-
const val =
|
|
219
|
+
const val = readBoundedString(dataView, tagOffset + 8, tagSize - 15, decodeBudget);
|
|
214
220
|
addTag(tags, tagSignature, val);
|
|
215
221
|
} else if (tagType === TAG_TYPE_SIGNATURE) {
|
|
216
222
|
const val = sliceToString(buffer.slice(tagOffset + 8, tagOffset + 12));
|
|
@@ -222,6 +228,12 @@ export function parseTags(dataView) {
|
|
|
222
228
|
return tags;
|
|
223
229
|
}
|
|
224
230
|
|
|
231
|
+
function readBoundedString(dataView, start, requestedLength, budget) {
|
|
232
|
+
const length = Math.max(0, Math.min(requestedLength, dataView.byteLength - start, budget.remaining));
|
|
233
|
+
budget.remaining -= length;
|
|
234
|
+
return sliceToString(dataView.buffer.slice(start, start + length));
|
|
235
|
+
}
|
|
236
|
+
|
|
225
237
|
function addTag(tags, tagSignature, value) {
|
|
226
238
|
if (iccTags[tagSignature]) {
|
|
227
239
|
tags[iccTags[tagSignature].name] = {value, description: value};
|