Skip to content

Commit

Permalink
Remove gb2312 encoding as it can crash the program
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
brunnre8 committed May 14, 2020
1 parent c512562 commit 0452e4e
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 8 deletions.
4 changes: 1 addition & 3 deletions charset/charset.go
Expand Up @@ -13,7 +13,6 @@ import (
"golang.org/x/text/encoding"
"golang.org/x/text/encoding/charmap"
"golang.org/x/text/encoding/ianaindex"
"golang.org/x/text/encoding/simplifiedchinese"
)

// Quirks table for charsets not handled by ianaindex
Expand All @@ -33,8 +32,7 @@ var charsets = map[string]encoding.Encoding{
"cp367": encoding.Nop,
"ascii": encoding.Nop, // non-standard

"ansi_x3.110-1983": charmap.ISO8859_1, // see RFC 1345 page 62, mostly superset of ISO 8859-1
"gb2312": simplifiedchinese.GBK, // GBK is a superset of HZGB2312
"ansi_x3.110-1983": charmap.ISO8859_1, // see RFC 1345 page 62, mostly superset of ISO 8859-1
"cp1250": charmap.Windows1250,
"cp1251": charmap.Windows1251,
"cp1252": charmap.Windows1252,
Expand Down
5 changes: 0 additions & 5 deletions charset/charset_test.go
Expand Up @@ -45,11 +45,6 @@ var testCharsets = []struct {
charset: "idontexist",
encoded: []byte{42},
},
{
charset: "gb2312",
encoded: []byte{178, 226, 202, 212},
decoded: "测试",
},
}

func TestCharsetReader(t *testing.T) {
Expand Down

0 comments on commit 0452e4e

Please sign in to comment.