-
Notifications
You must be signed in to change notification settings - Fork 18k
encoding/gob: preallocation in decodeSlice can consume large amounts of memory #55338
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
See previously #27635 and #28321.
For the sake of fuzzing, I guess you could patch the codebase to change the constant to whatever you see fit. I'm not sure whether it makes sense to add an API option just for that limit; if we were to improve the API for handling untrusted data, I think we would have to do it more generally, like #20221. |
Sorry, is this the bug? Is allocating 4GB OOM? Or what is it? It is unclear to me what the problem is. Thanks.
I'm not sure I understand what the purpose of adjusting tooBig is. Could you clarify? (But based on the comment above, this is probably not what we're going to do.) |
decodeSlice is preemptively allocating a slice as described by a malformed gob message, which describes a very large slice but not its content, by using reflect.MakeSlice. Because of this an adversarial, or corrupt, message can cause a very small message to consume a very large amount of memory. One solution is not preallocating the slice and using reflect.Append instead to grow it (this will presumably have some performance impact.) |
What version of Go do you use? Go 1.17.6 is no longer supported. I understand that the bug may still exist, but could you use newer version and report bugs for a supported version of Go? Thanks. |
Will output Hello, 世界 |
Let's just use |
Change https://go.dev/cl/433296 mentions this issue: |
I actually now use go version go1.18.3 darwin/amd64 |
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?
Run https://go.dev/play/p/nQR5wqtQV1K?v=gotip
What did you expect to see?
The program finishing and printing somme dummy data
What did you see instead?
Nothing but
This ends up allocating 4GB from encoding/gob.(*Decoder).decodeSlice
Can we have some function to set ourselves
tooBig
?Found by https://github.com/catenacyber/ngolo-fuzzing on oss-fuzz
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=50748
cc @rolandshoemaker
The text was updated successfully, but these errors were encountered: