mirror of
https://github.com/denoland/deno.git
synced 2024-12-25 00:29:09 -05:00
fix(ext/node): fix Buffer.copy when sourceStart > source.length (#21345)
This commit is contained in:
parent
4ed9278bf4
commit
567d7ff923
4 changed files with 7 additions and 6 deletions
|
@ -22,7 +22,6 @@
|
||||||
"test-buffer-alloc.js",
|
"test-buffer-alloc.js",
|
||||||
"test-buffer-arraybuffer.js",
|
"test-buffer-arraybuffer.js",
|
||||||
"test-buffer-bytelength.js",
|
"test-buffer-bytelength.js",
|
||||||
"test-buffer-copy.js",
|
|
||||||
"test-buffer-from.js",
|
"test-buffer-from.js",
|
||||||
"test-buffer-includes.js",
|
"test-buffer-includes.js",
|
||||||
"test-buffer-indexof.js",
|
"test-buffer-indexof.js",
|
||||||
|
|
|
@ -131,7 +131,7 @@ b.copy(Buffer.alloc(0), 1, 1, 1);
|
||||||
b.copy(Buffer.alloc(1), 1, 1, 1);
|
b.copy(Buffer.alloc(1), 1, 1, 1);
|
||||||
|
|
||||||
// Try to copy 0 bytes from past the end of the source buffer
|
// Try to copy 0 bytes from past the end of the source buffer
|
||||||
b.copy(Buffer.alloc(1), 0, 2048, 2048);
|
b.copy(Buffer.alloc(1), 0, 1024, 1024);
|
||||||
|
|
||||||
// Testing for smart defaults and ability to pass string values as offset
|
// Testing for smart defaults and ability to pass string values as offset
|
||||||
{
|
{
|
||||||
|
|
|
@ -165,7 +165,6 @@ assert.throws(
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
/*
|
|
||||||
// Copy throws if sourceStart is greater than length of source
|
// Copy throws if sourceStart is greater than length of source
|
||||||
assert.throws(
|
assert.throws(
|
||||||
() => Buffer.allocUnsafe(5).copy(Buffer.allocUnsafe(5), 0, 100),
|
() => Buffer.allocUnsafe(5).copy(Buffer.allocUnsafe(5), 0, 100),
|
||||||
|
@ -174,7 +173,6 @@ assert.throws(
|
||||||
name: 'RangeError',
|
name: 'RangeError',
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
*/
|
|
||||||
|
|
||||||
{
|
{
|
||||||
// Check sourceEnd resets to targetEnd if former is greater than the latter
|
// Check sourceEnd resets to targetEnd if former is greater than the latter
|
||||||
|
|
|
@ -1536,8 +1536,12 @@ Buffer.prototype.copy = function copy(
|
||||||
sourceStart = 0;
|
sourceStart = 0;
|
||||||
} else {
|
} else {
|
||||||
sourceStart = toInteger(sourceStart, 0);
|
sourceStart = toInteger(sourceStart, 0);
|
||||||
if (sourceStart < 0) {
|
if (sourceStart < 0 || sourceStart > this.length) {
|
||||||
throw new codes.ERR_OUT_OF_RANGE("sourceStart", ">= 0", sourceStart);
|
throw new codes.ERR_OUT_OF_RANGE(
|
||||||
|
"sourceStart",
|
||||||
|
`>= 0 && <= ${this.length}`,
|
||||||
|
sourceStart,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (sourceStart >= MAX_UINT32) {
|
if (sourceStart >= MAX_UINT32) {
|
||||||
throw new codes.ERR_OUT_OF_RANGE(
|
throw new codes.ERR_OUT_OF_RANGE(
|
||||||
|
|
Loading…
Reference in a new issue