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
expfmt: TextDecoder infinite bufio Read recursion #442
Comments
Repro of the underlying issue with just the standard library: https://go.dev/play/p/2UTNBLVR1J__E |
This was referenced Feb 9, 2023
roidelapluie
added a commit
to roidelapluie/common
that referenced
this issue
Feb 20, 2023
The test case checks that a *bufio.Reader can be passed to expfmt.NewDecoder with the FmtText format without causing an infinite recursion. This is a regression test for the issue reported in prometheus#442. Signed-off-by: Julien Pivotto <roidelapluie@o11y.eu>
radek-ryckowski
pushed a commit
to goldmansachs/common
that referenced
this issue
May 18, 2023
The test case checks that a *bufio.Reader can be passed to expfmt.NewDecoder with the FmtText format without causing an infinite recursion. This is a regression test for the issue reported in prometheus#442. Signed-off-by: Julien Pivotto <roidelapluie@o11y.eu>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Problem
If the
io.Reader
passed toexpfmt.NewDecoder
with theexpfmt.FmtText
format is a*bufio.Reader
, thenDecoder.Decode
will infinitely recurse in thebufio.(*Reader).Read
function.Explanation
expfmt.(*textDecoder).Decode calls expfmt.(*TextParser).TextToMetricFamilies passing its same
io.Reader
each time, which is then passed to expfmt.(*TextParser).reset, which contains the following snippet:The problem is that
bufio.NewReader
will return the givenio.Reader
without wrapping it, if it happens to already be a*bufio.Reader
of sufficient size. All good on the first call fromDecode
, but the second call ends up setting the*bufio.Reader
as its own underlyingio.Reader
and we get an infinite recursion.A reasonable person might argue that this is a bug in
bufio
, but we can still fix it inexpfmt
.Repro
The text was updated successfully, but these errors were encountered: