-
Notifications
You must be signed in to change notification settings - Fork 18k
bufio: calling Reset with itself leads to infinite recursion #58423
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
Change https://go.dev/cl/466815 mentions this issue: |
@ianlancetaylor you might want to use the two-value type assertion in case |
@ericlagergren Thanks, but it's not necessary. When comparing a non-interface against an interface value, we first check that the types are the same. If they are not, the comparison is not-equal. Only if the types are the same do we compare the values. And if the types are the same, we know that the type must be |
@ianlancetaylor oops. Apologies for the noise. |
This can happen in reasonable code because NewReader(r) can return r, if r is already a Reader. Similarly for Writer. Fixes golang#58423 Change-Id: Iff9d9265410bee68fbaeb7175369847bd737eb2c Reviewed-on: https://go-review.googlesource.com/c/go/+/466815 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org>
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 ran into this issue in a prometheus package that I was using.
The problem is that
bufio.NewReader
will return its givenio.Reader
as-is, if it happens to already be a*bufio.Reader
of sufficient size. If you later callbufio.(*Reader).Reset
on the "new"*bufio.Reader
with the originalio.Reader
, it ends up setting the*bufio.Reader
as its own underlyingio.Reader
. Then when you try toRead
from it, there's an infinite recursion and stack overflow.It's kinda strange to
Reset
a*bufio.Reader
with the sameio.Reader
from which it was created, but I don't thinkbufio.NewReader
should use the return as-is optimization without also handling thisReset
with self issue.My repro code is obviously contrived, but the actual case where this happened seemed fairly reasonable.
https://go.dev/play/p/2UTNBLVR1J__E
What did you expect to see?
I expected to see my server running smoothly.
What did you see instead?
My server kept crashing or getting OOM killed.
The text was updated successfully, but these errors were encountered: