python-blake2 icon indicating copy to clipboard operation
python-blake2 copied to clipboard

Data with null bytes is not supported

Open veorq opened this issue 12 years ago • 10 comments

Data that includes null bytes seems to throw an exception:

import blake2 blake2.blake2('\x02\x01') 'c9b2d35d76fb7c0d8ffe8d5342d869b2237569d57e1f9415ee732f802e17e9a384f390834addad4a04443bcfe91e985d6c2daddd16bd97471bd2c02cc47159cd' blake2.blake2('\x02\x00') Traceback (most recent call last): File "", line 1, in TypeError: argument 1 must be string without null bytes, not str blake2.blake2('\x00\x01') Traceback (most recent call last): File "", line 1, in TypeError: argument 1 must be string without null bytes, not str

Same with blake2.blake2b and blake2.blake2s.

veorq avatar Jan 07 '13 09:01 veorq

updated if function get null string, it will return None

darjeeling avatar Jan 09 '13 13:01 darjeeling

Still does not support arbitrary data (ie that includes null bytes); why be limited to strings?

veorq avatar Jan 14 '13 09:01 veorq

sorry I'm still busy. =) I'll fix it in two days.

darjeeling avatar Jan 14 '13 13:01 darjeeling

@pgonee fixed this. thx!

darjeeling avatar Feb 19 '13 06:02 darjeeling

Thanks, but I still don't understand why strings with null bytes are not supported; why should the API be limited to strings of characters, rather than arbitrary byte strings?

On Tue, Feb 19, 2013 at 7:46 AM, Bae KwonHan [email protected]:

@pgonee https://github.com/pgonee fixed this. thx!

— Reply to this email directly or view it on GitHubhttps://github.com/darjeeling/python-blake2/issues/2#issuecomment-13759225.

veorq avatar Feb 19 '13 06:02 veorq

@aumasson Still not working? perhaps I think the fixed version of python-blake2 is not yet uploaded to PyPI. Try to clone this repository directly or ask @darjeeling .

pgonee avatar Feb 19 '13 07:02 pgonee

Have not tried the module, just read "Pull Request #3: string containing \x00 raises unexpected exception." on https://github.com/darjeeling/python-blake2/issues/2

On Tue, Feb 19, 2013 at 8:03 AM, EUNJO WI [email protected] wrote:

@aumasson Still not working? perhaps I think the fixed version of python-blake2 is not yet uploaded to PyPI. Try to clone this repository directly or ask @darjeeling .

— Reply to this email directly or view it on GitHub.

veorq avatar Feb 19 '13 07:02 veorq

@aumasson No. I'm afraid you misunderstood. There was a bug that the string containing \x00 raises unexpected exception, exactly what you experienced. and thus I fixed it. Check it out again.

In short, strings with null bytes are supported now. ^^

pgonee avatar Feb 19 '13 07:02 pgonee

Ok, sorry for misunderstanding.

There is something strange though:

import blake2 blake2.blake2('\x00') '507ed301000000008fa05700000000004098d3010000000025c15700000000000005da01000000001c104135167f000078cabc00ff7f000080cabc00ff7f0000' blake2.blake2('\x00') '507ed301000000008fa057000000000050006637167f00008fa05700000000000005da01000000001c104135167f000078cabc00ff7f000080cabc00ff7f0000' blake2.blake2('\x01') '507ed301000000008fa05700000000008005da010000000000000000000000003005da01000000001c104135167f000078cabc00ff7f000080cabc00ff7f0000' blake2.blake2('\x01') '507ed301000000008fa05700000000005005da010000000000000000000000000005da01000000001c104135167f000078cabc00ff7f000080cabc00ff7f0000'

Note that the hash of \x00 is different when computed twice. Also, why do we have all those zeros?

On Tue, Feb 19, 2013 at 8:12 AM, EUNJO WI [email protected] wrote:

@aumasson https://github.com/aumasson No. I'm afraid you misunderstood. There was a bug that the string containing \x00 raises unexpected exception, exactly what you experienced. and thus I fixed it. Check it out again.

— Reply to this email directly or view it on GitHubhttps://github.com/darjeeling/python-blake2/issues/2#issuecomment-13759810.

veorq avatar Feb 19 '13 07:02 veorq

The version in Pypi is still returning None when given a string containing a null character. This is a critical bug which renders the library completely unusable. Null strings are valid inputs for hash functions, and should result in hash outputs not None. It's utterly bizarre that this bug is in there, because it seems like something you'd have to specifically add.

bramcohen avatar Dec 24 '16 06:12 bramcohen