-
Notifications
You must be signed in to change notification settings - Fork 18k
x/net/http2: suspicious uint32→int conversion in http2 frame implementation #64961
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
Comments
(attn @neild) |
@sivukhin, want to send a fix? At the very least, this code ought to be written more clearly. |
Yes, sure, will prepare patch tomorrow. |
@bcmills, done: https://go-review.googlesource.com/c/net/+/554235 Also, what do you think about adding helpers in stdlib which will simplify integer type conversions to native |
Change https://go.dev/cl/554275 mentions this issue: |
Change https://go.dev/cl/554235 mentions this issue: |
Go version
analyzed net library from commit: f12db26b1c9293fa3eb95c936e548d2c1fba4ba9
What operating system and processor architecture are you using (
go env
)?Analyzed source code with linter - so the env is irrelevant.
What did you do?
I ran custom govanish linter against
golang/net
GitHub repo and it found that following statements were removed from compiled binary:This is ok because my machine is 64 bit, but when I inspected this code I found it weird because conversion of types
uint32 -> int32 -> uint32
on 32bit architectures should results in noop because there is no loss of precision.I implemented explicit conversion funcs with
int32
/int64
types to prove this statement:Godbolt link with compiled functions against
x86 gc (tip)
target: https://godbolt.org/z/688bf4jEsI suspect that this part of the code will produce negative
MaxStringLen
header. Not sure if this will results in any bad consequences but I think it's better to fix this issue and implement more straightforward check.What did you expect to see?
Conversion from
uint32
toint
should always produce non-negative numbersWhat did you see instead?
Conversion from
uint32
toint
can produce negative numbersThe text was updated successfully, but these errors were encountered: