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

encoding/binary: Size panics when passed a nil pointer to a slice #60892

Closed
lmb opened this issue Jun 20, 2023 · 3 comments
Closed

encoding/binary: Size panics when passed a nil pointer to a slice #60892

lmb opened this issue Jun 20, 2023 · 3 comments
Labels
NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@lmb
Copy link
Contributor

lmb commented Jun 20, 2023

What version of Go are you using (go version)?

1.20

Does this issue reproduce with the latest release?

Yes.

What did you do?

Pass (*[]byte)(nil) to binary.Size.

https://go.dev/play/p/eKvs4FJHkxy

What did you expect to see?

The function should return -1.

What did you see instead?

The function panicked instead:

panic: reflect: call of reflect.Value.Type on zero Value

goroutine 1 [running]:
reflect.Value.typeSlow({0x0?, 0x0?, 0xc0000406c8?})
	/usr/local/go-faketime/src/reflect/value.go:2610 +0x12e
reflect.Value.Type(...)
	/usr/local/go-faketime/src/reflect/value.go:2605
encoding/binary.dataSize({0x0?, 0x0?, 0x60?})
	/usr/local/go-faketime/src/encoding/binary/binary.go:490 +0x17f
encoding/binary.Size({0x4873c0?, 0x0?})
	/usr/local/go-faketime/src/encoding/binary/binary.go:463 +0xb9
main.main()
	/tmp/sandbox3549274882/prog.go:11 +0x25
@gopherbot
Copy link

Change https://go.dev/cl/504575 mentions this issue: encoding/binary: on invalid type return -1 from Size

@bcmills bcmills added the NeedsFix The path to resolution is known, but the work has not been done. label Jun 20, 2023
@dmitshur dmitshur added this to the Go1.21 milestone Jun 21, 2023
@lmb
Copy link
Contributor Author

lmb commented Jul 4, 2023

Could this get a backport to v1.20?

@ianlancetaylor
Copy link
Contributor

We normally only backport serious bugs that have no workaround. This bug has a simple workaround, so it's not eligible for backporting.

bradfitz pushed a commit to tailscale/go that referenced this issue Jul 15, 2023
Size is defined as returning -1 if the type is not fixed-size.
Before this CL cases like Size((*[]int)(nil)) would crash.

Fixes golang#60892

Change-Id: Iee8e20a0aee24b542b78cb4160c3b2c5a3eb02c2
Reviewed-on: https://go-review.googlesource.com/c/go/+/504575
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants