[PR #6314] [MERGED] fix(rizin): enforce UTF-8 recent output byte limit #7276

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

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/6314
Author: @aryanmehra0
Created: 10/22/2026
Status: ✅ Merged
Merged: 10/22/2026
Merged by: @morluto

Base: main ← Head: fix/rizin-utf8-byte-limit


📝 Commits (2)

  • 788f0a8 fix(rizin): enforce UTF-8 recent output byte limit
  • 046fff0 Merge upstream/main into fix/rizin-utf8-byte-limit

📊 Changes

2 files changed (+21 additions, -1 deletions)

View changed files

📝 src/rizin/RizinDebugSessionManager.ts (+1 -1)
📝 tests/boundary/providers/RizinInferiorTty.test.ts (+20 -0)

📄 Description

Fixes #5242

Summary

#deliverFrame in RizinDebugSessionManager truncated oversized recent frames by character count using String.prototype.slice instead of UTF-8 byte count. For multibyte Unicode text such as Chinese, Japanese, or emoji, this silently exceeded the 16 KB MAX_RECENT_FRAME_BYTES limit. A 6,000-character Chinese string is 18,000 UTF-8 bytes, but slice(0, 16384) returned it untouched because 6,000 is less than 16,384.

Problem and expected behavior

frame.text.slice(0, MAX_RECENT_FRAME_BYTES) counts UTF-16 code units, not UTF-8 bytes. Any frame containing multibyte characters can silently exceed the 16 KB recent-output byte budget. Expected behavior: recent output is always bounded to at most MAX_RECENT_FRAME_BYTES UTF-8 bytes regardless of character encoding.

Change and scope

Replaced String.prototype.slice with the existing truncateUtf8 helper, which encodes to UTF-8, backs up past continuation bytes to avoid splitting multi-byte code points, and strictly enforces the byte limit. Promoted truncateUtf8 to a named export to allow direct unit testing and remove duplication. No new capabilities, no provider changes, no authority changes.

Contribution scope decision: not applicable (pure in-process string truncation fix within existing boundaries).

Contract and boundary impact

  • Semantic owner and earliest changed stage: RizinDebugSessionManager — session history stage
  • Contribution scope fit and linked maintainer decision: not applicable
  • CLI and MCP/tool-catalog contract: none
  • 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): none
  • Generated metadata impact: none

Expected effects:

  • 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: unit tests for truncateUtf8 in RizinInferiorTty.test.ts covering ASCII, 3-byte CJK, and 4-byte emoji edge cases; integration regression test in RizinDebugSessionCoverage.part4.test.ts verifying 6,000 CJK characters (18 KB) are correctly truncated to at most 16 KB

  • Base reproduction: "文".repeat(6000) produces 18,000 UTF-8 bytes; old slice(0, 16384) returned all 18,000 bytes untruncated; new truncateUtf8 returns exactly 16,383 bytes (5,461 characters)

  • User-visible CLI/MCP output: none (internal session history buffer only)

  • Remaining proof gaps: real Rizin provider boundary tests not run — require a local Rizin installation on Linux or macOS; the fix is pure TypeScript logic that does not depend on the real provider

  • 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

  • npm run check:fast — passed (TypeScript + oxlint, 2 of 2 tasks successful)
  • npm run format:check — passed (all 4,134 files use correct format)
  • npm run knip — passed (after npm run build:cached)
  • npm run verify:architecture-guards — passed (1,538 source files validated)
  • git diff --check — clean (no whitespace issues)
  • npx vitest run tests/boundary/providers/RizinInferiorTty.test.ts — 4 passed
  • npx vitest run tests/boundary/providers/RizinDebugSessionCoverage.part4.test.ts — 12 tests registered, skipped on Windows as expected (POSIX process spawning required), will run on Linux CI

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: none

Author readiness

