1
0
mirror of https://github.com/golang/go synced 2024-09-30 03:14:28 -06:00

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/37912
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Hiroshi Ioka 2017-03-08 08:11:33 +09:00 committed by Brad Fitzpatrick
parent 0020b8a257
commit 5de5dd8d25
2 changed files with 4 additions and 3 deletions

View File

@ -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 {

View File

@ -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 {