From 39aa5acc5b13632714248b22913d7ad1337c916c Mon Sep 17 00:00:00 2001 From: Ian Shim <100327837+ian-shim@users.noreply.github.com> Date: Mon, 18 Mar 2024 13:34:15 -0700 Subject: [PATCH] Check unexpected error and return when decoding chunks (#359) --- node/store.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/node/store.go b/node/store.go index 8ab33a8f4f..87d3210039 100644 --- a/node/store.go +++ b/node/store.go @@ -5,6 +5,7 @@ import ( "context" "encoding/binary" "errors" + "io" "time" "github.com/Layr-Labs/eigenda/api/grpc/node" @@ -361,15 +362,24 @@ func decodeChunks(data []byte) ([][]byte, error) { for { var length uint64 - if err := binary.Read(buf, binary.LittleEndian, &length); err != nil { + err := binary.Read(buf, binary.LittleEndian, &length) + if errors.Is(err, io.EOF) { break } + if err != nil { + return nil, err + } + chunk := make([]byte, length) - if _, err := buf.Read(chunk); err != nil { + _, err = buf.Read(chunk) + if errors.Is(err, io.EOF) { break } - chunks = append(chunks, chunk) + if err != nil { + return nil, err + } + chunks = append(chunks, chunk) if buf.Len() < 8 { break }