When a record header is correctly read, but no data follows (io.ReadFull line 86 returns io.EOF), Decode will return io.EOF instead of io.ErrUnexpectedEOF (which would signal a partial broken record instead of no record).
|
// Decode reads a binary record from an io.Reader and fills the provided |
|
// *Record struct. |
|
// |
|
// It uses a pointer over a *Record struct instead of returning a *Record |
|
// struct for performance reason: it tries to reuse the already allocated Data |
|
// field. |
|
func Decode(rd io.Reader, rec *Record) error { |
|
var hdr Header |
|
if err := binary.Read(rd, binary.BigEndian, &hdr); err != nil { |
|
return err |
|
} |
|
|
|
rec.Time = time.Unix(0, int64(hdr.Time)) |
|
rec.Fd = int(hdr.Fd) |
|
rec.Size = int(hdr.Size) |
|
|
|
// Reuse the data slice |
|
if cap(rec.Data) >= int(rec.Size) { |
|
rec.Data = rec.Data[:rec.Size] |
|
} else { |
|
rec.Data = make([]byte, rec.Size) |
|
} |
|
|
|
if _, err := io.ReadFull(rd, rec.Data); err != nil { |
|
return err |
|
} |
|
|
|
return nil |
|
} |
io.ErrUnexpectedEOF would signal a problem with the file instead of just hiding the issue to the caller.
When a record header is correctly read, but no data follows (
io.ReadFullline 86 returnsio.EOF),Decodewill returnio.EOFinstead ofio.ErrUnexpectedEOF(which would signal a partial broken record instead of no record).sshproxy/pkg/record/record.go
Lines 63 to 91 in 7239859
io.ErrUnexpectedEOFwould signal a problem with the file instead of just hiding the issue to the caller.