Skip to content

Commit

Permalink
fix(shwap): io.ReadFull for read helpers (#3696)
Browse files Browse the repository at this point in the history
* Gracefully handles case when `Read` reads enough data and returns io.EOF
  * Currently, the code fails in such a case.
* Ensures we catch EOF as an UnexepectedEOF when not enough data given.
  • Loading branch information
Wondertan authored Aug 28, 2024
1 parent e93e63f commit ed82a2e
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion share/shwap/eds_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func EdsIDFromBinary(data []byte) (EdsID, error) {
// ReadFrom reads the binary form of EdsID from the provided reader.
func (eid *EdsID) ReadFrom(r io.Reader) (int64, error) {
data := make([]byte, EdsIDSize)
n, err := r.Read(data)
n, err := io.ReadFull(r, data)
if err != nil {
return int64(n), err
}
Expand Down
2 changes: 1 addition & 1 deletion share/shwap/row_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func RowIDFromBinary(data []byte) (RowID, error) {

func (rid *RowID) ReadFrom(r io.Reader) (int64, error) {
data := make([]byte, RowIDSize)
n, err := r.Read(data)
n, err := io.ReadFull(r, data)
if err != nil {
return int64(n), err
}
Expand Down
2 changes: 1 addition & 1 deletion share/shwap/row_namespace_data_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func RowNamespaceDataIDFromBinary(data []byte) (RowNamespaceDataID, error) {
// ReadFrom reads the binary form of RowNamespaceDataID from the provided reader.
func (s *RowNamespaceDataID) ReadFrom(r io.Reader) (int64, error) {
data := make([]byte, RowNamespaceDataIDSize)
n, err := r.Read(data)
n, err := io.ReadFull(r, data)
if err != nil {
return int64(n), err
}
Expand Down
2 changes: 1 addition & 1 deletion share/shwap/sample_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func SampleIDFromBinary(data []byte) (SampleID, error) {
// ReadFrom reads the binary form of SampleID from the provided reader.
func (sid *SampleID) ReadFrom(r io.Reader) (int64, error) {
data := make([]byte, SampleIDSize)
n, err := r.Read(data)
n, err := io.ReadFull(r, data)
if err != nil {
return int64(n), err
}
Expand Down

0 comments on commit ed82a2e

Please sign in to comment.