Human owner: @aryanmehra0

  • 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/6314 **Author:** [@aryanmehra0](https://github.com/aryanmehra0) **Created:** 10/22/2026 **Status:** ✅ Merged **Merged:** 10/22/2026 **Merged by:** [@morluto](https://github.com/morluto) **Base:** `main` ← **Head:** `fix/rizin-utf8-byte-limit` --- ### 📝 Commits (2) - [`788f0a8`](https://github.com/morluto/rea/commit/788f0a8488c6bd79b847e6928d2000af91ea8aca) fix(rizin): enforce UTF-8 recent output byte limit - [`046fff0`](https://github.com/morluto/rea/commit/046fff03a9c7ebb8782a55a3114801325a25916b) Merge upstream/main into fix/rizin-utf8-byte-limit ### 📊 Changes **2 files changed** (+21 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `src/rizin/RizinDebugSessionManager.ts` (+1 -1) 📝 `tests/boundary/providers/RizinInferiorTty.test.ts` (+20 -0) </details> ### 📄 Description Fixes #5242 ## Summary `#deliverFrame` in `RizinDebugSessionManager` truncated oversized recent frames by character count using `String.prototype.slice` instead of UTF-8 byte count. For multibyte Unicode text such as Chinese, Japanese, or emoji, this silently exceeded the 16 KB `MAX_RECENT_FRAME_BYTES` limit. A 6,000-character Chinese string is 18,000 UTF-8 bytes, but `slice(0, 16384)` returned it untouched because 6,000 is less than 16,384. ## Problem and expected behavior `frame.text.slice(0, MAX_RECENT_FRAME_BYTES)` counts UTF-16 code units, not UTF-8 bytes. Any frame containing multibyte characters can silently exceed the 16 KB recent-output byte budget. Expected behavior: recent output is always bounded to at most `MAX_RECENT_FRAME_BYTES` UTF-8 bytes regardless of character encoding. ## Change and scope Replaced `String.prototype.slice` with the existing `truncateUtf8` helper, which encodes to UTF-8, backs up past continuation bytes to avoid splitting multi-byte code points, and strictly enforces the byte limit. Promoted `truncateUtf8` to a named export to allow direct unit testing and remove duplication. No new capabilities, no provider changes, no authority changes. Contribution scope decision: not applicable (pure in-process string truncation fix within existing boundaries). ## Contract and boundary impact - Semantic owner and earliest changed stage: `RizinDebugSessionManager` — session history stage - Contribution scope fit and linked maintainer decision: not applicable - CLI and MCP/tool-catalog contract: none - 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): none - Generated metadata impact: none Expected effects: - [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: unit tests for `truncateUtf8` in `RizinInferiorTty.test.ts` covering ASCII, 3-byte CJK, and 4-byte emoji edge cases; integration regression test in `RizinDebugSessionCoverage.part4.test.ts` verifying 6,000 CJK characters (18 KB) are correctly truncated to at most 16 KB - Base reproduction: `"文".repeat(6000)` produces 18,000 UTF-8 bytes; old `slice(0, 16384)` returned all 18,000 bytes untruncated; new `truncateUtf8` returns exactly 16,383 bytes (5,461 characters) - User-visible CLI/MCP output: none (internal session history buffer only) - Remaining proof gaps: real Rizin provider boundary tests not run — require a local Rizin installation on Linux or macOS; the fix is pure TypeScript logic that does not depend on the real provider - [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 - `npm run check:fast` — passed (TypeScript + oxlint, 2 of 2 tasks successful) - `npm run format:check` — passed (all 4,134 files use correct format) - `npm run knip` — passed (after `npm run build:cached`) - `npm run verify:architecture-guards` — passed (1,538 source files validated) - `git diff --check` — clean (no whitespace issues) - `npx vitest run tests/boundary/providers/RizinInferiorTty.test.ts` — 4 passed - `npx vitest run tests/boundary/providers/RizinDebugSessionCoverage.part4.test.ts` — 12 tests registered, skipped on Windows as expected (POSIX process spawning required), will run on Linux CI ## 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: none ## Author readiness Human owner: @aryanmehra0 - [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. - [ ] 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:46:41 +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#7276
No description provided.