mirror of
https://github.com/FiloSottile/age.git
synced 2026-09-04 07:07:16 +00:00
armor,internal/format: restore CCTV fuzz seed corpora
Reported by Joe Doyle of Trail of Bits.
This commit is contained in:
+9
-4
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user