You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Address6.fromByteArray and fromUnsignedByteArray fold whatever they are given
into a BigInt and bounds-check only the aggregate, so wrong-length,
out-of-range and non-integer input produces a plausible wrong address instead
of an error: three bytes give ::1:203, seventeen bytes whose first is zero
give ::1, a low byte of 300 gives ::12c, and a byte of 1.5 gives 100::. A
17-byte array shows why the aggregate bound cannot cover this, since a leading
zero keeps the magnitude under 2**128. Address4 rejects all four.
This reaches consumers. socks calls Address6.fromByteArray at three sites with
Array.from(buff.readBuffer(16)), and in parseUDPFrame that buffer is an
unvalidated datagram while smart-buffer's readBuffer clamps a short read with
Math.min rather than throwing. A SOCKS5 UDP frame carrying four address bytes
therefore reports a remote host of 0000:0000:0000:0000:0000:0000:dead:beef.
Both methods now require exactly 16 bytes.
fromByteArray keeps folding signed bytes to unsigned, so an Int8Array or a
Java byte[] still works and nothing that parses today stops parsing; its floor
is -128, below which folding would silently produce a value the caller did not
mean. fromUnsignedByteArray takes 0 to 255. The length and range checks live
in one place that Address4 shares, replacing its copy of the same loop, with
its messages unchanged.
Address6.fromByteArray accepting signed bytes while Address4.fromByteArray
rejects them, and toUnsignedByteArray returning what toByteArray already
returns, are differences to settle in a major version rather than here, where
the point is to reach the versions socks resolves. A test asserts the major
version is below 11 and names what to delete when it is not.
The byte array parameters are typed number[] rather than any[], matching
Address4.
Co-authored-by: gaoflow <[email protected]>
0 commit comments