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
encoding/hex: panic on hex.Decode with not enough space of dst #34982
Comments
Change https://golang.org/cl/201957 mentions this issue: |
The documentation for
Did you ensure that The |
As noted on the CL: I don't think this would be a net improvement, regardless of whether If the lengths of If the lengths are already known, then an extra run-time comparison potentially slows the loop for no benefit — and, more importantly, masks bugs that would otherwise be caught during testing (as panics) by treating them as equivalent to invalid input strings. |
Thanks for your comments. Like you commented, Decode says
But does not say
In case of sending and receiveing And actually I agree with your comment
But I steel think hex.Decode need I hope golang official library doesn't panic without saying. |
You're describing using the API as such:
which, per the function's docs, is incorrect:
I do think the docs could be more clear that the function expects |
Go APIs generally do not (and should not!) document what happens if you call them with arguments that do not satisfy their documented preconditions. A function that panics for a given input today could be changed to accept that input, return an explicit error for it, report a race in (It should strive to always do something reasonable in order to help the user diagnose the problem, but beyond that it should not be constrained in what it does. In that regard, a |
If there is no more comments, is it ok to close this issue? I found out why this issue happened and how to fix it. Thanks @bcmills |
Done. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I tried hex.Decode with not enough space of dst
https://play.golang.org/p/suJblfGs0EQ
What did you expect to see?
returning error
What did you see instead?
panic
I belive this panic occured because of hex.Decode does not check length or capacity of dst
In src/encoding/hex/hex.go#L58
and I suggest change this code into
The text was updated successfully, but these errors were encountered: