From c572383bda78534ec4fa41939e0a0db8531887fe Mon Sep 17 00:00:00 2001 From: Forrin Date: Fri, 14 Jun 2024 12:55:58 -0500 Subject: [PATCH] Attestation Verification - Buffer Fix (#9198) * swap scanner to readline for attestations * replace readLine with readBytes --- pkg/cmd/attestation/verification/attestation.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/cmd/attestation/verification/attestation.go b/pkg/cmd/attestation/verification/attestation.go index 0b6499ece..52a8ff025 100644 --- a/pkg/cmd/attestation/verification/attestation.go +++ b/pkg/cmd/attestation/verification/attestation.go @@ -73,21 +73,21 @@ func loadBundlesFromJSONLinesFile(path string) ([]*api.Attestation, error) { attestations := []*api.Attestation{} - scanner := bufio.NewScanner(file) - for scanner.Scan() { - b := scanner.Bytes() + reader := bufio.NewReader(file) + + var line []byte + line, err = reader.ReadBytes('\n') + for err == nil { var bundle bundle.ProtobufBundle bundle.Bundle = new(protobundle.Bundle) - err = bundle.UnmarshalJSON(b) + err = bundle.UnmarshalJSON(line) if err != nil { return nil, fmt.Errorf("failed to unmarshal bundle from JSON: %v", err) } a := api.Attestation{Bundle: &bundle} attestations = append(attestations, &a) - } - if err := scanner.Err(); err != nil { - return nil, err + line, err = reader.ReadBytes('\n') } return attestations, nil