-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
parseHexInt doesn't check the value's length. #17208
Comments
let a = 0xFF00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF compiles, but shouldn't
|
Related: |
@timotheecour I wouldn't say this behavior is arbitrary; if the hex is treated as bytes, it's valid behavior to turn negative. If the hex is treated as an integer though, as the name states, no signage should be applied. Moving to a pure unsigned type entirely would definitely resolve this though. Also, to comment on the use case in which this came up, due to the linking of #4350 whose first comment dismisses hex checking, it's not even any low-level sys task. I'm reading HTTP bodies. Streamed requests use the chunked transfer encoding which denotes length in hex. While receiving > 2 GB of data in a chunk is completely infeasible, this would claim it's < the max length (and then break on receiving said chunk). |
I wasn't all that serious when I wrote this and left the bug open for a good reason. My apologies. |
parseHexInt
, from strutils, doesn't check the hex value's bit length. If the sign bit is set (assuming a naive byte case), parseHexInt will return negative numbers. If the value's length is too long, only the last bytes of it are read, ignoring the first.Example
Current Output
Expected Output
A ValueError, and if execution wasn't halted, yet another (or at least a RangeError).
Possible Solution
Validate input length doesn't exceed the int size limit/if the sign bit was set.
The text was updated successfully, but these errors were encountered: