kamaci commented on issue #6932: Raw byte values should not be used in bitwise 
operations in combination with shifts.
URL: https://github.com/apache/incubator-druid/pull/6932#issuecomment-459274669
 
 
   Here are some explanations about this vulnerability:
   
   > When reading bytes in order to build other primitive values such as ints 
or longs, the byte values are automatically promoted, but that promotion can 
have unexpected results.
   > 
   > For instance, the binary representation of the integer 640 is 
0b0000_0010_1000_0000, which can also be written with the array of (unsigned) 
bytes [2, 128]. However, since Java uses two's complement, the representation 
of the integer in signed bytes will be [2, -128] (because the byte 0b1000_0000 
is promoted to the int 0b1111_1111_1111_1111_1111_1111_1000_0000). 
Consequently, trying to reconstruct the initial integer by shifting and adding 
the values of the bytes without taking care of the sign will not produce the 
expected result.
   
   
https://wiki.sei.cmu.edu/confluence/display/java/NUM52-J.+Be+aware+of+numeric+promotion+behavior

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to