bl 4.0.2 → 4.0.3
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/.travis.yml +1 -1
- package/BufferList.js +10 -1
- package/package.json +2 -1
- package/test/test.js +16 -0
package/.travis.yml
CHANGED
package/BufferList.js
CHANGED
|
@@ -134,12 +134,13 @@ BufferList.prototype.copy = function copy (dst, dstStart, srcStart, srcEnd) {
|
|
|
134
134
|
|
|
135
135
|
if (bytes > l) {
|
|
136
136
|
this._bufs[i].copy(dst, bufoff, start)
|
|
137
|
+
bufoff += l
|
|
137
138
|
} else {
|
|
138
139
|
this._bufs[i].copy(dst, bufoff, start, start + bytes)
|
|
140
|
+
bufoff += l
|
|
139
141
|
break
|
|
140
142
|
}
|
|
141
143
|
|
|
142
|
-
bufoff += l
|
|
143
144
|
bytes -= l
|
|
144
145
|
|
|
145
146
|
if (start) {
|
|
@@ -147,6 +148,9 @@ BufferList.prototype.copy = function copy (dst, dstStart, srcStart, srcEnd) {
|
|
|
147
148
|
}
|
|
148
149
|
}
|
|
149
150
|
|
|
151
|
+
// safeguard so that we don't return uninitialized memory
|
|
152
|
+
if (dst.length > bufoff) return dst.slice(0, bufoff)
|
|
153
|
+
|
|
150
154
|
return dst
|
|
151
155
|
}
|
|
152
156
|
|
|
@@ -188,6 +192,11 @@ BufferList.prototype.toString = function toString (encoding, start, end) {
|
|
|
188
192
|
}
|
|
189
193
|
|
|
190
194
|
BufferList.prototype.consume = function consume (bytes) {
|
|
195
|
+
// first, normalize the argument, in accordance with how Buffer does it
|
|
196
|
+
bytes = Math.trunc(bytes)
|
|
197
|
+
// do nothing if not a positive number
|
|
198
|
+
if (Number.isNaN(bytes) || bytes <= 0) return this
|
|
199
|
+
|
|
191
200
|
while (this._bufs.length) {
|
|
192
201
|
if (bytes >= this._bufs[0].length) {
|
|
193
202
|
bytes -= this._bufs[0].length
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bl",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.3",
|
|
4
4
|
"description": "Buffer List: collect buffers and access with a standard readable Buffer interface, streamable too!",
|
|
5
|
+
"license": "MIT",
|
|
5
6
|
"main": "bl.js",
|
|
6
7
|
"scripts": {
|
|
7
8
|
"lint": "standard *.js test/*.js",
|
package/test/test.js
CHANGED
|
@@ -463,6 +463,22 @@ tape('test toString encoding', function (t) {
|
|
|
463
463
|
t.end()
|
|
464
464
|
})
|
|
465
465
|
|
|
466
|
+
tape('uninitialized memory', function (t) {
|
|
467
|
+
const secret = crypto.randomBytes(256)
|
|
468
|
+
for (let i = 0; i < 1e6; i++) {
|
|
469
|
+
const clone = Buffer.from(secret)
|
|
470
|
+
const bl = new BufferList()
|
|
471
|
+
bl.append(Buffer.from('a'))
|
|
472
|
+
bl.consume(-1024)
|
|
473
|
+
const buf = bl.slice(1)
|
|
474
|
+
if (buf.indexOf(clone) !== -1) {
|
|
475
|
+
t.fail(`Match (at ${i})`)
|
|
476
|
+
break
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
t.end()
|
|
480
|
+
})
|
|
481
|
+
|
|
466
482
|
!process.browser && tape('test stream', function (t) {
|
|
467
483
|
const random = crypto.randomBytes(65534)
|
|
468
484
|
|