From 319cc848bd9f62f926e20de10092271536eb5786 Mon Sep 17 00:00:00 2001 From: Simon Zolin Date: Fri, 27 Sep 2019 13:22:08 +0300 Subject: [PATCH] - crash after filter update if its data is too small --- home/filter.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/home/filter.go b/home/filter.go index 73c4d9a0..8bf902a2 100644 --- a/home/filter.go +++ b/home/filter.go @@ -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, "= 0 || strings.Index(s, "= 0 { return false, fmt.Errorf("Data is HTML, not plain text")