internal/format: don't generate and reject empty lines in recipient bodies

Detected by https://github.com/str4d/rage/runs/532262359 and by go-fuzz.
This commit is contained in:
Filippo Valsorda
2020-03-25 00:25:17 -04:00
parent 35e582514d
commit f54bb8daab
4 changed files with 66 additions and 0 deletions

View File

@@ -60,6 +60,9 @@ func (r *Recipient) Marshal(w io.Writer) error {
if _, err := io.WriteString(w, "\n"); err != nil {
return err
}
if len(r.Body) == 0 {
return nil
}
ww := base64.NewEncoder(b64, &newlineWriter{dst: w})
if _, err := ww.Write(r.Body); err != nil {
return err
@@ -160,6 +163,9 @@ func Parse(input io.Reader) (*Header, io.Reader, error) {
if len(b) > bytesPerLine {
return nil, nil, errorf("malformed body line %q: too long", line)
}
if len(b) == 0 {
return nil, nil, errorf("malformed body line %q: line is empty", line)
}
r.Body = append(r.Body, b...)
if len(b) < bytesPerLine {
// Only the last line of a body can be short.