bufio: ScanLines hangs forever if it reads an enormous string with no newlines #35474
Labels
FrozenDueToAge
WaitingForInfo
Issue is not actionable because of missing required information, which needs to be provided.
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 sent an enormous string, (> 64*1024 bytes) through the scanner. This string contained no newlines.
Here's a repro case, plus a workaround, in a golang playground:
https://play.golang.org/p/VzBG989NJtz
What did you expect to see?
In a situation where the length of the data ScanLines searches exceeds the max token size, I'd expect either an error or for ScanLines just to return what it has.
What did you see instead?
ScanLines just hangs, I think because it loops forever, returning 0, nil, nil even when it can't get any more data because the token is already maxed out.
I was able to work around this by providing the scanner with a modified ScanLines function that just returns what it has when the data provided is the max token size, even if it hasn't reached a newline. I'm not really sure what the right default functionality should be (error vs returning what it has) but I know that I was not expecting it to hang like this.
I'd be happy to write a patch if we can agree on what would be the most intuitive/appropriate default.
Thanks so much!!
The text was updated successfully, but these errors were encountered: