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

Bug in the caching implementation #71

Closed
Stranger6667 opened this issue Nov 20, 2020 · 1 comment · Fixed by #72
Closed

Bug in the caching implementation #71

Stranger6667 opened this issue Nov 20, 2020 · 1 comment · Fixed by #72

Comments

@Stranger6667
Copy link
Contributor

After trying out atheris, based on your example (it is awesome, I'd say!) I found an interesting bug in caching that comes from the following fact:

>>> hash(-2)
-2
>>> hash(-1)
-2

From PEP-456:

The internal interface code between the hash function and the tp_hash slots implements special cases for zero length input and a return value of -1. An input of length 0 is mapped to hash value 0. The output -1 is mapped to -2.

It leads to a problem with the wrong canonicalisation, e.g. if {'exclusiveMaximum': 1, 'exclusiveMinimum': -1, 'type': 'number'} was cached first, then applying canonicalisation on {'exclusiveMaximum': 1, 'exclusiveMinimum': -2, 'type': 'number'} will return 'exclusiveMaximum': 1, 'exclusiveMinimum': -2, 'type': 'number'} :(

-1 is quite common, and these cache collisions make me think about the current implementation - I am not completely sure how to implement caching efficiently enough. However, in #69, after reducing how many schemas are inlined, the performance improved dramatically, and I am not sure if this caching layer worth having (at least in the current implementation)

What do you think?

@Zac-HD
Copy link
Member

Zac-HD commented Nov 20, 2020

Better to be obviously correct than keep a cache whoch is not obviously buggy, IMO - let's take it out then.

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 a pull request may close this issue.

2 participants