msgpackr 1.11.11 → 1.11.12

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/node.cjs CHANGED
@@ -3172,6 +3172,7 @@ class UnpackrStream extends stream.Transform {
3172
3172
  options.objectMode = true;
3173
3173
  super(options);
3174
3174
  options.structures = [];
3175
+ this.maxIncompleteBufferSize = options.maxIncompleteBufferSize !== undefined ? options.maxIncompleteBufferSize : 0x4000000;
3175
3176
  this.unpackr = options.unpackr || new Unpackr(options);
3176
3177
  }
3177
3178
  _transform(chunk, encoding, callback) {
@@ -3184,19 +3185,23 @@ class UnpackrStream extends stream.Transform {
3184
3185
  values = this.unpackr.unpackMultiple(chunk);
3185
3186
  } catch(error) {
3186
3187
  if (error.incomplete) {
3187
- this.incompleteBuffer = chunk.slice(error.lastPosition);
3188
+ let incompleteBuffer = chunk.slice(error.lastPosition);
3189
+ if (incompleteBuffer.length > this.maxIncompleteBufferSize) {
3190
+ this.incompleteBuffer = null;
3191
+ return callback(new Error('Maximum incomplete buffer size exceeded'))
3192
+ }
3193
+ this.incompleteBuffer = incompleteBuffer;
3188
3194
  values = error.values;
3189
- }
3190
- else
3191
- throw error
3192
- } finally {
3193
- for (let value of values || []) {
3194
- if (value === null)
3195
- value = this.getNullValue();
3196
- this.push(value);
3195
+ } else {
3196
+ return callback(error)
3197
3197
  }
3198
3198
  }
3199
- if (callback) callback();
3199
+ for (let value of values || []) {
3200
+ if (value === null)
3201
+ value = this.getNullValue();
3202
+ this.push(value);
3203
+ }
3204
+ callback();
3200
3205
  }
3201
3206
  getNullValue() {
3202
3207
  return Symbol.for(null)