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

Ignore spacing chars for base64decode #32422

Closed
wants to merge 1 commit into from

Conversation

Moelf
Copy link
Contributor

@Moelf Moelf commented Jun 26, 2019

fixes #32397

@@ -209,6 +209,7 @@ julia> String(b)
```
"""
function base64decode(s)
s = replace(s, r"\s" => "")
Copy link
Member

Choose a reason for hiding this comment

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

This implementation is not ideal since it copies the data. Would be best to handle it during decoding. I also believe it is only necessary to handle ASCII space and newline.

Copy link
Contributor Author

@Moelf Moelf Jun 26, 2019

Choose a reason for hiding this comment

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

So maybe do a || (space) || (newline) somwhere in here?

if b1 < 0x40 && b2 < 0x40 && b3 < 0x40 && b4 < 0x40 && p + 2 < p_end

Copy link
Member

Choose a reason for hiding this comment

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

Hi, I wrote the original code of this implementation to improve the performance based on my package (https://github.com/bicycle1885/CodecBase.jl). The implementation in this package ignores whitespace characters so it may help here. Otherwise, I can fix the issue instead of you if you are not in a rush.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I think I can pull this one off, Of course it would be easier if you can give me some hint on which part of the code is used to ignore invalid characters when decoding.

Copy link
Member

Choose a reason for hiding this comment

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

I don't remember the code well, but I think you can modify the decoding behavior just by modifying its look-up table.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that was the case in your CodecBase but not in Julia's code base.

@JeffBezanson
Copy link
Member

Will need a test of course.

@Moelf
Copy link
Contributor Author

Moelf commented Jun 26, 2019

Fun fact, python does this to handle invalid characters:
https://github.com/python/cpython/blob/5150d327924959639215ed0a78feffc0d88258da/Lib/base64.py#L85

@Moelf
Copy link
Contributor Author

Moelf commented Jun 26, 2019

@JeffBezanson I have the test covered, and I don't think it's worth to do in the decoding first because there are copying and allocation anyways (if we need to check if a char is valid or not), second because I don't think people pass ~GB of data into base64decode (bonus, regular expression is okally fast?)

@JeffBezanson
Copy link
Member

I disagree, and I also realized another problem which is that a user can directly call readbytes!(Base64DecodePipe(data), vector) where the same issue needs to be handled, plus vector is pre-allocated so no allocation necessarily occurs.

@Moelf Moelf closed this Jul 4, 2019
@Moelf Moelf deleted the base64decode_space branch July 4, 2019 06:45
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.

Base64 base64decode does not ignore whitespace, but should
3 participants