Commit 5de5dd8d authored by Hiroshi Ioka's avatar Hiroshi Ioka Committed by Brad Fitzpatrick

mime: fix panic parsing 'encoded-word'

https://go-review.googlesource.com/37812 says fix panic parsing.
Actually, it doesn't. so fix it.

Fixes #19416

Change-Id: Ie0c4241f10e5ebcbac20e184c2a7b13b22632eab
Reviewed-on: https://go-review.googlesource.com/37912Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 0020b8a2
......@@ -208,15 +208,15 @@ func (d *WordDecoder) Decode(word string) (string, error) {
if len(charset) == 0 {
return "", errInvalidWord
}
if len(word) <= split+3 {
return "", errInvalidWord
}
encoding := word[split+1]
// the field after split must only be one byte
if word[split+2] != '?' {
return "", errInvalidWord
}
text := word[split+3:]
if len(text) == 0 {
return "", errInvalidWord
}
content, err := decode(encoding, text)
if err != nil {
......
......@@ -90,6 +90,7 @@ func TestDecodeWord(t *testing.T) {
{"=?UTF-8?A?A?=", "", true},
{"=????=", "", true},
{"=?UTF-8?Q??=", "", true},
{"=?UTF-8???=", "", true},
}
for _, test := range tests {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment