Skip to content

fix: GetAsciiStringAt Python parity (predicate, bounds, maxLength, requireCstring)#29

Merged
tinysec merged 1 commit into
masterfrom
fix/get-ascii-string-at-parity
Jul 8, 2026
Merged

fix: GetAsciiStringAt Python parity (predicate, bounds, maxLength, requireCstring)#29
tinysec merged 1 commit into
masterfrom
fix/get-ascii-string-at-parity

Conversation

@tinysec

@tinysec tinysec commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Problem

NavigationExtensions.GetAsciiStringAt deviated from Python BinaryView.get_ascii_string_at (binaryview.py:8023) in four ways:

# Python (spec) C# (was) Impact
1 predicate 0 < c <= 0x7f (any non-NUL ASCII) 0x20..0x7e (printable-only) truncated runs containing control chars (tab, newline)
2 addr < start or addr >= end → None no bounds check read past view edge
3 max_length cap param hardcoded 4096 window no caller cap
4 require_cstring=True (NUL terminator) never checked returned non-C-string runs

Fix

Rewritten to mirror Python exactly, using BinaryReader (Position + ReadByte) — the same lazy byte loop Python uses (BinaryReader.seek/read8). Gains optional maxLength/requireCstring params with Python-matching defaults; existing callers unaffected, behavior changes toward parity.

Verification

  • dotnet build -c Release clean.
  • Harness: updated the independent oracle (ViewProbe.FindFirstAsciiCString) to the corrected spec (predicate 0<c<=0x7f + NUL terminator), plus 2 new tests (out-of-bounds → null; maxLength cap). 44/44 harness tests pass.

Surfaced while auditing the navigation layer for Python parity (continues the 1:1 parity directive; IL operand-count cluster was PRs #26/#27/#28).

…quireCstring)

NavigationExtensions.GetAsciiStringAt deviated from Python
BinaryView.get_ascii_string_at (binaryview.py:8023) in four ways:

1. Wrong byte predicate. C# used printable-only 0x20..0x7e; Python uses
   0 < c <= 0x7f (any non-NUL ASCII byte, including control characters such
   as tab 0x09 and newline 0x0a). Printable-only truncated runs containing
   control characters.
2. Missing address bounds check. Python returns None when addr < start or
   addr >= end; C# read unconditionally.
3. Missing maxLength parameter. Python caps the run at max_length; C# hardcoded
   a 4096 window.
4. Missing requireCstring parameter. Python requires a NUL terminator by
   default (require_cstring=True); C# never checked termination.

Rewritten to mirror Python exactly via BinaryReader (Position + ReadByte),
the same lazy byte loop Python uses (BinaryReader.seek/read8). Signature
gains maxLength/requireCstring optional params with Python-matching defaults,
so existing callers are unaffected; behavior changes toward parity.
@tinysec tinysec merged commit 095e644 into master Jul 8, 2026
1 check passed
@tinysec tinysec deleted the fix/get-ascii-string-at-parity branch July 8, 2026 09:53
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.

1 participant