8000 bpo-37596: Make `set` and `frozenset` marshalling deterministic by brandtbucher · Pull Request #27926 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-37596: Make set and frozenset marshalling deterministic #27926

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

Merged
merged 7 commits into from
Aug 25, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add regression test
  • Loading branch information
brandtbucher committed Aug 24, 2021
commit ae386193e1be41856daebaf0a78f1b1cb16387d7
14 changes: 14 additions & 0 deletions Lib/test/test_marshal.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,20 @@ def test_eof(self):
for i in range(len(data)):
self.assertRaises(EOFError, marshal.loads, data[0: i])

def test_deterministic_sets(self):
# bpo-37596: sets and frozensets must always marshal deterministically!
# Test this by seeding string hashes:
elements = "(float('nan'), b'a', b'b', b'c', 'x', 'y', 'z')"
for kind in ("set", "frozenset"):
script = f"import marshal; print(marshal.dumps({kind}({elements})))"
with self.subTest(kind):
# {nan, b"b", "x", b'a', b'c', 'y', 'z'}
_, a, _ = assert_python_ok("-c", script, PYTHONHASHSEED="0")
# {nan, 'x', b'a', 'z', b'b', 'y', b'c'}
_, b, _ = assert_python_ok("-c", script, PYTHONHASHSEED="1")
self.assertEqual(a, b)


LARGE_SIZE = 2**31
pointer_size = 8 if sys.maxsize > 0xFFFFFFFF else 4

Expand Down
0