exifreader 4.26.0 → 4.26.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "exifreader",
3
- "version": "4.26.0",
3
+ "version": "4.26.2",
4
4
  "description": "Library that parses Exif metadata in images.",
5
5
  "author": "Mattias Wallander <mattias@wallander.eu>",
6
6
  "repository": {
@@ -29,11 +29,11 @@
29
29
  "@babel/preset-env": "^7.25.4",
30
30
  "@babel/register": "^7.24.6",
31
31
  "@types/node": "^20.16.10",
32
- "babel-loader": "^9.2.1",
32
+ "babel-loader": "^10.0.0",
33
33
  "babel-plugin-rewire": "^1.2.0",
34
34
  "chai": "^4.3.10",
35
35
  "cross-env": "^7.0.3",
36
- "cypress": "^13.3.2",
36
+ "cypress": "^14.0.0",
37
37
  "eslint": "^8.52.0",
38
38
  "eslint-plugin-cypress": "^3.0.2",
39
39
  "husky": "^9.0.11",
@@ -44,7 +44,7 @@
44
44
  "string-replace-loader": "^3.1.0",
45
45
  "terser-webpack-plugin": "^5.3.10",
46
46
  "typescript": "^5.6.2",
47
- "webpack": "5.97.1",
47
+ "webpack": "5.98.0",
48
48
  "webpack-cli": "^5.1.4",
49
49
  "webpack-dev-server": "^5.0.4"
50
50
  },
@@ -161,7 +161,7 @@ function requireNodeFs() {
161
161
  }
162
162
 
163
163
  function isBrowserFileObject(data) {
164
- return (typeof window !== 'undefined') && (typeof File !== 'undefined') && (data instanceof File);
164
+ return (typeof File !== 'undefined') && (data instanceof File);
165
165
  }
166
166
 
167
167
  function loadFileObject(file) {
package/src/iptc-tags.js CHANGED
@@ -7,8 +7,12 @@ import TagDecoder from './tag-decoder.js';
7
7
 
8
8
  const BYTES_8BIM = 0x3842494d;
9
9
  const BYTES_8BIM_SIZE = 4;
10
- const RESOURCE_BLOCK_HEADER_SIZE = BYTES_8BIM_SIZE + 8;
11
- const NAA_RESOURCE_BLOCK_TYPE = 0x0404;
10
+ const RESOURCE_ID_SIZE = 2;
11
+ const RESOURCE_NAME_SIZE_SIZE = 1;
12
+ const RESOURCE_NAME_MIN_SIZE = 2;
13
+ const RESOURCE_SIZE_SIZE = 4;
14
+ const RESOURCE_BLOCK_MIN_HEADER_SIZE = BYTES_8BIM_SIZE + RESOURCE_ID_SIZE + RESOURCE_NAME_MIN_SIZE + RESOURCE_SIZE_SIZE;
15
+ const NAA_RESOURCE_BLOCK_TYPE = 0x0404; // Sometimes called resource ID.
12
16
  const TAG_HEADER_SIZE = 5;
13
17
 
14
18
  export default {
@@ -28,26 +32,29 @@ function read(dataView, dataOffset, includeUnknown) {
28
32
  }
29
33
 
30
34
  function getNaaResourceBlock(dataView, dataOffset) {
31
- while (dataOffset + RESOURCE_BLOCK_HEADER_SIZE <= dataView.byteLength) {
35
+ while (dataOffset + RESOURCE_BLOCK_MIN_HEADER_SIZE <= dataView.byteLength) {
32
36
  const resourceBlock = getResourceBlock(dataView, dataOffset);
33
37
  if (isNaaResourceBlock(resourceBlock)) {
34
- return {naaBlock: resourceBlock, dataOffset: dataOffset + RESOURCE_BLOCK_HEADER_SIZE};
38
+ return {naaBlock: resourceBlock, dataOffset: dataOffset + resourceBlock.headerSize};
35
39
  }
36
- dataOffset += RESOURCE_BLOCK_HEADER_SIZE + resourceBlock.size + getBlockPadding(resourceBlock);
40
+ dataOffset += resourceBlock.headerSize + resourceBlock.size + getBlockPadding(resourceBlock);
37
41
  }
38
42
  throw new Error('No IPTC NAA resource block.');
39
43
  }
40
44
 
41
45
  function getResourceBlock(dataView, dataOffset) {
42
- const RESOURCE_BLOCK_SIZE_OFFSET = 10;
43
-
44
46
  if (dataView.getUint32(dataOffset, false) !== BYTES_8BIM) {
45
47
  throw new Error('Not an IPTC resource block.');
46
48
  }
47
49
 
50
+ // We currently do not use the resource name for anything, we just need to know the size.
51
+ const resourceNameSize = dataView.getUint8(dataOffset + BYTES_8BIM_SIZE + RESOURCE_ID_SIZE);
52
+ const resourceNameTotalSize = (resourceNameSize % 2 === 0 ? resourceNameSize + 1 : resourceNameSize) + RESOURCE_NAME_SIZE_SIZE;
53
+
48
54
  return {
55
+ headerSize: BYTES_8BIM_SIZE + RESOURCE_ID_SIZE + resourceNameTotalSize + RESOURCE_SIZE_SIZE,
49
56
  type: dataView.getUint16(dataOffset + BYTES_8BIM_SIZE),
50
- size: dataView.getUint16(dataOffset + RESOURCE_BLOCK_SIZE_OFFSET)
57
+ size: dataView.getUint32(dataOffset + BYTES_8BIM_SIZE + RESOURCE_ID_SIZE + resourceNameTotalSize),
51
58
  };
52
59
  }
53
60