summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAapo Alasuutari <aapo.alasuutari@gmail.com>2023-09-24 13:48:23 +0300
committerGitHub <noreply@github.com>2023-09-24 13:48:23 +0300
commitcb9ab9c3ac53ed642c6c648f4931056551a378b7 (patch)
tree2696769f549621f50fb0feb13add43b24a9dcdf4
parent0e2637f8517cada6c41431741caa8826be602f99 (diff)
fix(ext/node): Fix invalid length variable reference in blitBuffer (#20648)
-rw-r--r--ext/node/polyfills/internal/buffer.mjs7
1 files changed, 4 insertions, 3 deletions
diff --git a/ext/node/polyfills/internal/buffer.mjs b/ext/node/polyfills/internal/buffer.mjs
index 1a2dc31df..29c0a5584 100644
--- a/ext/node/polyfills/internal/buffer.mjs
+++ b/ext/node/polyfills/internal/buffer.mjs
@@ -1760,22 +1760,23 @@ function utf8ToBytes(string, units) {
}
function blitBuffer(src, dst, offset, byteLength = Infinity) {
+ const srcLength = src.length;
// Establish the number of bytes to be written
const bytesToWrite = Math.min(
// If byte length is defined in the call, then it sets an upper bound,
// otherwise it is Infinity and is never chosen.
byteLength,
// The length of the source sets an upper bound being the source of data.
- src.length,
+ srcLength,
// The length of the destination minus any offset into it sets an upper bound.
dst.length - offset,
);
- if (bytesToWrite < src.length) {
+ if (bytesToWrite < srcLength) {
// Resize the source buffer to the number of bytes we're about to write.
// This both makes sure that we're actually only writing what we're told to
// write but also prevents `Uint8Array#set` from throwing an error if the
// source is longer than the target.
- src = src.subarray(0, length);
+ src = src.subarray(0, bytesToWrite);
}
dst.set(src, offset);
return bytesToWrite;