exifreader 4.38.1 → 4.39.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 +23 -99
- package/dist/exif-reader.js +1 -1
- package/dist/exif-reader.js.map +1 -1
- package/exif-reader.d.ts +1 -0
- package/package.json +8 -8
- package/src/icc-tags.js +12 -1
- package/src/tag-names-utils.js +4 -0
- package/src/utils.js +73 -14
package/exif-reader.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "exifreader",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.39.0",
|
|
4
4
|
"description": "Library that parses Exif metadata in images.",
|
|
5
5
|
"author": "Mattias Wallander <mattias@wallander.eu>",
|
|
6
6
|
"repository": {
|
|
@@ -26,14 +26,14 @@
|
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@babel/core": "^7.25.2",
|
|
29
|
-
"@babel/preset-env": "^7.
|
|
30
|
-
"@babel/register": "^7.
|
|
31
|
-
"@types/node": "^25.
|
|
29
|
+
"@babel/preset-env": "^7.29.5",
|
|
30
|
+
"@babel/register": "^7.29.3",
|
|
31
|
+
"@types/node": "^25.6.2",
|
|
32
32
|
"babel-loader": "^10.0.0",
|
|
33
33
|
"babel-plugin-rewire": "^1.2.0",
|
|
34
34
|
"chai": "^4.3.10",
|
|
35
35
|
"cross-env": "^10.0.0",
|
|
36
|
-
"cypress": "^15.
|
|
36
|
+
"cypress": "^15.14.2",
|
|
37
37
|
"eslint": "^8.52.0",
|
|
38
38
|
"eslint-plugin-cypress": "^3.0.2",
|
|
39
39
|
"husky": "^9.0.11",
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
"nyc": "^18.0.0",
|
|
44
44
|
"rimraf": "^5.0.5",
|
|
45
45
|
"string-replace-loader": "^3.1.0",
|
|
46
|
-
"terser-webpack-plugin": "^5.
|
|
47
|
-
"typescript": "^6.0.
|
|
48
|
-
"webpack": "5.
|
|
46
|
+
"terser-webpack-plugin": "^5.5.0",
|
|
47
|
+
"typescript": "^6.0.3",
|
|
48
|
+
"webpack": "5.106.2",
|
|
49
49
|
"webpack-cli": "^7.0.0",
|
|
50
50
|
"webpack-dev-server": "^5.0.4"
|
|
51
51
|
},
|
package/src/icc-tags.js
CHANGED
|
@@ -87,6 +87,8 @@ function hasTagsData(buffer, tagHeaderOffset) {
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
export function parseTags(dataView) {
|
|
90
|
+
const MIN_MULTI_LOCALIZED_UNICODE_RECORD_SIZE = 12;
|
|
91
|
+
const MULTI_LOCALIZED_UNICODE_RECORDS_OFFSET = 16;
|
|
90
92
|
const buffer = dataView.buffer;
|
|
91
93
|
|
|
92
94
|
const length = dataView.getUint32();
|
|
@@ -156,7 +158,16 @@ export function parseTags(dataView) {
|
|
|
156
158
|
} else if (tagType === TAG_TYPE_MULTI_LOCALIZED_UNICODE_TYPE) {
|
|
157
159
|
const numRecords = dataView.getUint32(tagOffset + 8);
|
|
158
160
|
const recordSize = dataView.getUint32(tagOffset + 12);
|
|
159
|
-
|
|
161
|
+
if (recordSize < MIN_MULTI_LOCALIZED_UNICODE_RECORD_SIZE) {
|
|
162
|
+
return tags;
|
|
163
|
+
}
|
|
164
|
+
const recordsSize = numRecords * recordSize;
|
|
165
|
+
const availableRecordsSize = dataView.byteLength - tagOffset
|
|
166
|
+
- MULTI_LOCALIZED_UNICODE_RECORDS_OFFSET;
|
|
167
|
+
if (recordsSize > availableRecordsSize) {
|
|
168
|
+
return tags;
|
|
169
|
+
}
|
|
170
|
+
let offset = tagOffset + MULTI_LOCALIZED_UNICODE_RECORDS_OFFSET;
|
|
160
171
|
const val = [];
|
|
161
172
|
for (let recordNum = 0; recordNum < numRecords; recordNum++) {
|
|
162
173
|
const languageCode = getStringFromDataView(dataView, offset + 0, 2);
|
package/src/tag-names-utils.js
CHANGED
|
@@ -17,6 +17,10 @@ export function getEncodedString(value) {
|
|
|
17
17
|
} else if (encoding === 'UNICODE\x00') {
|
|
18
18
|
return '[Unicode encoded text]';
|
|
19
19
|
} else if (encoding === '\x00\x00\x00\x00\x00\x00\x00\x00') {
|
|
20
|
+
const text = getStringValue(value.slice(8));
|
|
21
|
+
if (/[\x20-\x7e]/.test(text)) {
|
|
22
|
+
return text;
|
|
23
|
+
}
|
|
20
24
|
return '[Undefined encoding]';
|
|
21
25
|
}
|
|
22
26
|
}
|
package/src/utils.js
CHANGED
|
@@ -150,14 +150,20 @@ export function strRepeat(string, num) {
|
|
|
150
150
|
export const COMPRESSION_METHOD_NONE = undefined;
|
|
151
151
|
export const COMPRESSION_METHOD_DEFLATE = 0;
|
|
152
152
|
export const COMPRESSION_METHOD_BROTLI = 'brotli';
|
|
153
|
+
export const DEFAULT_MAX_DECOMPRESSED_SIZE = 128 * 1024 * 1024;
|
|
153
154
|
|
|
154
155
|
export function decompress(dataView, compressionMethod, encoding, returnType = 'string', decompressConfig) {
|
|
156
|
+
const maxDecompressedSize = getMaxDecompressedSize(decompressConfig);
|
|
157
|
+
|
|
155
158
|
if (decompressConfig && compressionMethod !== COMPRESSION_METHOD_NONE) {
|
|
156
159
|
const decompressType = compressionMethod === COMPRESSION_METHOD_DEFLATE ? 'deflate' : 'brotli';
|
|
157
160
|
const customFn = decompressConfig[decompressType];
|
|
158
161
|
if (typeof customFn === 'function') {
|
|
159
162
|
const uint8 = new Uint8Array(dataView.buffer, dataView.byteOffset, dataView.byteLength);
|
|
160
163
|
return Promise.resolve(customFn(uint8)).then((result) => {
|
|
164
|
+
if (getResultByteLength(result) > maxDecompressedSize) {
|
|
165
|
+
return rejectExceedsMax(maxDecompressedSize);
|
|
166
|
+
}
|
|
161
167
|
if (returnType === 'dataview') {
|
|
162
168
|
if (result instanceof DataView) {
|
|
163
169
|
return result;
|
|
@@ -174,26 +180,16 @@ export function decompress(dataView, compressionMethod, encoding, returnType = '
|
|
|
174
180
|
|
|
175
181
|
if (compressionMethod === COMPRESSION_METHOD_DEFLATE) {
|
|
176
182
|
if (typeof DecompressionStream === 'function') {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
if (returnType === 'dataview') {
|
|
180
|
-
return new Response(decompressedStream).arrayBuffer().then((arrayBuffer) => new DataView(arrayBuffer));
|
|
181
|
-
}
|
|
182
|
-
return new Response(decompressedStream).arrayBuffer()
|
|
183
|
-
.then((buffer) => new TextDecoder(encoding).decode(buffer));
|
|
183
|
+
return readBoundedDecompressedStream(dataView, 'deflate', maxDecompressedSize)
|
|
184
|
+
.then((arrayBuffer) => decodeBuffer(arrayBuffer, returnType, encoding));
|
|
184
185
|
}
|
|
185
186
|
}
|
|
186
187
|
|
|
187
188
|
if (compressionMethod === COMPRESSION_METHOD_BROTLI) {
|
|
188
189
|
if (typeof DecompressionStream === 'function') {
|
|
189
190
|
try {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
if (returnType === 'dataview') {
|
|
193
|
-
return new Response(decompressedStream).arrayBuffer().then((arrayBuffer) => new DataView(arrayBuffer));
|
|
194
|
-
}
|
|
195
|
-
return new Response(decompressedStream).arrayBuffer()
|
|
196
|
-
.then((buffer) => new TextDecoder(encoding).decode(buffer));
|
|
191
|
+
return readBoundedDecompressedStream(dataView, 'brotli', maxDecompressedSize)
|
|
192
|
+
.then((arrayBuffer) => decodeBuffer(arrayBuffer, returnType, encoding));
|
|
197
193
|
} catch (_error) {
|
|
198
194
|
// brotli not supported by this DecompressionStream implementation
|
|
199
195
|
}
|
|
@@ -216,3 +212,66 @@ export function decompress(dataView, compressionMethod, encoding, returnType = '
|
|
|
216
212
|
}
|
|
217
213
|
return dataView;
|
|
218
214
|
}
|
|
215
|
+
|
|
216
|
+
function getMaxDecompressedSize(decompressConfig) {
|
|
217
|
+
if (decompressConfig && typeof decompressConfig.maxDecompressedSize === 'number') {
|
|
218
|
+
return decompressConfig.maxDecompressedSize;
|
|
219
|
+
}
|
|
220
|
+
return DEFAULT_MAX_DECOMPRESSED_SIZE;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function readBoundedDecompressedStream(dataView, format, maxDecompressedSize) {
|
|
224
|
+
const decompressionStream = new DecompressionStream(format);
|
|
225
|
+
const decompressedStream = new Blob([dataView]).stream().pipeThrough(decompressionStream);
|
|
226
|
+
const reader = decompressedStream.getReader();
|
|
227
|
+
const chunks = [];
|
|
228
|
+
let total = 0;
|
|
229
|
+
|
|
230
|
+
return pump();
|
|
231
|
+
|
|
232
|
+
function pump() {
|
|
233
|
+
return reader.read().then(({done, value}) => {
|
|
234
|
+
if (done) {
|
|
235
|
+
return concatChunks(chunks, total);
|
|
236
|
+
}
|
|
237
|
+
total += value.byteLength;
|
|
238
|
+
if (total > maxDecompressedSize) {
|
|
239
|
+
return reader.cancel().then(() => rejectExceedsMax(maxDecompressedSize));
|
|
240
|
+
}
|
|
241
|
+
chunks.push(value);
|
|
242
|
+
return pump();
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function concatChunks(chunks, total) {
|
|
248
|
+
const out = new Uint8Array(total);
|
|
249
|
+
let offset = 0;
|
|
250
|
+
for (let i = 0; i < chunks.length; i++) {
|
|
251
|
+
out.set(chunks[i], offset);
|
|
252
|
+
offset += chunks[i].byteLength;
|
|
253
|
+
}
|
|
254
|
+
return out.buffer;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function decodeBuffer(arrayBuffer, returnType, encoding) {
|
|
258
|
+
if (returnType === 'dataview') {
|
|
259
|
+
return new DataView(arrayBuffer);
|
|
260
|
+
}
|
|
261
|
+
return new TextDecoder(encoding).decode(arrayBuffer);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function getResultByteLength(result) {
|
|
265
|
+
if (result && typeof result.byteLength === 'number') {
|
|
266
|
+
return result.byteLength;
|
|
267
|
+
}
|
|
268
|
+
return 0;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function rejectExceedsMax(maxDecompressedSize) {
|
|
272
|
+
if (typeof console !== 'undefined' && typeof console.warn === 'function') { // eslint-disable-line no-console
|
|
273
|
+
// eslint-disable-next-line no-console
|
|
274
|
+
console.warn(`ExifReader: skipped a compressed metadata block that would exceed the maximum decompressed size of ${maxDecompressedSize} bytes.`);
|
|
275
|
+
}
|
|
276
|
+
return Promise.reject(`Decompressed metadata exceeded the maximum allowed size of ${maxDecompressedSize} bytes.`);
|
|
277
|
+
}
|