diff --git a/src/mime/encodedword.go b/src/mime/encodedword.go index dffcdef053..158feaad4f 100644 --- a/src/mime/encodedword.go +++ b/src/mime/encodedword.go @@ -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 { diff --git a/src/mime/encodedword_test.go b/src/mime/encodedword_test.go index ff79796042..b63fe043ed 100644 --- a/src/mime/encodedword_test.go +++ b/src/mime/encodedword_test.go @@ -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 {