Merge: - crash after filter update if its data is too small

* commit '319cc848bd9f62f926e20de10092271536eb5786':
  - crash after filter update if its data is too small
This commit is contained in:
Simon Zolin 2019-09-27 13:25:41 +03:00
commit 6a65c79a03
1 changed files with 8 additions and 2 deletions

View File

@ -370,11 +370,17 @@ func (filter *filter) update() (bool, error) {
return false, nil
}
if !isPrintableText(body[:4096]) {
var firstChunk []byte
if len(body) <= 4096 {
firstChunk = body
} else {
firstChunk = body[:4096]
}
if !isPrintableText(firstChunk) {
return false, fmt.Errorf("Data contains non-printable characters")
}
s := strings.ToLower(string(body[:4096]))
s := strings.ToLower(string(firstChunk))
if strings.Index(s, "<html") >= 0 ||
strings.Index(s, "<!doctype") >= 0 {
return false, fmt.Errorf("Data is HTML, not plain text")