Skip to content

Handle DWARF string sections larger than 2 GB - #1216

Open
Martin Řezník (martin-reznik) wants to merge 7 commits into
mainfrom
fix/large-debug-str
Open

Handle DWARF string sections larger than 2 GB#1216
Martin Řezník (martin-reznik) wants to merge 7 commits into
mainfrom
fix/large-debug-str

Conversation

@martin-reznik

Copy link
Copy Markdown
Contributor

Promotes the DWARF >2 GB string-section handling into main. Staged on fix/large-debug-str via #1207 (approved) and now being promoted.

What this does

  • Adds an IDwarfStringReader abstraction for DWARF string sections, with a file-backed implementation (DwarfFileStringReader) that reads individual null-terminated strings directly from the binary instead of materializing the whole .debug_str section into a byte[].
  • Adds the opt-in --dwarf-string-read-threshold CLI option. File-backed reads are used only when this option is supplied and the .debug_str section reaches the configured size.
  • Preserves the existing in-memory behavior by default and for sections below the threshold.
  • Adds regression tests for >2 GB reads and for the opt-in threshold wiring.

Root cause

ELFSharp materializes section contents into a byte[]; a .debug_str section larger than int.MaxValue overflows the 32-bit size conversion, preventing BinSkim from analyzing otherwise-valid ELF binaries (hit by Minecraft's Nintendo Switch symbol files).

Behavior / compatibility

  • Fully opt-in. With no --dwarf-string-read-threshold, the value is null and every existing user keeps the exact in-memory code path (asserted by a unit test).
  • No thread-safety change. Per-binary DWARF parsing is sequential and each ElfBinary builds/disposes its own reader per Lazy, so the stateful file-backed reader is never shared across BinSkim's file-level parallelism.
  • Mach-O is adapted to the new interface (signature only); the threshold is wired through ElfBinary only.

Known limitations (non-blocking, tracked for later)

  • Addressable offset is bounded at 4 GB (covers DWARF32 2-4 GB; not a >4 GB DWARF64 .debug_str).
  • The opt-in read is byte-by-byte, so it is slower on very large sections.
  • A >2 GB Mach-O .debug_str is still unsupported.

Refs

@akoeplinger

Alexander Köplinger (akoeplinger) commented Sep 2, 2026

Copy link
Copy Markdown
Member

looks like this is failing on some dotnet format errors?

@v-davidquiceno-ascendion

David Quiceno (v-davidquiceno-ascendion) commented Sep 2, 2026

Copy link
Copy Markdown

Alexander Köplinger (@akoeplinger) Martin Řezník (@martin-reznik) I fixed the CRLF formatting issue in #1218. dotnet format src --verify-no-changes passes with the update.

…t-format

Fix BinaryTargetManager line endings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants