The point is that the Transform() returns invalid nSrc.
What did you expect to see?
The Read() should return transform.errInconsistentByteCount because the Transform() returns invalid nSrc(nSrc > len(src)). The code comment says
errInconsistentByteCount means that Transform returned success (nil error) but also returned nSrc inconsistent with the src argument.
The error is suitable for this case.
What did you see instead?
It panics with slice bounds out of range.
panic: runtime error: slice bounds out of range
goroutine 1 [running]:
golang.org/x/text/transform.(*Reader).Read(0xc00003c700, 0xc00003c6dd, 0x3, 0x3, 0x0, 0xe0c843aa8a3c7960, 0xc00003c6f0)
/home/yuki/.local/src/golang.org/x/text/transform/transform.go:166 +0x622
main.main()
/home/yuki/.local/src/golang.org/x/text/transform/test/main.go:17 +0x20e
exit status 2
The stack trace points the internal of the library, not the implementation of Transformer. This behavior makes difficult to debug because the real problem is in the use of transform package, but the error doesn't suggest that.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
The point is that the
Transform()
returns invalidnSrc
.What did you expect to see?
The
Read()
should returntransform.errInconsistentByteCount
because theTransform()
returns invalidnSrc
(nSrc > len(src)
). The code comment saysThe error is suitable for this case.
What did you see instead?
It panics with
slice bounds out of range
.The stack trace points the internal of the library, not the implementation of Transformer. This behavior makes difficult to debug because the real problem is in the use of transform package, but the error doesn't suggest that.