-
Notifications
You must be signed in to change notification settings - Fork 26
[Bugfix] Padding chars no longer allowed anywhere but the end #31
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
Conversation
Data/ByteString/Base64/Internal.hs
Outdated
poke8 (plusPtr dst 2) (fromIntegral w) | ||
go (plusPtr dst 3) (plusPtr src 4) (n + 3) | ||
|
||
finish !dst !src !n |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This unrolls the tail end of the loop (the last 4 bytes to be encoded). Note the difference in padding checks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you know... comments such as these would be valuable to be included as source-code comments in the source-code... then you wouldn't have to point this out as github-PR-annotations... ;->
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
B-but. IT'S ALL UNDOCUMENTED HERBERT. I've added comments, but i'm trying to keep with the style of the thing. If we want to add a fuller documentation PR, i'm happy to do it separately.
I can add it to the pile of spring cleanings we need to do in this library.
Benchmarks with Pre-fix:
Post-fix:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here's some preliminary comments... I understand you noticed some issues in finish
-part yourself?
Data/ByteString/Base64/Internal.hs
Outdated
poke8 (plusPtr dst 2) (fromIntegral w) | ||
go (plusPtr dst 3) (plusPtr src 4) (n + 3) | ||
|
||
finish !dst !src !n |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you know... comments such as these would be valuable to be included as source-code comments in the source-code... then you wouldn't have to point this out as github-PR-annotations... ;->
@hvr all of your comments have been addressed. I factored out |
Looks like addressing @hvr's comments also managed to achieve better perf:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm now! :-)
This is a bit of a surprising bug in
base64-bytestring
:It stems from the fact that the decode algorithm is just wrong: it does not check that no padding chars occur in the first and second positions of the 32 bytes read off in each step of the decoding process! This PR fixes that, improves error reporting, and also improves performance by separating concerns in the decode routine to consider head, inner loop, and tail separately.