Skip to content

Commit

Permalink
fix: readByte returns errors on unexpected EOF (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
brianshih1 authored Apr 23, 2024
1 parent 141e857 commit 84f9b10
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions decoder_native_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ func TestDecoder_BoolInvalidSchema(t *testing.T) {
assert.Error(t, err)
}

func TestDecoder_BoolEof(t *testing.T) {
defer ConfigTeardown()

data := []byte{0x4}
schema := `{"fields":[{"name":"B","type":{"type":"int"}},{"name":"A","type":{"type":"boolean"}}],"name":"foo","type":"record"}`
dec, err := avro.NewDecoder(schema, bytes.NewReader(data))
require.NoError(t, err)

var b any
err = dec.Decode(&b)

assert.Error(t, err)
}

func TestDecoder_Int(t *testing.T) {
defer ConfigTeardown()

Expand Down
1 change: 1 addition & 0 deletions reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func (r *Reader) loadMore() bool {
func (r *Reader) readByte() byte {
if r.head == r.tail {
if !r.loadMore() {
r.Error = io.ErrUnexpectedEOF
return 0
}
}
Expand Down

0 comments on commit 84f9b10

Please sign in to comment.