exifreader 4.40.3 → 4.40.5
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 +1 -1
- package/src/icc-tags.js +27 -11
package/package.json
CHANGED
package/src/icc-tags.js
CHANGED
|
@@ -16,6 +16,8 @@ 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 MIN_MULTI_LOCALIZED_UNICODE_RECORD_SIZE = 12;
|
|
20
|
+
const MULTI_LOCALIZED_UNICODE_RECORDS_OFFSET = 16;
|
|
19
21
|
|
|
20
22
|
// ICC profile data can be longer than application segment max length of ~64k.
|
|
21
23
|
// so it can be split into multiple APP2 segments. Each segment includes
|
|
@@ -78,17 +80,16 @@ function getBuffer(dataView) {
|
|
|
78
80
|
return dataView.buffer;
|
|
79
81
|
}
|
|
80
82
|
|
|
81
|
-
function iccDoesNotHaveTagCount(
|
|
82
|
-
return
|
|
83
|
+
function iccDoesNotHaveTagCount(dataView) {
|
|
84
|
+
return dataView.byteLength < (ICC_TAG_COUNT_OFFSET + 4);
|
|
83
85
|
}
|
|
84
86
|
|
|
85
|
-
function
|
|
86
|
-
return
|
|
87
|
+
function doesNotHaveTagData(dataView, tagHeaderOffset) {
|
|
88
|
+
return dataView.byteLength < tagHeaderOffset + TAG_TABLE_SINGLE_TAG_DATA;
|
|
87
89
|
}
|
|
88
90
|
|
|
89
91
|
export function parseTags(dataView) {
|
|
90
|
-
const
|
|
91
|
-
const MULTI_LOCALIZED_UNICODE_RECORDS_OFFSET = 16;
|
|
92
|
+
const MAX_MLUC_RECORDS = 1000;
|
|
92
93
|
const buffer = dataView.buffer;
|
|
93
94
|
|
|
94
95
|
const length = dataView.getUint32();
|
|
@@ -124,23 +125,26 @@ export function parseTags(dataView) {
|
|
|
124
125
|
}
|
|
125
126
|
|
|
126
127
|
/* ICC data is incomplete but we have header parsed so lets return it */
|
|
127
|
-
if (iccDoesNotHaveTagCount(
|
|
128
|
+
if (iccDoesNotHaveTagCount(dataView)) {
|
|
128
129
|
return tags;
|
|
129
130
|
}
|
|
130
131
|
|
|
131
132
|
const tagCount = dataView.getUint32(128);
|
|
132
133
|
let tagHeaderOffset = 132;
|
|
134
|
+
// Budget for the total mluc text decoded across the whole profile. Caps
|
|
135
|
+
// the decoded text at O(profile size); real profiles use a small fraction.
|
|
136
|
+
let remainingMlucTextBytes = dataView.byteLength;
|
|
133
137
|
|
|
134
138
|
for (let i = 0; i < tagCount; i++) {
|
|
135
|
-
if (
|
|
136
|
-
//
|
|
139
|
+
if (doesNotHaveTagData(dataView, tagHeaderOffset)) {
|
|
140
|
+
// Not enough room left for the next tag table entry, return what we parsed until now
|
|
137
141
|
return tags;
|
|
138
142
|
}
|
|
139
143
|
const tagSignature = getStringFromDataView(dataView, tagHeaderOffset, 4);
|
|
140
144
|
const tagOffset = dataView.getUint32(tagHeaderOffset + 4);
|
|
141
145
|
const tagSize = dataView.getUint32(tagHeaderOffset + 8);
|
|
142
146
|
|
|
143
|
-
if (tagOffset >
|
|
147
|
+
if (tagOffset > dataView.byteLength) {
|
|
144
148
|
// Tag data is invalid, lets return what we managed to parse
|
|
145
149
|
return tags;
|
|
146
150
|
}
|
|
@@ -161,12 +165,21 @@ export function parseTags(dataView) {
|
|
|
161
165
|
if (recordSize < MIN_MULTI_LOCALIZED_UNICODE_RECORD_SIZE) {
|
|
162
166
|
return tags;
|
|
163
167
|
}
|
|
168
|
+
if (numRecords > MAX_MLUC_RECORDS) {
|
|
169
|
+
return tags;
|
|
170
|
+
}
|
|
164
171
|
const recordsSize = numRecords * recordSize;
|
|
165
172
|
const availableRecordsSize = dataView.byteLength - tagOffset
|
|
166
173
|
- MULTI_LOCALIZED_UNICODE_RECORDS_OFFSET;
|
|
167
174
|
if (recordsSize > availableRecordsSize) {
|
|
168
175
|
return tags;
|
|
169
176
|
}
|
|
177
|
+
// Records may legitimately share or overlap their text within a
|
|
178
|
+
// tag, so clamp each read to the tag bounds and draw from a
|
|
179
|
+
// profile-wide text budget rather than assuming non-overlapping
|
|
180
|
+
// storage. This caps the total decoded text at O(profile size)
|
|
181
|
+
// without truncating real profiles.
|
|
182
|
+
const tagTextEnd = Math.min(tagSize, dataView.byteLength - tagOffset);
|
|
170
183
|
let offset = tagOffset + MULTI_LOCALIZED_UNICODE_RECORDS_OFFSET;
|
|
171
184
|
const val = [];
|
|
172
185
|
for (let recordNum = 0; recordNum < numRecords; recordNum++) {
|
|
@@ -175,7 +188,10 @@ export function parseTags(dataView) {
|
|
|
175
188
|
const textLength = dataView.getUint32(offset + 4);
|
|
176
189
|
const textOffset = dataView.getUint32(offset + 8);
|
|
177
190
|
|
|
178
|
-
const
|
|
191
|
+
const availableInTag = Math.max(0, tagTextEnd - textOffset);
|
|
192
|
+
const boundedTextLength = Math.min(textLength, availableInTag, remainingMlucTextBytes);
|
|
193
|
+
remainingMlucTextBytes -= boundedTextLength;
|
|
194
|
+
const text = getUnicodeStringFromDataView(dataView, tagOffset + textOffset, boundedTextLength);
|
|
179
195
|
val.push({languageCode, countryCode, text});
|
|
180
196
|
offset += recordSize;
|
|
181
197
|
}
|