StatePickler cache is broken: can result in data corruption

Open
#66 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
python
Domain
backend

Research direction

Reproduce the failure using apptools.persistence.state_pickler and the dumps/loads example in the issue. Inspect StatePickler's object-cache keying and verify that distinct objects with colliding hashes remain distinct after a round trip. Done means the provided tuple example loads without data corruption, with regression coverage for the collision case.

Written by the indexing model from the issue text.

Description

type: bug

The StatePickler uses the hash function hash to generate a key for its object cache, at least for hashable objects. Without an extra equality check, this is broken, and leads to different objects with the same hash being treated as the same object.

Example failure resulting from this:

>>> from apptools.persistence.state_pickler import *
>>> loads_state(dumps([(-1, -1), (-2, -2), (-3, -3)]))
[(-1, -1), (-1, -1), (-3, -3)]

Here the error occurs because the tuples (-1, -1) and (-2, -2) have the same hash.

Dominant language
Python
Stars
38
Forks
21
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from enthought/apptools

All issues in enthought/apptools

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.