1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-24 08:09:08 -05:00

fix(ext/node): fix Buffer.copy when sourceStart > source.length (#21345)

This commit is contained in:
Yoshiya Hinosawa 2023-11-28 22:28:07 +09:00 committed by GitHub
parent 4ed9278bf4
commit 567d7ff923
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 6 deletions

View file

@ -22,7 +22,6 @@
"test-buffer-alloc.js",
"test-buffer-arraybuffer.js",
"test-buffer-bytelength.js",
"test-buffer-copy.js",
"test-buffer-from.js",
"test-buffer-includes.js",
"test-buffer-indexof.js",

View file

@ -131,7 +131,7 @@ b.copy(Buffer.alloc(0), 1, 1, 1);
b.copy(Buffer.alloc(1), 1, 1, 1);
// 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
{

View file

@ -165,7 +165,6 @@ assert.throws(
}
);
/*
// Copy throws if sourceStart is greater than length of source
assert.throws(
() => Buffer.allocUnsafe(5).copy(Buffer.allocUnsafe(5), 0, 100),
@ -174,7 +173,6 @@ assert.throws(
name: 'RangeError',
}
);
*/
{
// Check sourceEnd resets to targetEnd if former is greater than the latter

View file

@ -1536,8 +1536,12 @@ Buffer.prototype.copy = function copy(
sourceStart = 0;
} else {
sourceStart = toInteger(sourceStart, 0);
if (sourceStart < 0) {
throw new codes.ERR_OUT_OF_RANGE("sourceStart", ">= 0", sourceStart);
if (sourceStart < 0 || sourceStart > this.length) {
throw new codes.ERR_OUT_OF_RANGE(
"sourceStart",
`>= 0 && <= ${this.length}`,
sourceStart,
);
}
if (sourceStart >= MAX_UINT32) {
throw new codes.ERR_OUT_OF_RANGE(