armor,internal/format: restore CCTV fuzz seed corpora

Reported by Joe Doyle of Trail of Bits.
This commit is contained in:
Filippo Valsorda
2026-08-29 19:30:10 +02:00
parent 6424047654
commit e8d1b2f216
2 changed files with 16 additions and 8 deletions
+9 -4
View File
@@ -12,12 +12,12 @@ import (
"encoding/pem"
"fmt"
"io"
"io/fs"
"log"
"os"
"path/filepath"
"strings"
"testing"
agetest "c2sp.org/CCTV/age"
"filippo.io/age"
"filippo.io/age/armor"
"filippo.io/age/internal/format"
@@ -134,12 +134,13 @@ func testArmor(t *testing.T, size int) {
}
func FuzzMalleability(f *testing.F) {
tests, err := filepath.Glob("../testdata/testkit/*")
tests, err := fs.ReadDir(agetest.Vectors, ".")
if err != nil {
f.Fatal(err)
}
seeds := 0
for _, test := range tests {
contents, err := os.ReadFile(test)
contents, err := fs.ReadFile(agetest.Vectors, test.Name())
if err != nil {
f.Fatal(err)
}
@@ -149,8 +150,12 @@ func FuzzMalleability(f *testing.F) {
}
if bytes.Contains(header, []byte("armored: yes")) {
f.Add(contents)
seeds++
}
}
if seeds == 0 {
f.Fatal("no armored test vectors")
}
f.Fuzz(func(t *testing.T, data []byte) {
r := armor.NewReader(bytes.NewReader(data))
content, err := io.ReadAll(r)
+7 -4
View File
@@ -11,11 +11,11 @@ import (
"bytes"
"errors"
"io"
"os"
"path/filepath"
"io/fs"
"strings"
"testing"
agetest "c2sp.org/CCTV/age"
"filippo.io/age/internal/format"
)
@@ -159,12 +159,12 @@ func TestParseLimits(t *testing.T) {
}
func FuzzMalleability(f *testing.F) {
tests, err := filepath.Glob("../../testdata/testkit/*")
tests, err := fs.ReadDir(agetest.Vectors, ".")
if err != nil {
f.Fatal(err)
}
for _, test := range tests {
contents, err := os.ReadFile(test)
contents, err := fs.ReadFile(agetest.Vectors, test.Name())
if err != nil {
f.Fatal(err)
}
@@ -174,6 +174,9 @@ func FuzzMalleability(f *testing.F) {
}
f.Add(contents)
}
if len(tests) == 0 {
f.Fatal("no test vectors")
}
f.Fuzz(func(t *testing.T, data []byte) {
h, payload, err := format.Parse(bytes.NewReader(data))
if err != nil {