[PR #5200] [MERGED] fix(evm): trim hex carrier whitespace in linear time #6812

Closed
opened 2026-11-01 21:43:12 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/5200
Author: @Dragolone
Created: 10/19/2026
Status: ✅ Merged
Merged: 10/21/2026
Merged by: @morluto

Base: main ← Head: fix/evm-carrier-linear-trim


📝 Commits (2)

  • 516172d fix(evm): trim hex carrier whitespace in linear time
  • 6c93e92 Merge branch 'main' into fix/evm-carrier-linear-trim

📊 Changes

2 files changed (+19 additions, -3 deletions)

View changed files

📝 src/evm/EvmBytecodeCarrier.test.ts (+8 -0)
📝 src/evm/EvmBytecodeCarrier.ts (+11 -3)

📄 Description

Summary

decodeEvmBytecodeCarrier trims outer ASCII whitespace from a hex carrier with text.replace(/^[\x09-\x0d\x20]+|[\x09-\x0d\x20]+$/g, ""). For an invalid carrier with a long interior whitespace run, the end-anchored branch is retried at every position of that run and fails at $ each time, so trimming takes quadratic time before the carrier is rejected.

A 200,000-space run takes about 18.5 s. A few hundred KB can therefore exhaust the worker deadline instead of returning the documented invalid-format error.

No issue is linked: I searched open issues and PRs for "EvmBytecodeCarrier" and "hex carrier" and found no report of this; no open PR touches EvmBytecodeCarrier.ts.

Problem and expected behavior

Smallest trigger: the hex carrier 60 + 200,000 spaces + 00.

Expected: it is rejected with EvmCarrierFailure in linear time.

Change and scope

Trimming now uses two index scans over the same whitespace set (\t, \n, \v, \f, \r, space), then the existing 0x prefix strip and byte-pair check. Accepted and rejected carriers are unchanged; a BOM and other Unicode spaces stay invalid as before.

Not included: other carrier encodings.

Contribution scope: a robustness fix in existing parsing; a maintainer scope decision is not applicable.

Contract and boundary impact

  • Semantic owner and earliest changed stage: decodeEvmBytecodeCarrier in src/evm/EvmBytecodeCarrier.ts.
  • Contribution scope fit and linked maintainer decision: in scope; not applicable.
  • CLI and MCP/tool-catalog contract: none; the same carriers are accepted and rejected.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: none.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): not applicable.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none.

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated: src/evm/EvmBytecodeCarrier.test.ts — "rejects a long interior separator run in linear time". It expects EvmCarrierFailure for 60 + 200,000 spaces + 00, within 1 s.
  • Base reproduction or other evidence: executed. With EvmBytecodeCarrier.ts reverted to main, the test fails after about 18.5–18.9 s (expected … to be less than 1000).
  • User-visible CLI/MCP output (if applicable): unchanged.
  • Remaining proof gaps: the test bound is wall-clock based; the fixed version finishes in milliseconds, leaving a wide margin.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npx vitest run src/evm/EvmBytecodeCarrier.test.ts with EvmBytecodeCarrier.ts reverted to main ba866a26e — 1 failed (18.85 s), 9 passed.
  • The same file with the fix — 10 tests passed.
  • npx tsc --noEmit — 0 errors.
  • npx oxlint on the changed files — 0 errors.
  • npx oxfmt --check on the changed files — clean.
  • npm run verify:module-boundaries and the pre-push hook (deps check, typecheck, lint) — passed.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: removes a quadratic-time path on caller-supplied carriers.

Author readiness

