]> Cypherpunks repositories - gostls13.git/commitdiff
encoding/base32, encoding/base64: document Decode to short buffer
authorIan Lance Taylor <iant@golang.org>
Thu, 22 Aug 2024 20:47:13 +0000 (13:47 -0700)
committerGopher Robot <gobot@golang.org>
Fri, 30 Aug 2024 19:38:50 +0000 (19:38 +0000)
Document that if one of the Decode methods in these packages is given
a short buffer, it panics.

Fixes #69024

Change-Id: I1c0e4c74274965c1cfa0422cc8f86af4fefb1d00
Reviewed-on: https://go-review.googlesource.com/c/go/+/607499
Auto-Submit: Ian Lance Taylor <iant@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
src/encoding/base32/base32.go
src/encoding/base64/base64.go

index 9e988ef39b4f4dfcff2b3690c7044a5dbfdd0828..66f24e98a6604d12843f4c926a2176175219152a 100644 (file)
@@ -387,7 +387,8 @@ func (enc *Encoding) decode(dst, src []byte) (n int, end bool, err error) {
 
 // Decode decodes src using the encoding enc. It writes at most
 // [Encoding.DecodedLen](len(src)) bytes to dst and returns the number of bytes
-// written. If src contains invalid base32 data, it will return the
+// written. The caller must ensure that dst is large enough to hold all
+// the decoded data. If src contains invalid base32 data, it will return the
 // number of bytes successfully written and [CorruptInputError].
 // Newline characters (\r and \n) are ignored.
 func (enc *Encoding) Decode(dst, src []byte) (n int, err error) {
index 87f45863bd7b4dcb2a5cafa9468e1f3f463ff702..7f0fa2de78e6bf6075546590c9e35d90f72b4641 100644 (file)
@@ -508,7 +508,8 @@ func (d *decoder) Read(p []byte) (n int, err error) {
 
 // Decode decodes src using the encoding enc. It writes at most
 // [Encoding.DecodedLen](len(src)) bytes to dst and returns the number of bytes
-// written. If src contains invalid base64 data, it will return the
+// written. The caller must ensure that dst is large enough to hold all
+// the decoded data. If src contains invalid base64 data, it will return the
 // number of bytes successfully written and [CorruptInputError].
 // New line characters (\r and \n) are ignored.
 func (enc *Encoding) Decode(dst, src []byte) (n int, err error) {