Skip to content

test(native): replace parser wall-clock bounds with work measures - #10671

Closed
Davmunrey wants to merge 3 commits into
morluto:mainfrom
Davmunrey:claude/native-parser-work-bounds
Closed

Davmunrey wants to merge 3 commits into
morluto:mainfrom
Davmunrey:claude/native-parser-work-bounds

Conversation

@Davmunrey

Copy link
Copy Markdown
Contributor

Summary

Refs #10513. This slice covers native parsers. It complements #10619, #10627 and the JavaScript-lifetime slice. It replaces or deletes 4 of the 6 wall-clock bounds in src/native/** tests and changes no production code.

Change and scope

  • NativeInitializersParsers.test.ts, near-maximal section table: the 10 s bound becomes a count of ELF section-table reads through a test-local pass-through of readElfDirectoryFromBuffer. The test measured 6 reads per header and allows 16; a read beyond the limit throws.
  • NativeInitializersParsers.test.ts, huge DT_INIT_ARRAYSZ: the bound is deleted, because the test already asserts the slot budget.
  • PeLoadConfigParser.test.ts: the same read count over the readPeImage section table. The test measured 2 reads per section and allows 4.
  • KernelModuleParser.test.ts: the bound is deleted, because the test already asserts exact counts and a 2 MiB report bound.
  • Kept for a maintainer decision: the BinaryHardeningParsers bound (5 s) and the ElfNoteParser gold-version bound (1 s). Their regressions do not change any parser counter (14 s and 9.1 s when reintroduced), so no deterministic measure fits without a production counter.

Evidence and regression coverage

Each regression was reintroduced in an uncommitted change:

  • Header walk per initializer lookup: the old test failed after 64 s; the new test fails in about 1 s on the read count.
  • Section scan per PE callback: the old test took 3.8 s; the new test fails on the read count.
  • Unclamped slot scan: the old test hung (killed at 90 s) and never reached its time check. This case was not re-run against the new file.
  • Name decode per section, and overlong names listed: both the old and new tests fail.

Validation performed

  • npm run test:local on the 5 native test files: 353 passed.
  • npm run check:fast passed. oxfmt --check passed.

Author readiness

Human owner: @Davmunrey

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

Six assertions in five native parser tests bounded elapsed time (1 to
10 s). They depend on host speed and can fail on loaded CI shards
without a regression.

Four are replaced or removed:
- Near-maximal ELF section table (initializers): count section-table
  element reads through a test-local pass-through of
  readElfDirectoryFromBuffer. Reading the image reads each of the 65,535
  headers six times; the test allows 16. Walking the headers to name
  each slot's target reads them once per slot and stops at the allowance.
- Largest PE section table (load config): the same count over the
  readPeImage section table. Indexing names reads each section twice;
  the test allows 4. A per-callback scan reads them 4,096 more times.
- Huge declared DT_INIT_ARRAYSZ: deleted. The test already pins
  examined_entries to the slot budget and the budget limitation.
  Scanning the declared 2^50 slots never returns, so the elapsed check
  was never reached.
- Shared huge __ksymtab name: deleted. The test already pins the exact
  examined count, null names with their reason and a 2 MiB report bound.
  Decoding the shared name per section exceeds the section directory's
  16 MiB name budget.

Two bounds stay because no counter observes their regression:
- BinaryHardeningParsers, hostile section table (5 s): rescanning the
  admitted note tables per candidate works on spans copied out of the
  section headers, so no parser counter, limit or test-visible read
  changes.
- ElfNoteParser, GNU gold version (1 s): a backtracking trailing-NUL
  regex leaves the text budget charges unchanged.

Validation: each regression was reintroduced in the parser (uncommitted)
and run against the base test file and the new one where it changed.
- Header walk per initializer lookup: base failed after 64,207 ms
  (10,000 ms bound); new failed in about 1 s at the read allowance.
- Section scan per PE callback: base failed at 3,775 ms (1,000 ms
  bound); new failed at the read allowance.
- Unclamped DT_INIT_ARRAYSZ scan: the base test did not finish in 90 s
  (not rerun on the new file, which only drops lines after the read).
- Shared name decoded per section: base and new failed with
  BinaryResourceFailure (16 MiB name budget). Over-long names listed:
  base and new failed the report schema.
- Kept bounds: rescanning admitted note tables failed at 14,009 ms
  (5,000 ms); a regex NUL trim failed at 9,106 ms (1,000 ms).
test:local on the five files: 353 passed. check:fast: passed.

Refs morluto#10513
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-14T20:59:15.419822Z
We couldn’t complete this review. Comment @codex review to try again.
43e2fbb PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@greptile-apps

greptile-apps Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The test-only changes appear safe to merge.

Summary

Replaces two native-parser timing assertions with test-local section-read allowances and removes two timing assertions while keeping existing budget and output checks.

  • The ELF stress test caps section-table reads during initializer lookups.
  • The PE callback stress test caps section reads while locating callbacks.
  • The slot and kernel-module budget tests no longer use fixed-time cutoffs.

Reviews (2) · Last reviewed commit: "test(native): format the moved section d..." · Reviewed by Greptile

Main moved ArtifactReader to src/resources and readPeImage and readElfDirectoryFromBuffer to src/domain/native. The work-count tests mock those readers, and a mock of a path that no longer exists intercepts nothing, so their read budgets would pass without counting. The mocks now name the new modules; each test fails again when its budget is cut to one read.
@Davmunrey

Copy link
Copy Markdown
Contributor Author

Superseded by 8318d28 (#11648), which bounds section lookups in the same three parser tests (KernelModuleParser, NativeInitializersParsers, PeLoadConfigParser) by table reads. Closing.

@Davmunrey Davmunrey closed this Nov 16, 2026
@morluto morluto added the area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior label Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants