mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 09:31:22 -05:00
fix(ext/node): Fix invalid length variable reference in blitBuffer (#20648)
This commit is contained in:
parent
0e2637f851
commit
cb9ab9c3ac
1 changed files with 4 additions and 3 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue