mirror of https://github.com/miniflux/v2.git
Make sure slice is not out of range when reading XML prolog
This commit is contained in:
parent
70be08eaf8
commit
f3bff76aa1
|
@ -84,7 +84,12 @@ func (r *Response) EnsureUnicodeBody() (err error) {
|
||||||
|
|
||||||
// We ignore documents with encoding specified in XML prolog.
|
// We ignore documents with encoding specified in XML prolog.
|
||||||
// This is going to be handled by the XML parser.
|
// 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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,6 +123,7 @@ func TestEnsureUnicodeWithHTMLDocuments(t *testing.T) {
|
||||||
{"rdf_utf8.xml", "application/rss+xml; charset=utf-8", true},
|
{"rdf_utf8.xml", "application/rss+xml; charset=utf-8", true},
|
||||||
{"charset-content-type-xml-iso88591.xml", "application/rss+xml; charset=ISO-8859-1", false},
|
{"charset-content-type-xml-iso88591.xml", "application/rss+xml; charset=ISO-8859-1", false},
|
||||||
{"windows_1251.xml", "text/xml", false},
|
{"windows_1251.xml", "text/xml", false},
|
||||||
|
{"smallfile.xml", "text/xml; charset=utf-8", true},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range unicodeTestCases {
|
for _, tc := range unicodeTestCases {
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
<?xml version="1.0"?>
|
Loading…
Reference in New Issue