Description
Thing to note here: A >>> B
converts both arguments to unsigned int: http://www.ecma-international.org/ecma-262/6.0/#sec-unsigned-right-shift-operator.
buffer.js#L314 is not reachable. If argumentFixed.start
is a number that is less than 0, thenstart >>> 0
makes it a (large) positive number.- buffer.js#L498 has
offset < 0
check that is not reachable, because above it was either set to0
oroffset >>> 0
orlength >>> 0
. buffer.js#L498 haslength < 0
check that is reachable only throughXXX legacy write(string, encoding, offset, length) - remove in v0.13
case, because else it was set to either0
,undefined
, orthis.length
(which should be probably not less than 0 I guess). On a side note: sould that legacy path be removed in 4.0 or not? Btw, in the «legacy write(» case there is no type checking or casting forlength
.
Also, on many other lines, offset = offset >>> 0
and a succeeding checkInt(this, value, offset
is done.
Note that -30064771000 >>> 0
=== 72
, which makes -30064771000
a valid offset
input, which could be a bit unexpected. Also, checkInt
doesn't check for offset
(or offset + ext
) to be not less than zero. Such check would be unreachable now (because offset
is always cast to unsigned), but it could be usable once this is fixed.
var x = new Buffer(10).fill(0);
x.writeUInt32BE(0xdeadbeef, -30064771070);
x
<Buffer 00 00 de ad be ef 00 00 00 00>
Btw, with these negative values the same happens also when >>
or |
(or any other cast-to-int) is used: -30064771070 >> 0 === 2
, -30064771070 | 0 === 0
. All checks should be probably done before int casting.
Maybe it's worth splitting this into two issues — unreachable code and casting before checks.