Skip to content

Commit

Permalink
fix: nil check BatchHeader when reading JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdecaf committed Apr 26, 2024
1 parent 385aea0 commit ee5c9fa
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
8 changes: 5 additions & 3 deletions file.go
Expand Up @@ -361,9 +361,10 @@ func (f *File) setBatchesFromJSON(bs []byte) error {
}
// Add new batches to file
for i := range batches.Batches {
if batches.Batches[i] == nil {
if batches.Batches[i] == nil || batches.Batches[i].Header == nil {
continue
}

batch := *batches.Batches[i]
batch.SetID(batch.Header.ID)
batch.SetValidation(f.validateOpts)
Expand All @@ -390,11 +391,12 @@ func (f *File) setBatchesFromJSON(bs []byte) error {

// Add new iatBatches to file
for i := range iatBatches.IATBatches {
if len(iatBatches.IATBatches) == 0 {
iatBatch := iatBatches.IATBatches[i]

if iatBatch.Header == nil {
continue
}

iatBatch := iatBatches.IATBatches[i]
iatBatch.ID = iatBatch.Header.ID
iatBatch.SetValidation(f.validateOpts)

Expand Down
2 changes: 0 additions & 2 deletions server/test/unordered_batches/unordered_batch_test.go
Expand Up @@ -52,7 +52,5 @@ func TestUnorderedBatches(t *testing.T) {
server.Handler.ServeHTTP(w, req)
w.Flush()

fmt.Printf("\n%s\n", w.Body.String())

require.Equal(t, http.StatusOK, w.Code)
}
2 changes: 2 additions & 0 deletions test/fuzz/testdata/fuzz/FuzzReaderWriterJSON/e499142d79b69666
@@ -0,0 +1,2 @@
go test fuzz v1
string("{\"BAtChes\":[{\"BAtChHeAder\":null}]}")
@@ -0,0 +1,2 @@
go test fuzz v1
string("{\"iatBatches\":[{\"IATBatchHeader\":null}]}")

0 comments on commit ee5c9fa

Please sign in to comment.