Skip to content

Commit 7b0fdd1

Browse files
ianlancetaylorgopherbot
authored andcommitted
encoding/base32, encoding/base64: document Decode to short buffer
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 <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> Reviewed-by: Damien Neil <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent d0baac3 commit 7b0fdd1

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/encoding/base32/base32.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,8 @@ func (enc *Encoding) decode(dst, src []byte) (n int, end bool, err error) {
387387

388388
// Decode decodes src using the encoding enc. It writes at most
389389
// [Encoding.DecodedLen](len(src)) bytes to dst and returns the number of bytes
390-
// written. If src contains invalid base32 data, it will return the
390+
// written. The caller must ensure that dst is large enough to hold all
391+
// the decoded data. If src contains invalid base32 data, it will return the
391392
// number of bytes successfully written and [CorruptInputError].
392393
// Newline characters (\r and \n) are ignored.
393394
func (enc *Encoding) Decode(dst, src []byte) (n int, err error) {

src/encoding/base64/base64.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,8 @@ func (d *decoder) Read(p []byte) (n int, err error) {
508508

509509
// Decode decodes src using the encoding enc. It writes at most
510510
// [Encoding.DecodedLen](len(src)) bytes to dst and returns the number of bytes
511-
// written. If src contains invalid base64 data, it will return the
511+
// written. The caller must ensure that dst is large enough to hold all
512+
// the decoded data. If src contains invalid base64 data, it will return the
512513
// number of bytes successfully written and [CorruptInputError].
513514
// New line characters (\r and \n) are ignored.
514515
func (enc *Encoding) Decode(dst, src []byte) (n int, err error) {

0 commit comments

Comments
 (0)