pschanely / CrossHair

An analysis tool for Python that blurs the line between testing and type systems.
Other
996 stars 47 forks source link

Support `base64.b64encode()` and friends #293

Closed Zac-HD closed 1 month ago

Zac-HD commented 1 month ago

Recent upgrades fixed enough prior problems for https://github.com/HypothesisWorks/hypothesis/pull/4034 to uncover:

Traceback (most recent call last):
  File ".../hypothesis/hypothesis-python/tests/cover/test_reproduce_failure.py", line 37, in test_encoding_loop
    assert decode_failure(encode_failure(b)) == b
  File ".../hypothesis/core.py", line 357, in encode_failure
    return base64.b64encode(buffer)
  File ".../lib/python3.10/base64.py", line 58, in b64encode
    encoded = binascii.b2a_base64(s, newline=False)
TypeError: a bytes-like object is required, not 'SymbolicBytes'

and unlike e.g. https://github.com/pschanely/CrossHair/issues/286, base64-encoding seems suffiently well-behaved that it would be feasible to have a symbolic implementation instead of realizing. Thoughts?

pschanely commented 1 month ago

and unlike e.g. #286, base64-encoding seems suffiently well-behaved that it would be feasible to have a symbolic implementation instead of realizing. Thoughts?

Yeah, very feasible! (heh, though I've been putting off a similar support for int(s, base=n) where n != 10)

pschanely commented 1 month ago

This is in 0.0.66!

Only supporting base64.b64encode and base64.b64decode so far. There's a lot of binascii left to do, but tracking that in #289