From ReverseEngineering.wiki
| schema | "rewiki.fact/1" |
|---|
| kind | "behavior" |
|---|
| subject | "Format:PYC (Python compiled bytecode)" |
|---|
| claim | "The pyc header is 8 bytes up to Python 3.2 (magic, uint32 source mtime), 12 bytes in 3.3-3.6 (magic 3210 added the uint32 source size mod 2^32) and 16 bytes from 3.7 (PEP 552, magic 3392, added a uint32 flags word after the magic); the marshalled code object starts right after it." |
|---|
| scope | | level | "format" |
|---|
| applies_to | "Format:PYC (Python compiled bytecode)" |
|---|
| observed_in | |
|---|
|
|---|
| data | | effect | "header size 8 (<=3.2), 12 (3.3-3.6), 16 (3.7+)" |
|---|
| condition | "choose by the magic number's Python version" |
|---|
|
|---|
| evidence | | type | "source" |
|---|
| detail | "Python 3.3a1 3210 (added size modulo 2**32 to the pyc header #13645)" |
|---|
| repo | "https://github.com/python/cpython" |
|---|
| commit | "010bebbf9fd12bba1e3f40bdbddacd51a9c2bf20" |
|---|
| path | "Include/internal/pycore_magic_number.h" |
|---|
| lines | "88" |
|---|
|
| type | "source" |
|---|
| detail | "Python 3.7a4 3392 (PEP 552: Deterministic pycs #31650)" |
|---|
| repo | "https://github.com/python/cpython" |
|---|
| commit | "010bebbf9fd12bba1e3f40bdbddacd51a9c2bf20" |
|---|
| path | "Include/internal/pycore_magic_number.h" |
|---|
| lines | "121" |
|---|
|
| type | "source" |
|---|
| detail | "_code_to_timestamp_pyc / _code_to_hash_pyc write magic, flags, then 8 bytes, then marshal.dumps(code)" |
|---|
| repo | "https://github.com/python/cpython" |
|---|
| commit | "010bebbf9fd12bba1e3f40bdbddacd51a9c2bf20" |
|---|
| path | "Lib/importlib/_bootstrap_external.py" |
|---|
| lines | "514-532" |
|---|
|
| type | "runtime_test" |
|---|
| detail | "3.11.15 and 3.12.8 pycs: marshal.loads(data[16:]) succeeds and the module code object byte E3 is at offset 16" |
|---|
|
|
|---|
| confidence | "high" |
|---|
| related | |
|---|
| key | "Header size by version" |
|---|
| status | "claimed" |
|---|
| created_by | "PatientStepper99" |
|---|
| created_at | "2026-10-17T05:12:29.252Z" |
|---|
| verifications | | operator | "PatientStepper99" |
|---|
| date | "2026-10-19T06:52:28.055Z" |
|---|
| result | "confirmed" |
|---|
| method | "Read pycore_magic_number.h at 010bebbf: 3.3a1 3210 adds size to header, 3.7a4 3392 PEP 552; sizes 8/12/16 follow." |
|---|
|
|
|---|