Skip to content

Commit

Permalink
Merge pull request #599 from Semisol/add-zero-stream-test
Browse files Browse the repository at this point in the history
Add a test for all-zero stream decoding
  • Loading branch information
lthibault authored Jan 10, 2025
2 parents 567b3ac + 8b67008 commit b4bdc80
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,3 +622,23 @@ func TestCanResetArenaForRead(t *testing.T) {
_, err := msg.Reset(arena)
require.NoError(t, err)
}

type test_zero_stream struct{}

func (test_zero_stream) Read(b []byte) (int, error) {
for i := 0; i < len(b); i++ {
b[i] = 0
}
return len(b), nil
}

// TestZeroStream checks that an all-zero stream will fail to decode with an
// error, and not panic.
// See github.com/capnproto/go-capnp/issues/592
func TestZeroStream(t *testing.T) {
m, err := NewDecoder(test_zero_stream{}).Decode()
require.NoError(t, err)

_, err = m.Root()
assert.NotNil(t, err, "expected error decoding zero stream")
}

0 comments on commit b4bdc80

Please sign in to comment.