bl 1.2.2 → 1.2.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 +4 -7
- package/bl.js +10 -1
- package/package.json +1 -1
- package/test/test.js +16 -0
package/.travis.yml
CHANGED
package/bl.js
CHANGED
|
@@ -173,18 +173,22 @@ BufferList.prototype.copy = function copy (dst, dstStart, srcStart, srcEnd) {
|
|
|
173
173
|
|
|
174
174
|
if (bytes > l) {
|
|
175
175
|
this._bufs[i].copy(dst, bufoff, start)
|
|
176
|
+
bufoff += l
|
|
176
177
|
} else {
|
|
177
178
|
this._bufs[i].copy(dst, bufoff, start, start + bytes)
|
|
179
|
+
bufoff += l
|
|
178
180
|
break
|
|
179
181
|
}
|
|
180
182
|
|
|
181
|
-
bufoff += l
|
|
182
183
|
bytes -= l
|
|
183
184
|
|
|
184
185
|
if (start)
|
|
185
186
|
start = 0
|
|
186
187
|
}
|
|
187
188
|
|
|
189
|
+
// safeguard so that we don't return uninitialized memory
|
|
190
|
+
if (dst.length > bufoff) return dst.slice(0, bufoff)
|
|
191
|
+
|
|
188
192
|
return dst
|
|
189
193
|
}
|
|
190
194
|
|
|
@@ -217,6 +221,11 @@ BufferList.prototype.toString = function toString (encoding, start, end) {
|
|
|
217
221
|
}
|
|
218
222
|
|
|
219
223
|
BufferList.prototype.consume = function consume (bytes) {
|
|
224
|
+
// first, normalize the argument, in accordance with how Buffer does it
|
|
225
|
+
bytes = Math.trunc(bytes)
|
|
226
|
+
// do nothing if not a positive number
|
|
227
|
+
if (Number.isNaN(bytes) || bytes <= 0) return this
|
|
228
|
+
|
|
220
229
|
while (this._bufs.length) {
|
|
221
230
|
if (bytes >= this._bufs[0].length) {
|
|
222
231
|
bytes -= this._bufs[0].length
|
package/package.json
CHANGED
package/test/test.js
CHANGED
|
@@ -381,6 +381,22 @@ tape('test toString encoding', function (t) {
|
|
|
381
381
|
t.end()
|
|
382
382
|
})
|
|
383
383
|
|
|
384
|
+
tape('uninitialized memory', function (t) {
|
|
385
|
+
const secret = crypto.randomBytes(256)
|
|
386
|
+
for (let i = 0; i < 1e6; i++) {
|
|
387
|
+
const clone = Buffer.from(secret)
|
|
388
|
+
const bl = new BufferList()
|
|
389
|
+
bl.append(Buffer.from('a'))
|
|
390
|
+
bl.consume(-1024)
|
|
391
|
+
const buf = bl.slice(1)
|
|
392
|
+
if (buf.indexOf(clone) !== -1) {
|
|
393
|
+
t.fail(`Match (at ${i})`)
|
|
394
|
+
break
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
t.end()
|
|
398
|
+
})
|
|
399
|
+
|
|
384
400
|
!process.browser && tape('test stream', function (t) {
|
|
385
401
|
var random = crypto.randomBytes(65534)
|
|
386
402
|
, rndhash = hash(random, 'md5')
|