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

Calling Decode multiple times from same instance corrupted results #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

cyotek
Copy link

@cyotek cyotek commented Nov 8, 2016

Hello,

I was playing around with your Ascii85 implementation when I discovered that calling Decode multiple times from the same Ascii85 instance would cause data corruption on successive calls. For example, the following output was generated by changing TestString to call and print Decode twice

<~9jqo^BlbD-BleB1DJ+*+F(f,q/0JhKF<GL>[email protected]$d7F!,L7@<6@)/0JDEF<G%<+EV:2F!,
O<DJ+*.@<*K0@<6L(Df-\0Ec5e;DffZ(EZee.Bl.9pF"AGXBPCsi+DGm>@3BB/F*&OCAfu2/AKY
i(DIb:@FD,*)+C]U=@3BN#EcYf8ATD3s@q?d$AftVqCh[NqF<G:8+EV:.+Cf>-FD5W8ARlolDIa
l(DId<j@<?3r@:F%a+D58'ATD4$Bl@l3De:,-DJs`8ARoFb/0JMK@qB4^F!,R<AKZ&-DfTqBG%G
>uD.RTpAKYo'+CT/5+Cei#DII?(E,9)oF*2M7/c~>

Encoded in 345 chars

Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.

Decoded 269 chars

{d??is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.

You can see the first few characters in the second call have been corrupted. I first spotted this when storing encoded passwords in an XML file then wondering why they weren't working anymore after successive saves :)

Fortunately the fix was simple - so simple it seems a little absurd creating a pull request (especially given it was a demo to accompany your blog post), but that seems to be the GitHub way. Basically, the Decode method needs to reset the _tuple instance variable back to 0 prior to doing its thing, and successive calls then work fine without the corruption. (At least I hope so, I haven't really grokked how it truly works).

Thanks for providing the helpful class!

Regards;
Richard Moss

@graingert
Copy link
Contributor

@cyotek is this bug in SimpleBase?

@coding-horror it might be worth archiving this project now that it's pointing to SimpleBase

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.

2 participants