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

Provide nicer error messages when providing incompatible types to encoder #108

Open
ralexstokes opened this issue Mar 26, 2020 · 3 comments

Comments

@ralexstokes
Copy link
Member

ralexstokes commented Mar 26, 2020

reported by Mehdi wrt the beacon fuzz efforts run by Sigma Prime:

e.g.

import ssz
ssz.encode(True, "byte")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/scop/.local/lib/python3.6/site-packages/ssz/codec.py", line 28, in encode
    return sedes_obj.serialize(value)
  File "/home/scop/.local/lib/python3.6/site-packages/ssz/sedes/byte.py", line 14, in serialize
    if len(value) != 1:
TypeError: object of type 'bool' has no len()
import ssz
ssz.encode('', 'uint32')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/scop/.local/lib/python3.6/site-packages/ssz/codec.py", line 28, in encode
    return sedes_obj.serialize(value)
  File "/home/scop/.local/lib/python3.6/site-packages/ssz/sedes/uint.py", line 15, in serialize
    if value < 0:
TypeError: '<' not supported between instances of 'str' and 'int'

update: it would be nice of the library tied to detect some basic misuses and provide nicer error messages, rather than the above which are rather opaque.

@ralexstokes
Copy link
Member Author

after some internal conversation, we decided to put this responsibility on the programmer to use encode correctly

@pipermerriam
Copy link
Member

Is there a reason not to do some basic type checking and raise friendlier errors?

@ralexstokes
Copy link
Member Author

not really, but then this becomes a slightly different issue (as it was motivated by fuzzing efforts), i'll re-open and change the title to reflect this is more about usability

@ralexstokes ralexstokes reopened this Mar 27, 2020
@ralexstokes ralexstokes changed the title Harden py-ssz to adversarial inputs Provide nicer error messages when providing incompatible types to encoder Mar 27, 2020
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

No branches or pull requests

2 participants