Skip to content

Commit bd8f96e

Browse files
committed
buffer: validate copyArrayBuffer offsets against buffer length
CopyArrayBuffer() computed `byteLength - offset` in unsigned arithmetic before its CHECK_GE bounds check. An offset greater than the buffer length wrapped the subtraction to a near-SIZE_MAX value, so the check passed and memcpy() copied out of bounds. process.binding('buffer').copyArrayBuffer() is an internal, trusted binding; the only in-tree caller, the Web Streams BYOB reader, already validates the offsets in JS. Assert the offsets are within bounds with CHECK_LE before the subtractions so the invariant holds regardless of caller, matching the CHECK-based style already used here. Signed-off-by: Ilia Alshanetsky <ilia@ilia.ws>
1 parent 2fb168f commit bd8f96e

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

src/node_buffer.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,6 +1569,10 @@ void CopyArrayBuffer(const FunctionCallbackInfo<Value>& args) {
15691569
uint32_t source_offset = args[3].As<Uint32>()->Value();
15701570
size_t bytes_to_copy = args[4].As<Uint32>()->Value();
15711571

1572+
// Assert the offsets are within bounds before the subtractions below, which
1573+
// would otherwise underflow and defeat the bytes_to_copy bounds checks.
1574+
CHECK_LE(destination_offset, destination_byte_length);
1575+
CHECK_LE(source_offset, source_byte_length);
15721576
CHECK_GE(destination_byte_length - destination_offset, bytes_to_copy);
15731577
CHECK_GE(source_byte_length - source_offset, bytes_to_copy);
15741578

0 commit comments

Comments
 (0)