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

charset_to_int drops characters on some inputs

Open DoronShapiro opened this issue 10 years ago • 0 comments

To reproduce:

>>> from utilitybelt import charset_to_int
>>> from utilitybelt import base32_chars
>>> charset_to_int("AARDVARK", base32_chars)
574259754
>>> charset_to_int("RDVARK", base32_chars)
574259754

When the leading characters of s are the first element of the charset, they are not included in the returned integer. This is because output starts as 0 and is then multiplied by some number added to an index, which in these cases is also 0.

This behavior becomes an issue in the secret sharing library (https://github.com/blockstack/secret-sharing/) that depends on utilitybelt, as it corrupts secrets and leaks information about secret contents.

One possible fix is to initialize output as 1 instead of 0.

DoronShapiro avatar Jan 08 '16 16:01 DoronShapiro