Skip to content

Commit 9239033

Browse files
kixelatedclaude
andauthored
Fix buffer capacity check in varint encode to account for byteOffset (#127)
The capacity check was comparing against the buffer's total byteLength without accounting for byteOffset. For Uint8Array views over a larger buffer, this could incorrectly allow writes that exceed the available space. Use dst.byteOffset + dst.byteLength + size > dst.buffer.byteLength to properly check the actual end position of the appended data. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <[email protected]>
1 parent 62fd026 commit 9239033

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

web-transport-ws/src/varint.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class VarInt {
2828
const x = this.value;
2929

3030
const size = this.size();
31-
if (dst.buffer.byteLength < dst.byteLength + size) {
31+
if (dst.byteOffset + dst.byteLength + size > dst.buffer.byteLength) {
3232
throw new Error("destination buffer too small");
3333
}
3434

0 commit comments

Comments
 (0)