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

APSWBuffer_FromObject() "conniving performance hack" is unreliable #256

Closed
dgrunwald opened this issue Jan 28, 2019 · 2 comments
Closed

Comments

@dgrunwald
Copy link

Assertion failed: tmp==APSWBuffer_hash(res), file apsw\src\apswbuffer.c, line 200

Using APSW 3.26.0-r1 on Python 2.7.15 on Windows.
When using PYTHONHASHSEED=random, APSWBuffer_hash() no longer corresponds to Python hash algorithm, which invalidates the optimization of stealing the existing hash code.
In debug mode this triggers an assertion, not sure what kind of misbehavior could be triggered in normal builds.

Hash Randomization is enabled by default in Python 3, so that's probably also affected.

@dgrunwald
Copy link
Author

Even without hash randomization, there's a subtle bug when the hash computation results in -1:
When copying such a hash code from Python, it's adjusted to -2 (and stays that way; as the +1 is avoided in this special case).
However in APSWBuffer_hash, the +1 is always added and the -1->-2 special case is handled only later. So if the python hash computation results in -1, the effective hash code as determined by APSWBuffer_FromObject() is -2; but the effective hash code as determined by APSWBuffer_hash is 0.

@rogerbinns
Copy link
Owner

I greatly appreciate you finding this problem - thank you!

rogerbinns added a commit that referenced this issue Mar 5, 2019
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