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 +15 -10
- package/dist/node.cjs.map +1 -1
- package/package.json +1 -1
- package/stream.js +15 -10
package/package.json
CHANGED
package/stream.js
CHANGED
|
@@ -25,6 +25,7 @@ export class UnpackrStream extends Transform {
|
|
|
25
25
|
options.objectMode = true
|
|
26
26
|
super(options)
|
|
27
27
|
options.structures = []
|
|
28
|
+
this.maxIncompleteBufferSize = options.maxIncompleteBufferSize !== undefined ? options.maxIncompleteBufferSize : 0x4000000
|
|
28
29
|
this.unpackr = options.unpackr || new Unpackr(options)
|
|
29
30
|
}
|
|
30
31
|
_transform(chunk, encoding, callback) {
|
|
@@ -37,19 +38,23 @@ export class UnpackrStream extends Transform {
|
|
|
37
38
|
values = this.unpackr.unpackMultiple(chunk)
|
|
38
39
|
} catch(error) {
|
|
39
40
|
if (error.incomplete) {
|
|
40
|
-
|
|
41
|
+
let incompleteBuffer = chunk.slice(error.lastPosition)
|
|
42
|
+
if (incompleteBuffer.length > this.maxIncompleteBufferSize) {
|
|
43
|
+
this.incompleteBuffer = null
|
|
44
|
+
return callback(new Error('Maximum incomplete buffer size exceeded'))
|
|
45
|
+
}
|
|
46
|
+
this.incompleteBuffer = incompleteBuffer
|
|
41
47
|
values = error.values
|
|
48
|
+
} else {
|
|
49
|
+
return callback(error)
|
|
42
50
|
}
|
|
43
|
-
else
|
|
44
|
-
throw error
|
|
45
|
-
} finally {
|
|
46
|
-
for (let value of values || []) {
|
|
47
|
-
if (value === null)
|
|
48
|
-
value = this.getNullValue()
|
|
49
|
-
this.push(value)
|
|
50
|
-
}
|
|
51
51
|
}
|
|
52
|
-
|
|
52
|
+
for (let value of values || []) {
|
|
53
|
+
if (value === null)
|
|
54
|
+
value = this.getNullValue()
|
|
55
|
+
this.push(value)
|
|
56
|
+
}
|
|
57
|
+
callback()
|
|
53
58
|
}
|
|
54
59
|
getNullValue() {
|
|
55
60
|
return Symbol.for(null)
|