Skip to content

Commit e1f8cd6

Browse files
committed
armor: reject empty lines in armored data
Caught by the new CCTV test vectors!
1 parent 77b0403 commit e1f8cd6

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

armor/armor.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ func (r *armoredReader) Read(p []byte) (int, error) {
140140
if string(line) == Footer {
141141
return 0, r.setErr(drainTrailing())
142142
}
143+
if len(line) == 0 {
144+
return 0, r.setErr(errors.New("empty line in armored data"))
145+
}
143146
if len(line) > format.ColumnsPerLine {
144147
return 0, r.setErr(errors.New("column limit exceeded"))
145148
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require (
1313

1414
// Test dependencies.
1515
require (
16-
c2sp.org/CCTV/age v0.0.0-20240306222714-3ec4d716e805
16+
c2sp.org/CCTV/age v0.0.0-20250426113718-46fad5b26cb2
1717
github.com/rogpeppe/go-internal v1.12.0
1818
golang.org/x/tools v0.22.0 // indirect
1919
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
c2sp.org/CCTV/age v0.0.0-20240306222714-3ec4d716e805 h1:u2qwJeEvnypw+OCPUHmoZE3IqwfuN5kgDfo5MLzpNM0=
2-
c2sp.org/CCTV/age v0.0.0-20240306222714-3ec4d716e805/go.mod h1:FomMrUJ2Lxt5jCLmZkG3FHa72zUprnhd3v/Z18Snm4w=
1+
c2sp.org/CCTV/age v0.0.0-20250426113718-46fad5b26cb2 h1:CgfUtBNKpcGa3dLCktwniIKTMkxlELJcvS+EQRlGeGs=
2+
c2sp.org/CCTV/age v0.0.0-20250426113718-46fad5b26cb2/go.mod h1:SrHC2C7r5GkDk8R+NFVzYy/sdj0Ypg9htaPXQq5Cqeo=
33
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
44
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
55
filippo.io/hpke v0.4.0 h1:p575VVQ6ted4pL+it6M00V/f2qTZITO0zgmdKCkd5+A=

testkit_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ package age_test
99

1010
import (
1111
"bytes"
12+
"compress/zlib"
1213
"crypto/sha256"
1314
"encoding/hex"
1415
"errors"
@@ -55,6 +56,7 @@ type vector struct {
5556
}
5657

5758
func parseVector(t *testing.T, test []byte) *vector {
59+
var z bool
5860
v := &vector{file: test}
5961
for {
6062
line, rest, ok := bytes.Cut(v.file, []byte("\n"))
@@ -105,12 +107,31 @@ func parseVector(t *testing.T, test []byte) *vector {
105107
v.identities = append(v.identities, i)
106108
case "armored":
107109
v.armored = true
110+
case "compressed":
111+
if value != "zlib" {
112+
t.Fatal("invalid test file: unknown compression:", value)
113+
}
114+
z = true
108115
case "comment":
109116
t.Log(value)
110117
default:
111118
t.Fatal("invalid test file: unknown header key:", key)
112119
}
113120
}
121+
if z {
122+
r, err := zlib.NewReader(bytes.NewReader(v.file))
123+
if err != nil {
124+
t.Fatal(err)
125+
}
126+
b, err := io.ReadAll(r)
127+
if err != nil {
128+
t.Fatal(err)
129+
}
130+
if err := r.Close(); err != nil {
131+
t.Fatal(err)
132+
}
133+
v.file = b
134+
}
114135
return v
115136
}
116137

0 commit comments

Comments
 (0)