Skip to content

tools/extract_offsets: fail closed on hex/malformed DWARF offsets, forward declarations, and nested members (fixes #3370) - #3371

Open
zainrizvi0611-cmd wants to merge 71 commits into
limitlessprojects:mainfrom
zainrizvi0611-cmd:fix-extract-offsets-3370
Open

zainrizvi0611-cmd wants to merge 71 commits into
limitlessprojects:mainfrom
zainrizvi0611-cmd:fix-extract-offsets-3370

Conversation

@zainrizvi0611-cmd

Copy link
Copy Markdown

Fixes #3370

Summary

Hardens tools/extract_offsets.py so DWARF offset and struct byte-size extraction fails closed deterministically:

  1. Strict decimal, hex, and DW_OP_plus_uconst unsigned integer parsing (_parse_dwarf_uint in tools/extract_offsets.py):
    Parses DW_AT_data_member_location and DW_AT_byte_size with full-token anchors supporting decimal (16), hexadecimal (0x10), and (DW_OP_plus_uconst: N) forms instead of re.search(r"...:\s*(\d+)") (which previously matched only the leading 0 of 0x10 or leading digits of malformed strings).
  2. Fail closed on missing or invalid DW_AT_byte_size (tools/extract_offsets.py):
    Exits non-zero (FAILED: missing or invalid DW_AT_byte_size for ...) when runtime.g or runtime.m is missing a valid DW_AT_byte_size attribute instead of printing size=None.
  3. Skip DWARF forward declarations and nested member DIEs (members_of in tools/extract_offsets.py):
    Ignores DW_AT_declaration forward-declaration DIEs, prefers complete struct definitions with member entries, and restricts member collection to direct children (e["depth"] == base + 1) so nested struct/union fields (depth >= base + 2) cannot overwrite runtime.g or runtime.m offsets. Also passes encoding="utf-8", errors="replace" to subprocess.run.
  4. Regression tests (tools/test_extract_offsets.py):
    Adds test_hex_offsets_forward_decl_and_nested_members, test_malformed_member_offset_fails_closed, and test_missing_struct_byte_size_fails_closed.

Verification

python3 -m py_compile tools/extract_offsets.py tools/test_extract_offsets.py
python3 -m unittest discover -s tools -p "test_extract_offsets.py" -v

Rewards address (Base USDC / ETH): 0x0970e4ad9Ff0a9A183e9c22de4664CC4A17804e6

@github-actions github-actions Bot added the bot:stale-base Shepherd: behind main beyond threshold label Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:stale-base Shepherd: behind main beyond threshold

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[tooling] tools/extract_offsets.py silently truncates hex DWARF offsets to 0, fails on forward declarations, and clobbers fields from nested structs

1 participant