aboutsummaryrefslogtreecommitdiff
path: root/src/encoding
diff options
context:
space:
mode:
Diffstat (limited to 'src/encoding')
-rw-r--r--src/encoding/base32/base32.go3
-rw-r--r--src/encoding/base32/base32_test.go52
2 files changed, 55 insertions, 0 deletions
diff --git a/src/encoding/base32/base32.go b/src/encoding/base32/base32.go
index 5f3af4c8bb..fa6e42e26c 100644
--- a/src/encoding/base32/base32.go
+++ b/src/encoding/base32/base32.go
@@ -445,6 +445,9 @@ func (d *decoder) Read(p []byte) (n int, err error) {
if d.nbuf < min {
return 0, d.err
}
+ if nn > 0 && d.end {
+ return 0, CorruptInputError(0)
+ }
// Decode chunk into p, or d.out and then p if p is too small.
var nr int
diff --git a/src/encoding/base32/base32_test.go b/src/encoding/base32/base32_test.go
index dbd2b613b4..323d04e68b 100644
--- a/src/encoding/base32/base32_test.go
+++ b/src/encoding/base32/base32_test.go
@@ -627,6 +627,58 @@ func TestBufferedDecodingSameError(t *testing.T) {
}
}
+func TestBufferedDecodingPadding(t *testing.T) {
+ testcases := []struct {
+ chunks []string
+ expectedError string
+ }{
+ {[]string{
+ "I4======",
+ "==",
+ }, "unexpected EOF"},
+
+ {[]string{
+ "I4======N4======",
+ }, "illegal base32 data at input byte 2"},
+
+ {[]string{
+ "I4======",
+ "N4======",
+ }, "illegal base32 data at input byte 0"},
+
+ {[]string{
+ "I4======",
+ "========",
+ }, "illegal base32 data at input byte 0"},
+
+ {[]string{
+ "I4I4I4I4",
+ "I4======",
+ "I4======",
+ }, "illegal base32 data at input byte 0"},
+ }
+
+ for _, testcase := range testcases {
+ testcase := testcase
+ pr, pw := io.Pipe()
+ go func() {
+ for _, chunk := range testcase.chunks {
+ _, _ = pw.Write([]byte(chunk))
+ }
+ _ = pw.Close()
+ }()
+
+ decoder := NewDecoder(StdEncoding, pr)
+ _, err := io.ReadAll(decoder)
+
+ if err == nil && len(testcase.expectedError) != 0 {
+ t.Errorf("case %q: got nil error, want %v", testcase.chunks, testcase.expectedError)
+ } else if err.Error() != testcase.expectedError {
+ t.Errorf("case %q: got %v, want %v", testcase.chunks, err, testcase.expectedError)
+ }
+ }
+}
+
func TestEncodedDecodedLen(t *testing.T) {
type test struct {
in int