[issue37596] Reproducible pyc: frozenset is not serialized in a deterministic order
STINNER Victor
report at bugs.python.org
Fri Sep 3 07:44:18 EDT 2021
STINNER Victor <vstinner at python.org> added the comment:
The test failed at:
def test_deterministic_sets(self):
# bpo-37596: To support reproducible builds, sets and frozensets need to
# have their elements serialized in a consistent order (even when they
# have been scrambled by hash randomization):
for kind in ("set", "frozenset"):
for elements in (
"float('nan'), b'a', b'b', b'c', 'x', 'y', 'z'",
# Also test for bad interactions with backreferencing:
"('string', 1), ('string', 2), ('string', 3)",
):
s = f"{kind}([{elements}])"
with self.subTest(s):
# First, make sure that our test case still has different
# orders under hash seeds 0 and 1. If this check fails, we
# need to update this test with different elements:
args = ["-c", f"print({s})"]
_, repr_0, _ = assert_python_ok(*args, PYTHONHASHSEED="0")
_, repr_1, _ = assert_python_ok(*args, PYTHONHASHSEED="1")
self.assertNotEqual(repr_0, repr_1) # <=== HERE
(...)
It checks that the representation of a set is different for two different PYTHONHASHSEED values (0 and 1). On my Fedora 34, I confirm that they are different:
PYTHONHASHSEED=0:
vstinner at apu$ PYTHONHASHSEED=0 ./python -c "print(set([('string', 1), ('string', 2), ('string', 3)]))"
{('string', 1), ('string', 2), ('string', 3)}
vstinner at apu$ PYTHONHASHSEED=0 ./python -c "print(set([('string', 1), ('string', 2), ('string', 3)]))"
{('string', 1), ('string', 2), ('string', 3)}
vstinner at apu$ PYTHONHASHSEED=0 ./python -c "print(set([('string', 1), ('string', 2), ('string', 3)]))"
{('string', 1), ('string', 2), ('string', 3)}
versus PYTHONHASHSEED=1:
vstinner at apu$ PYTHONHASHSEED=1 ./python -c "print(set([('string', 1), ('string', 2), ('string', 3)]))"
{('string', 3), ('string', 1), ('string', 2)}
vstinner at apu$ PYTHONHASHSEED=1 ./python -c "print(set([('string', 1), ('string', 2), ('string', 3)]))"
{('string', 3), ('string', 1), ('string', 2)}
vstinner at apu$ PYTHONHASHSEED=1 ./python -c "print(set([('string', 1), ('string', 2), ('string', 3)]))"
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37596>
_______________________________________
More information about the Python-bugs-list
mailing list