Skip to content

Commit

Permalink
Check unexpected error and return when decoding chunks (#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-shim authored Mar 18, 2024
1 parent a5f9e24 commit 39aa5ac
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions node/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"encoding/binary"
"errors"
"io"
"time"

"github.com/Layr-Labs/eigenda/api/grpc/node"
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 39aa5ac

Please sign in to comment.