]> Cypherpunks repositories - gostls13.git/commitdiff
mime: fix panic parsing 'encoded-word'
authorHiroshi Ioka <hirochachacha@gmail.com>
Tue, 7 Mar 2017 23:11:33 +0000 (08:11 +0900)
committerBrad Fitzpatrick <bradfitz@golang.org>
Sun, 9 Apr 2017 19:03:00 +0000 (19:03 +0000)
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>

src/mime/encodedword.go
src/mime/encodedword_test.go

index dffcdef053cedab14b5bc23c12c50c6e63407401..158feaad4fd4a539ded8fc6c460b766b601be8de 100644 (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 {
index ff797960429271a58c27cbdd003b3527423079c2..b63fe043eda5efaa63d2e7bcffcb00674ab36401 100644 (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 {