-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
x/text: Problem with charset 'hz-gb-2312', program stuck in infinite loop and gets killed! #35118
Comments
Not sure if this is going to help in tracking down the issue or not but have a look at the following tests (just changing the value of
So it's not the odd number of tildes that's breaking it either, hope this helps! |
In that last case, shouldn't the decoder return an error? Since The simplifiedchinese transformer seems to be returning |
Aside: This sounds like the kind of bug fuzzing would catch. Might be worth writing a few fuzz functions for this repo. cc @yevgenypats |
Thanks @josharian , I'll look into this. |
Any news about this issue at all? |
Hi, I would like to give this one a shot. As mentioned, in this encoding '~' is an escape character which must be followed by another character, from RFC 1843: As far as I can tell, Transform() only returns The reason for the infinite loop is when the replacement character is inserted, the The reason for the different behaviour on the number of '~' characters is due to the size of the destination buffer. If this buffer is not big enough to store the replacement character, Transform() returns For example, []byte("~~~~~") requires 5 bytes for the destination buffer (1 byte each for the 2 pairs of '~' + 3 bytes for the replacement character). The incorrect So to summarise behaviour Perhaps an additional improvement in String() would be a sanity check if |
Change https://golang.org/cl/220460 mentions this issue: |
Upstream go's x/text/encoding package has a bug that makes the 'hz-gb-2312' encoding crash (golang/go#35118) This was reported to go-message in emersion#95 This commit removes the offending encoding so that go-message can't crash if people import the charset package. It should be reverted once the upstream package is fixed by the go developers.
Upstream go's x/text/encoding package has a bug that makes the 'hz-gb-2312' encoding crash (golang/go#35118) This was reported to go-message in emersion#95 This commit removes the offending encoding so that go-message can't crash if people import the charset package. It should be reverted once the upstream package is fixed by the go developers.
Upstream go's x/text/encoding package has a bug that makes the 'hz-gb-2312' encoding crash (golang/go#35118) This was reported to go-message in #95 This commit removes the offending encoding so that go-message can't crash if people import the charset package. It should be reverted once the upstream package is fixed by the go developers.
The upstream Go issue has been fixed [1]. [1]: golang/go#35118 References: #95
…finite loop If the final character in the source buffer is a single '~' escape character, size is not updated. The loop either doesn't make progress if size is zero, or size retains the value from a previous iteration which may return an incorrect source bytes consumed count. Count the single '~' as 1 byte consumed. Fixes golang/go#35118 Change-Id: I3eadf1b4cb632a7c4dc4255325b467a6907c10c0 Reviewed-on: https://go-review.googlesource.com/c/text/+/220460 Reviewed-by: Nigel Tao <[email protected]> Trust: Nigel Tao <[email protected]> Trust: Marcel van Lohuizen <[email protected]>
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?
https://play.golang.org/p/V5OAmSmE9-r
What did you expect to see?
For the program to exit normally.
What did you see instead?
Gets stuck in an infinite loop and gets killed. In playground you'll see: "Program exited: process took too long."
The culprit is the Tilde (~ or ascii=126) which if shows up at the end of a line, makes
decoder.Bytes(content)
get stuck in an infinite loop for this particular encoding.The text was updated successfully, but these errors were encountered: