mirror of
https://github.com/FiloSottile/age.git
synced 2026-01-03 10:55:14 +00:00
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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user