Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic on all zero stream #592

Open
bytescreator opened this issue Sep 5, 2024 · 0 comments
Open

Panic on all zero stream #592

bytescreator opened this issue Sep 5, 2024 · 0 comments

Comments

@bytescreator
Copy link

bytescreator commented Sep 5, 2024

When a stream containing all zero bytes is decoded by capnp.Decoder, a message which contains a zero length segment causes message.Root to panic whilst reading the message. I don't know that this is intended behaviour so i reported just in case.

Possible cause is when Segment.root is called by Message.Root; Segment.root returns a zero value PointerList (due to out of bounds) which causes a panic in List.primitiveElem

Reproducing code

package main

import (
	"capnproto.org/go/capnp/v3"
)

type zeros struct{}

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

func main() {
	m, err := capnp.NewDecoder(zeros{}).Decode()
	if err != nil {
		panic(err)
	}

	m.Root()
}

panic

panic: list element out of bounds

goroutine 1 [running]:
capnproto.org/go/capnp/v3.List.primitiveElem({0x0, 0x0, 0x0, {0x0, 0x0}, 0x0, 0x0}, 0xc00011de20?, {0x0, 0x1})
        $GOPATH/pkg/mod/capnproto.org/go/capnp/[email protected]/list.go:190 +0x1a8
capnproto.org/go/capnp/v3.PointerList.primitiveElem(...)
        $GOPATH/pkg/mod/capnproto.org/go/capnp/[email protected]/list-gen.go:226
capnproto.org/go/capnp/v3.PointerList.At({0x0, 0x0, 0x0, {0x0, 0x0}, 0x0, 0x0}, 0xbfd445?)
        $GOPATH/pkg/mod/capnproto.org/go/capnp/[email protected]/list.go:356 +0xbf
capnproto.org/go/capnp/v3.(*Message).Root(0xc00007c080?)
        $GOPATH/pkg/mod/capnproto.org/go/capnp/[email protected]/message.go:202 +0xe8
main.main()
        $GOPATH/src/<REDACTED>/test.go:22 +0x3e
exit status 2

go.mod

module capnptest

go 1.22.2

require capnproto.org/go/capnp/v3 v3.0.1-alpha.2

require (
	github.com/colega/zeropool v0.0.0-20230505084239-6fb4a4f75381 // indirect
	golang.org/x/sync v0.7.0 // indirect
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant