msgpackr-extract 2.2.0 → 3.0.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.
@@ -8,4 +8,6 @@ process.chdir(dirname(__dirname));
8
8
  exec('prebuildify-ci download', (error, stdout, stderr) => {
9
9
  console.error(stderr);
10
10
  console.log(stdout);
11
+ if (error?.code)
12
+ process.exit(error.code);
11
13
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "msgpackr-extract",
3
3
  "author": "Kris Zyp",
4
- "version": "2.2.0",
4
+ "version": "3.0.1",
5
5
  "description": "Node addon for string extraction for msgpackr",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -22,7 +22,7 @@
22
22
  "main": "./index.js",
23
23
  "gypfile": true,
24
24
  "dependencies": {
25
- "node-gyp-build-optional-packages": "5.0.3"
25
+ "node-gyp-build-optional-packages": "5.0.7"
26
26
  },
27
27
  "files": [
28
28
  "index.js",
@@ -34,12 +34,12 @@
34
34
  "download-msgpackr-prebuilds": "./bin/download-prebuilds.js"
35
35
  },
36
36
  "optionalDependencies": {
37
- "@msgpackr-extract/msgpackr-extract-darwin-arm64": "2.2.0",
38
- "@msgpackr-extract/msgpackr-extract-darwin-x64": "2.2.0",
39
- "@msgpackr-extract/msgpackr-extract-linux-arm": "2.2.0",
40
- "@msgpackr-extract/msgpackr-extract-linux-arm64": "2.2.0",
41
- "@msgpackr-extract/msgpackr-extract-linux-x64": "2.2.0",
42
- "@msgpackr-extract/msgpackr-extract-win32-x64": "2.2.0"
37
+ "@msgpackr-extract/msgpackr-extract-darwin-arm64": "3.0.1",
38
+ "@msgpackr-extract/msgpackr-extract-darwin-x64": "3.0.1",
39
+ "@msgpackr-extract/msgpackr-extract-linux-arm": "3.0.1",
40
+ "@msgpackr-extract/msgpackr-extract-linux-arm64": "3.0.1",
41
+ "@msgpackr-extract/msgpackr-extract-linux-x64": "3.0.1",
42
+ "@msgpackr-extract/msgpackr-extract-win32-x64": "3.0.1"
43
43
  },
44
44
  "devDependencies": {
45
45
  "prebuildify-platform-packages": "5.0.2",
package/src/extract.cpp CHANGED
@@ -23,7 +23,8 @@ find the string tokens and determine their position and length. All strings are
23
23
  #endif
24
24
 
25
25
  const int MAX_TARGET_SIZE = 255;
26
- typedef int (*token_handler)(uint8_t* source, int position, int size);
26
+ const uint UNEXPECTED_END = 0xffffffff;
27
+ typedef uint32_t (*token_handler)(uint8_t* source, uint32_t position, uint32_t size);
27
28
  token_handler tokenTable[256] = {};
28
29
  napi_value unexpectedEnd(napi_env env) {
29
30
  napi_value returnValue;
@@ -37,14 +38,14 @@ public:
37
38
  // napi_ref targetArray; // could consider reenabling this optimization for napi
38
39
  bool hasTargetArray = false;
39
40
  uint8_t* source;
40
- int position = 0;
41
- int writePosition = 0;
42
- int stringStart = 0;
43
- int lastStringEnd = 0;
41
+ uint32_t position = 0;
42
+ uint32_t writePosition = 0;
43
+ uint32_t stringStart = 0;
44
+ uint32_t lastStringEnd = 0;
44
45
 
45
- void readString(napi_env env, int length, bool allowStringBlocks, napi_value* target) {
46
- int start = position;
47
- int end = position + length;
46
+ void readString(napi_env env, uint32_t length, bool allowStringBlocks, napi_value* target) {
47
+ uint32_t start = position;
48
+ uint32_t end = position + length;
48
49
  if (allowStringBlocks) { // for larger strings, we don't bother to check every character for being latin, and just go right to creating a new string
49
50
  while(position < end) {
50
51
  if (source[position] < 0x80) // ensure we character is latin and can be decoded as one byte
@@ -83,7 +84,7 @@ public:
83
84
  lastStringEnd = end;
84
85
  }
85
86
 
86
- napi_value extractStrings(napi_env env, int startingPosition, int size, uint8_t* inputSource) {
87
+ napi_value extractStrings(napi_env env, uint32_t startingPosition, uint32_t size, uint8_t* inputSource) {
87
88
  napi_value target[MAX_TARGET_SIZE + 1]; // leave one for the queued string
88
89
  writePosition = 0;
89
90
  lastStringEnd = 0;
@@ -107,7 +108,7 @@ public:
107
108
  if (position >= size) {
108
109
  return unexpectedEnd(env);
109
110
  }
110
- int length = source[position++];
111
+ uint32_t length = source[position++];
111
112
  if (length + position > size) {
112
113
  return unexpectedEnd(env);
113
114
  }
@@ -116,7 +117,7 @@ public:
116
117
  if (2 + position > size) {
117
118
  return unexpectedEnd(env);
118
119
  }
119
- int length = source[position++] << 8;
120
+ uint32_t length = source[position++] << 8;
120
121
  length += source[position++];
121
122
  if (length + position > size) {
122
123
  return unexpectedEnd(env);
@@ -126,7 +127,7 @@ public:
126
127
  if (4 + position > size) {
127
128
  return unexpectedEnd(env);
128
129
  }
129
- int length = source[position++] << 24;
130
+ uint32_t length = source[position++] << 24;
130
131
  length += source[position++] << 16;
131
132
  length += source[position++] << 8;
132
133
  length += source[position++];
@@ -143,7 +144,7 @@ public:
143
144
  position += (size_t ) handle;
144
145
  } else {
145
146
  position = tokenTable[token](source, position, size);
146
- if (position < 0) {
147
+ if (position == UNEXPECTED_END) {
147
148
  return unexpectedEnd(env);
148
149
  }
149
150
  }
@@ -166,7 +167,7 @@ public:
166
167
  memcpy(&array, &v8Array, sizeof(array));
167
168
  #else
168
169
  napi_create_array_with_length(env, writePosition, &array);
169
- for (int i = 0; i < writePosition; i++) {
170
+ for (uint32_t i = 0; i < writePosition; i++) {
170
171
  napi_set_element(env, array, i, target[i]);
171
172
  }
172
173
  #endif
@@ -195,54 +196,54 @@ void setupTokenTable() {
195
196
  // fixext 16
196
197
  tokenTable[0xd8] = (token_handler) 17;
197
198
  // bin 8
198
- tokenTable[0xc4] = ([](uint8_t* source, int position, int size) -> int {
199
+ tokenTable[0xc4] = ([](uint8_t* source, uint32_t position, uint32_t size) -> uint32_t {
199
200
  if (position >= size) {
200
- return -1;
201
+ return UNEXPECTED_END;
201
202
  }
202
- int length = source[position++];
203
+ uint32_t length = source[position++];
203
204
  return position + length;
204
205
  });
205
206
  // bin 16
206
- tokenTable[0xc5] = ([](uint8_t* source, int position, int size) -> int {
207
+ tokenTable[0xc5] = ([](uint8_t* source, uint32_t position, uint32_t size) -> uint32_t {
207
208
  if (position + 2 > size) {
208
- return -1;
209
+ return UNEXPECTED_END;
209
210
  }
210
- int length = source[position++] << 8;
211
+ uint32_t length = source[position++] << 8;
211
212
  length += source[position++];
212
213
  return position + length;
213
214
  });
214
215
  // bin 32
215
- tokenTable[0xc6] = ([](uint8_t* source, int position, int size) -> int {
216
+ tokenTable[0xc6] = ([](uint8_t* source, uint32_t position, uint32_t size) -> uint32_t {
216
217
  if (position + 4 > size)
217
- return -1;
218
- int length = source[position++] << 24;
218
+ return UNEXPECTED_END;
219
+ uint32_t length = source[position++] << 24;
219
220
  length += source[position++] << 16;
220
221
  length += source[position++] << 8;
221
222
  length += source[position++];
222
223
  return position + length;
223
224
  });
224
225
  // ext 8
225
- tokenTable[0xc7] = ([](uint8_t* source, int position, int size) -> int {
226
+ tokenTable[0xc7] = ([](uint8_t* source, uint32_t position, uint32_t size) -> uint32_t {
226
227
  if (position >= size)
227
- return -1;
228
- int length = source[position++];
228
+ return UNEXPECTED_END;
229
+ uint32_t length = source[position++];
229
230
  position++;
230
231
  return position + length;
231
232
  });
232
233
  // ext 16
233
- tokenTable[0xc8] = ([](uint8_t* source, int position, int size) -> int {
234
+ tokenTable[0xc8] = ([](uint8_t* source, uint32_t position, uint32_t size) -> uint32_t {
234
235
  if (position + 2 > size)
235
- return -1;
236
- int length = source[position++] << 8;
236
+ return UNEXPECTED_END;
237
+ uint32_t length = source[position++] << 8;
237
238
  length += source[position++];
238
239
  position++;
239
240
  return position + length;
240
241
  });
241
242
  // ext 32
242
- tokenTable[0xc9] = ([](uint8_t* source, int position, int size) -> int {
243
+ tokenTable[0xc9] = ([](uint8_t* source, uint32_t position, uint32_t size) -> uint32_t {
243
244
  if (position + 4 > size)
244
- return -1;
245
- int length = source[position++] << 24;
245
+ return UNEXPECTED_END;
246
+ uint32_t length = source[position++] << 24;
246
247
  length += source[position++] << 16;
247
248
  length += source[position++] << 8;
248
249
  length += source[position++];
@@ -261,7 +262,7 @@ napi_value extractStrings(napi_env env, napi_callback_info info) {
261
262
  napi_get_value_uint32(env, args[1], &size);
262
263
  uint8_t* source;
263
264
  size_t buffer_size;
264
- napi_get_buffer_info(env, args[2], (void**) &source, &buffer_size);
265
+ napi_get_arraybuffer_info(env, args[2], (void**) &source, &buffer_size);
265
266
  return extractor->extractStrings(env, position, size, source);
266
267
  }
267
268
  #define EXPORT_NAPI_FUNCTION(name, func) { napi_property_descriptor desc = { name, 0, func, 0, 0, 0, (napi_property_attributes) (napi_writable | napi_configurable), 0 }; napi_define_properties(env, exports, 1, &desc); }