Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

__static_attributes__ is not deterministic #124442

Closed
Labels
3.13bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error
@kp2pml30

Description

@kp2pml30

Bug report

Bug description:

Tested on commit:e9b00cc

Order of strings in__static_attributes__ is not deterministic

Running the following a couple of times produces different hashes:

/opt/cpython/cross-build/build/python ../../Programs/_freeze_module.py zipimport ../../Lib/zipimport.py Python/frozen_modules/zipimport.hsha256sum ./Python/frozen_modules/zipimport.h

I patched this generator to output dis as follows:

diff --git a/Programs/_freeze_module.py b/Programs/_freeze_module.pyindex ba638ee..7e837e9 100644--- a/Programs/_freeze_module.py+++ b/Programs/_freeze_module.py@@ -24,6 +24,9 @@ def compile_and_marshal(name: str, text: bytes) -> bytes:     filename = f"<frozen {name}>"     # exec == Py_file_input     code = compile(text, filename, "exec", optimize=0, dont_inherit=True)+    import dis+    with open("/tmp/a", "at") as f:+        dis.dis(code, file=f)     return marshal.dumps(code)

Then disassembly differs in one place (after removingat 0x[a-f0-9]*):

diff --git a/tmp/a b/tmp/bindex 372a97c..4010046 100644--- a/tmp/a+++ b/tmp/b@@ -291,7 +291,7 @@ Disassembly of <code object zipimporter , file "<frozen zipimport>", line 50>: 289           LOAD_CONST              15 (<code object __repr__ , file "<frozen zipimport>", line 289>)               MAKE_FUNCTION               STORE_NAME              16 (__repr__)-              LOAD_CONST              16 (('archive', 'prefix'))+              LOAD_CONST              16 (('prefix', 'archive'))               STORE_NAME              17 (__static_attributes__)               RETURN_CONST             4 (None)

diff in.h files is quite small, so I assume only sorting is affected:

-    0,0,0,41,2,114,46,0,0,0,114,44,0,0,0,169,+    0,0,0,41,2,114,44,0,0,0,114,46,0,0,0,169,

CPython versions tested on:

3.13

Operating systems tested on:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp