diff options
author | Frédéric Guillot <fred@miniflux.net> | 2018-11-24 12:17:00 -0800 |
---|---|---|
committer | Frédéric Guillot <fred@miniflux.net> | 2018-11-24 12:17:00 -0800 |
commit | f3bff76aa1739ad37c225e578e7e64be6fea46d7 (patch) | |
tree | dff65965d66fb8cda57a46a838dafdc8e69247dc /http | |
parent | 70be08eaf856f3a1bb724a160c44e515e07b2294 (diff) |
Make sure slice is not out of range when reading XML prolog
Diffstat (limited to 'http')
-rw-r--r-- | http/client/response.go | 7 | ||||
-rw-r--r-- | http/client/response_test.go | 1 | ||||
-rw-r--r-- | http/client/testdata/smallfile.xml | 1 |
3 files changed, 8 insertions, 1 deletions
diff --git a/http/client/response.go b/http/client/response.go index 8fcaa26..340fa07 100644 --- a/http/client/response.go +++ b/http/client/response.go @@ -84,7 +84,12 @@ func (r *Response) EnsureUnicodeBody() (err error) { // We ignore documents with encoding specified in XML prolog. // This is going to be handled by the XML parser. - if xmlEncodingRegex.Match(buffer[0:1024]) { + length := 1024 + if len(buffer) < 1024 { + length = len(buffer) + } + + if xmlEncodingRegex.Match(buffer[0:length]) { return } } diff --git a/http/client/response_test.go b/http/client/response_test.go index 7c024af..5b23d5c 100644 --- a/http/client/response_test.go +++ b/http/client/response_test.go @@ -123,6 +123,7 @@ func TestEnsureUnicodeWithHTMLDocuments(t *testing.T) { {"rdf_utf8.xml", "application/rss+xml; charset=utf-8", true}, {"charset-content-type-xml-iso88591.xml", "application/rss+xml; charset=ISO-8859-1", false}, {"windows_1251.xml", "text/xml", false}, + {"smallfile.xml", "text/xml; charset=utf-8", true}, } for _, tc := range unicodeTestCases { diff --git a/http/client/testdata/smallfile.xml b/http/client/testdata/smallfile.xml new file mode 100644 index 0000000..780ef24 --- /dev/null +++ b/http/client/testdata/smallfile.xml @@ -0,0 +1 @@ +<?xml version="1.0"?>
\ No newline at end of file |