Human owner: @Dragolone

  • 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.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/5200 **Author:** [@Dragolone](https://github.com/Dragolone) **Created:** 10/19/2026 **Status:** ✅ Merged **Merged:** 10/21/2026 **Merged by:** [@morluto](https://github.com/morluto) **Base:** `main` ← **Head:** `fix/evm-carrier-linear-trim` --- ### 📝 Commits (2) - [`516172d`](https://github.com/morluto/rea/commit/516172de6caafb5c606d04c4bae679589e9a361c) fix(evm): trim hex carrier whitespace in linear time - [`6c93e92`](https://github.com/morluto/rea/commit/6c93e92e54ca16c1b187c4cf35061d3140753821) Merge branch 'main' into fix/evm-carrier-linear-trim ### 📊 Changes **2 files changed** (+19 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `src/evm/EvmBytecodeCarrier.test.ts` (+8 -0) 📝 `src/evm/EvmBytecodeCarrier.ts` (+11 -3) </details> ### 📄 Description ## Summary `decodeEvmBytecodeCarrier` trims outer ASCII whitespace from a hex carrier with `text.replace(/^[\x09-\x0d\x20]+|[\x09-\x0d\x20]+$/g, "")`. For an invalid carrier with a long **interior** whitespace run, the end-anchored branch is retried at every position of that run and fails at `$` each time, so trimming takes quadratic time before the carrier is rejected. A 200,000-space run takes about 18.5 s. A few hundred KB can therefore exhaust the worker deadline instead of returning the documented invalid-format error. No issue is linked: I searched open issues and PRs for "EvmBytecodeCarrier" and "hex carrier" and found no report of this; no open PR touches `EvmBytecodeCarrier.ts`. ## Problem and expected behavior Smallest trigger: the hex carrier `60` + 200,000 spaces + `00`. Expected: it is rejected with `EvmCarrierFailure` in linear time. ## Change and scope Trimming now uses two index scans over the same whitespace set (`\t`, `\n`, `\v`, `\f`, `\r`, space), then the existing `0x` prefix strip and byte-pair check. Accepted and rejected carriers are unchanged; a BOM and other Unicode spaces stay invalid as before. Not included: other carrier encodings. Contribution scope: a robustness fix in existing parsing; a maintainer scope decision is not applicable. ## Contract and boundary impact - Semantic owner and earliest changed stage: `decodeEvmBytecodeCarrier` in `src/evm/EvmBytecodeCarrier.ts`. - Contribution scope fit and linked maintainer decision: in scope; not applicable. - CLI and MCP/tool-catalog contract: none; the same carriers are accepted and rejected. - Provider, bridge, target-format, or platform compatibility: none. - Evidence, artifact, provenance, or reconstruction contract: none. - Target selection, authority, upstream behavior, and cleanup details (if applicable): not applicable. - Generated metadata (`docs/public/product-catalog.json`), package, or installation impact: none. Expected effects (check known effects; use documentation-only on its own). Unchecked items do not establish absence; leave uncertainties visible. - [x] Read existing files or captured data. - [ ] Launch or attach to a process. - [ ] Inject instrumentation or run scripts/code. - [ ] Change process memory, registers, files, or configuration. - [ ] Contact network services. - [ ] Recover protected code or work around protections. - [ ] Documentation or usability only; no target interaction. - [ ] Not sure yet; investigation or maintainer guidance needed. ## Evidence and regression coverage - Tests added or updated: `src/evm/EvmBytecodeCarrier.test.ts` — "rejects a long interior separator run in linear time". It expects `EvmCarrierFailure` for `60` + 200,000 spaces + `00`, within 1 s. - Base reproduction or other evidence: executed. With `EvmBytecodeCarrier.ts` reverted to main, the test fails after about 18.5–18.9 s (`expected … to be less than 1000`). - User-visible CLI/MCP output (if applicable): unchanged. - Remaining proof gaps: the test bound is wall-clock based; the fixed version finishes in milliseconds, leaving a wide margin. For evidence-bearing changes: - [x] Observed, derived, and inferred claims remain distinguishable. - [x] Artifact identity, source provenance, and failed attempts remain preserved. - [x] Unsupported, incomplete, unavailable, or uncertain outcomes remain visible. ## Validation performed - `npx vitest run src/evm/EvmBytecodeCarrier.test.ts` with `EvmBytecodeCarrier.ts` reverted to main ba866a26e — 1 failed (18.85 s), 9 passed. - The same file with the fix — 10 tests passed. - `npx tsc --noEmit` — 0 errors. - `npx oxlint` on the changed files — 0 errors. - `npx oxfmt --check` on the changed files — clean. - `npm run verify:module-boundaries` and the pre-push hook (deps check, typecheck, lint) — passed. ## Compatibility, safety, and release - Breaking changes or migration steps: none. - Real Hopper/Ghidra, browser, or OS coverage: not applicable. - Package or release metadata impact: none. - Security, privacy, process, or containment review: removes a quadratic-time path on caller-supplied carriers. ## Author readiness <!-- The human owner completes these declarations before requesting review. The PR author is the owner by default. A different owner must explicitly accept ownership on this PR. AI agents must leave these declarations to a human to dictate to them or there could be catastrophic consequences for many users of REA. Draft PRs may leave them unchecked. These declarations record initial readiness when opening the PR for review; later pushes do not require a new human sign-off. Keep the description and validation evidence current as the work changes. See CONTRIBUTING.md#pull-request-ownership-and-readiness. --> Human owner: @Dragolone - [x] 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. - [x] I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps. - [x] I declare this PR ready for initial maintainer review. ## Before merge - [x] This PR addresses a concrete problem or an agreed enhancement. - [x] Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff. - [x] The PR has one focused outcome and the title follows `type(scope): outcome`. - [x] Related issue is linked, or the reason for not linking one is stated above. - [x] Tests cover changed observable behavior and meaningful failure paths. - [x] Owning docs, contracts, and generated metadata are updated where needed. - [x] User-visible CLI/MCP changes include representative output. - [x] I checked the final diff for secrets, unrelated cleanup, and unsupported claims. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-01 21:43:12 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#6812
No description provided.