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/base64: Decode shouldn't panic when destination buffer is insufficient #63278

Closed
RodionGork opened this issue Sep 28, 2023 · 3 comments

Comments

@RodionGork
Copy link

RodionGork commented Sep 28, 2023

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

1.21

What operating system and processor architecture are you using (go env)?

ubuntu 22.04 on amd64

What did you do?

base64.StdEncoding.Decode is called with the destination buffer of insufficient size

https://go.dev/play/p/8mGzeMnqg5e

What did you expect to see?

either of two seems acceptable:

  • destination buffer is filled up to its capacity, remaining decoded data are discarded
  • specific error is returned (as the method signature has second value for error)

What did you see instead?

panic: runtime error: index out of range [2] with length 1

which is not only harmful but also misleading as the size of destination buffer is larger than 1

Note

This seemingly existed at least since 1.18 and was already reported but failed to gain attention and was closed after confused discussion: #54532

@seankhliao
Copy link
Member

see #58391

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Sep 28, 2023
@RodionGork
Copy link
Author

thanks but no idea "see what", sorry

library methods shouldn't panic and referred issue doesn't explain why they should

@ianlancetaylor
Copy link
Contributor

We have decided that in the Go standard library functions are permitted to panic if the input arguments fail their preconditions. For example, functions in the Go standard library do not routinely check whether they have been passed a nil pointer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants