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

fix base64 decode related builtin function #263

Merged
merged 4 commits into from
Mar 13, 2024

Conversation

ysugimoto
Copy link
Owner

Fixes #255

Fastly terminates null-byte on a decoded string in base64 decoding functions:

  • digest.base64_decode
  • digest.base64url_decode
  • digest.base64url_decode_nopad

Additionally, digest.base64url_decode_nopad also stops decoding when a padding sign (=) is found.
This PR follows Fastly behavior that describes the documentation.

Copy link
Collaborator

@richardmarshall richardmarshall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proper handling of null bytes in the decode output and ignoring decoding errors definitely gets us closer to matching Fastly's behavior but there's still one issue.

Invalid characters are skipped entirely when decoding, and do not contribute to the bits for the current byte being output. Decoding continues for subsequent data as if the invalid character were not present.

Since the go decoder stops processing the input on invalid characters they should first be removed from the input before passing to the decoder.

@ysugimoto
Copy link
Owner Author

I looked into Fastly documentation and improved base64-ed string dealing with corresponding functions.
Adding more edge test cases and be sure Faslty's actual behavior: https://fiddle.fastly.dev/fiddle/b2e84dcd

Copy link
Collaborator

@richardmarshall richardmarshall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good, just a couple questions on the diff.

Sorry for not getting to this sooner I briefly looked at it when you submitted it and didn't have time to do a real review and forgot to leave the notification marked as unread. Oops.

@richardmarshall
Copy link
Collaborator

LGTM

@ysugimoto ysugimoto merged commit 7ad2ed4 into main Mar 13, 2024
3 checks passed
@ysugimoto ysugimoto deleted the fix-base64-decoding-function branch March 13, 2024 02:57
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

Successfully merging this pull request may close these issues.

[BUG] Base64 decode process is different from the actual one
2 participants