-
Notifications
You must be signed in to change notification settings - Fork 18k
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/base32: cannot decode nonpadded encodings #20854
Comments
@bradfitz: Sure. It was a mistake to not modify Decode to allow non- or custom-padding. Do you think that the message needs to be padded with the same character as specified by Update: In the patch linked below (I'll submit a CL later) the padding for decoding must be set with |
Expects the padding of the input to be the same as set by Encoding.WithPadding() Fixes golang#20854
How would you know what padding character to strip for "padded" encoded
strings that don't have any padding? Zero padding characters is allowable
if padding is not needed.
…On Fri, Jun 30, 2017 at 12:49 AM, Gustav Westling ***@***.***> wrote:
@bradfitz <https://github.com/bradfitz>: Sure. It was a mistake to not
modify Decode to allow non- or custom-padding.
Do you think that the message needs to be padded with the same character
as specified by WithPadding(), or should we allow any type of padding (or
none at all)? I'd pick the latter option, but it might not be as safe.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#20854 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AFYNAXScuZoBdqvjHMdPZruyc_9uOaZpks5sJKiOgaJpZM4OJ0mj>
.
|
@bobjalex: The case where the input is a valid base32 encoded message (with = as padding), but no padding is necessary is already covered in the Decode() method shipped in the existing go1.9 betas. (Example: In the other case you could look for a character that is not a part of the base32 alphabet, and infer that the first char like that is the one that is the padding char. |
Expects the padding of the input to be the same as set by Encoding.WithPadding() Fixes golang#20854
Expects the padding of the input to be the same as set by Encoding.WithPadding() Fixes golang#20854 Signed-off-by: Gustav Westling <gustav@westling.xyz>
A downside to inferring the padding char is that it would somewhat limit the ability to detect corruption. RFC 4648 says A 33-character subset of US-ASCII is used, enabling 5 bits to be That would mean that any character outside of the 33 allowable would indicate corruption. The fact that encoding/base32 allows a "special processing" character other than "=" doesn't matter, since the set of allowable characters is still 33. |
CL https://golang.org/cl/47341 mentions this issue. |
CL 47341 added support for decoding non-padded messages. But DecodedLen still returned a multiple of 5 for messages without a padding, even though it is possible to calculate the len exactly when using NoPadding. This change makes DecodedLen return the exact number of bytes that will be written. A change to the decoding logic is also made so that it can handle this case. DecodedLen now has the same behaviour as DecodedLen in encoding/base64. Fixes #20854 Change-Id: I729e0b1c0946c866fb675c854f835f366dd4b5a4 Reviewed-on: https://go-review.googlesource.com/47710 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Change https://golang.org/cl/47750 mentions this issue: |
Change https://golang.org/cl/47710 mentions this issue: |
decode with pad "=" or "A" get illegal base32 data at input byte |
@biexiang if you believe you have found a bug, please open a new issue. Don't forget to include a reproducer. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?What operating system and processor architecture are you using (
go env
)?What did you do?
Tried to decode a base32 nonpadded encoding.
If possible, provide a recipe for reproducing the error.
The attached little program demonstrates the bug:
base32_bug.go.txt
What did you expect to see?
A proper decoding.
What did you see instead?
The error: decoding not padded: illegal base32 data at input byte 8
Even though WithPadding(base32.NoPadding) was specified.
The text was updated successfully, but these errors were encountered: