[PR #7470] fix(adb)!: reject malformed package numeric tokens #7859

Open
opened 2026-11-05 01:48:11 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/7470
Author: @kittimzhe
Created: 10/27/2026
Status: 🔄 Open

Base: main ← Head: fix/adb-attached-letter-ids


📝 Commits (2)

  • c3b54d1 fix(adb): reject package ids with attached text instead of admitting the prefix
  • 552afbc fix(adb)!: preserve malformed version declarations

📊 Changes

5 files changed (+169 additions, -12 deletions)

View changed files

📝 docs/adb-device-analysis.md (+3 -1)
📝 src/adb/AdbShellOutput.test.ts (+37 -0)
📝 src/adb/AdbShellOutput.ts (+14 -4)
📝 src/domain/adb/adbDeviceAnalysis.ts (+15 -7)
📝 tests/acceptance/applications/adbNumericDeclarations.test.ts (+100 -0)

📄 Description

Summary

inspect_adb_package admitted the leading digit run of a userId/appId declaration, so userId=10123abc became user_id: 10123 with no numeric issue and complete coverage, and a malformed declaration before a valid one could decide which id the caller received. The decimal id must now end its token; attached text makes the declaration an invalid_format numeric issue with its original line, and package coverage becomes partial. Fixes #7409.

Problem and expected behavior

Smallest trigger: a dumpsys package section whose only id declaration is userId=10123abc.

Violated invariant: docs/adb-device-analysis.md ("Interpret the result") — malformed declarations before or after a valid value remain in numeric_issues, any issue makes package coverage partial, and user_id is the first valid declaration. parseDumpsysPackageOutput matched ^(\d+) and passed only the digits to the safe-integer check, so the attached text was lost before the validity decision.

Expected: userId=10123abc alone → user_id: null, one invalid_format issue with the original line, coverage partial. With a valid userId=10456 also present → user_id: 10456, the malformed lines retained as issues, coverage partial.

Change and scope

  • src/adb/AdbShellOutput.ts: the id pattern requires the digits to end their token (^(\d+)(?:\s|$)). Whitespace-separated suffixes such as userId=10001 installing=true stay admitted exactly as before; non-numeric, negative and unsafe declarations keep their current reasons.
  • tests/acceptance/applications/adbNumericDeclarations.test.ts: two scenarios in the existing CLI + MCP table — attached text as the only declaration, and attached text on both sides of a valid declaration across both spellings.
  • Not included: no change to first-valid selection for well-formed declarations or to other dumpsys fields.

Follow the contribution scope.
Unresolved scope, authority, side effects, or required verification block
integration. Link the required maintainer scope decision for new providers or
capabilities involving target execution, injection, mutation, or protection
recovery; ordinary fixes within existing boundaries may state "not applicable".
Draft PRs may leave the scope decision pending and the readiness and merge checklists
unchecked. Maintainers can help resolve open questions.

Contract and boundary impact

  • Semantic owner and earliest changed stage: parseDumpsysPackageOutput, the single parser of Package Manager id declarations; AdbProvider projects its parsed facts unchanged. No superseded path.
  • Contribution scope fit and linked maintainer decision: ordinary fix within the existing parser boundary — not applicable.
  • CLI and MCP/tool-catalog contract: such declarations now appear in numeric_issues (invalid_format) and make coverage partial instead of yielding a prefix id. No schema or tool-catalog change.
  • Provider, bridge, target-format, or platform compatibility: none; the accepted grammar for well-formed declarations is unchanged.
  • Evidence, artifact, provenance, or reconstruction contract: the original raw_line is retained in the issue.
  • 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: two scenarios in tests/acceptance/applications/adbNumericDeclarations.test.ts, run through both CLI and MCP.
  • Base reproduction or other evidence: executed. With the parser change stashed, the new scenario fails on user_id (expected null, received 10123).
  • User-visible CLI/MCP output (if applicable): userId=10123abc alone → user_id: null, numeric_issues.total: 1 (invalid_format, original line), coverage: partial.
  • Remaining proof gaps: synthetic dumpsys text through the existing adb stand-in fixture only; no real Android device or emulator, and no real-device occurrence of the attached-letter shape is claimed.

Boundary regressions covered: malformed-input parsing and first-valid selection with issues on both sides. Lifecycle regressions: not applicable (no new resources).

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

  • npm run test:focused -- tests/acceptance/applications/adbNumericDeclarations.test.ts src/adb/AdbShellOutput.test.ts src/adb/AdbProvider.test.ts — 151 passed.
  • npm run check:fast — passed.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. Output that previously admitted a digit prefix now reports user_id: null or the next valid id, with partial coverage.
  • Real Hopper/Ghidra, browser, or OS coverage: none; no real Android device.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: none.

Version-code follow-up

The same parser now rejects attached text in versionCode (#7534), preserving the first valid signed decimal token exactly and recording malformed lines as version_code numeric issues. This adds a field variant to the output schema and changes malformed-output coverage, so exhaustive consumers need to handle it.

Validation on the updated branch: 48 parser and built CLI/MCP tests passed, including malformed declarations before and after a valid large signed value; check:fast and git diff --check passed. The adb responses are fixtures; no real device was tested.

Author readiness

Human owner: @kittimzhe

  • 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/7470 **Author:** [@kittimzhe](https://github.com/kittimzhe) **Created:** 10/27/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/adb-attached-letter-ids` --- ### 📝 Commits (2) - [`c3b54d1`](https://github.com/morluto/rea/commit/c3b54d1b12101208d9deddafa2bc7ee8056f873c) fix(adb): reject package ids with attached text instead of admitting the prefix - [`552afbc`](https://github.com/morluto/rea/commit/552afbc42604ee082bbc56727f19af9e68f2bb72) fix(adb)!: preserve malformed version declarations ### 📊 Changes **5 files changed** (+169 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `docs/adb-device-analysis.md` (+3 -1) 📝 `src/adb/AdbShellOutput.test.ts` (+37 -0) 📝 `src/adb/AdbShellOutput.ts` (+14 -4) 📝 `src/domain/adb/adbDeviceAnalysis.ts` (+15 -7) 📝 `tests/acceptance/applications/adbNumericDeclarations.test.ts` (+100 -0) </details> ### 📄 Description ## Summary `inspect_adb_package` admitted the leading digit run of a `userId`/`appId` declaration, so `userId=10123abc` became `user_id: 10123` with no numeric issue and complete coverage, and a malformed declaration before a valid one could decide which id the caller received. The decimal id must now end its token; attached text makes the declaration an `invalid_format` numeric issue with its original line, and package coverage becomes partial. Fixes #7409. ## Problem and expected behavior Smallest trigger: a `dumpsys package` section whose only id declaration is `userId=10123abc`. Violated invariant: `docs/adb-device-analysis.md` ("Interpret the result") — malformed declarations before or after a valid value remain in `numeric_issues`, any issue makes package coverage partial, and `user_id` is the first *valid* declaration. `parseDumpsysPackageOutput` matched `^(\d+)` and passed only the digits to the safe-integer check, so the attached text was lost before the validity decision. Expected: `userId=10123abc` alone → `user_id: null`, one `invalid_format` issue with the original line, coverage partial. With a valid `userId=10456` also present → `user_id: 10456`, the malformed lines retained as issues, coverage partial. ## Change and scope - `src/adb/AdbShellOutput.ts`: the id pattern requires the digits to end their token (`^(\d+)(?:\s|$)`). Whitespace-separated suffixes such as `userId=10001 installing=true` stay admitted exactly as before; non-numeric, negative and unsafe declarations keep their current reasons. - `tests/acceptance/applications/adbNumericDeclarations.test.ts`: two scenarios in the existing CLI + MCP table — attached text as the only declaration, and attached text on both sides of a valid declaration across both spellings. - Not included: no change to first-valid selection for well-formed declarations or to other `dumpsys` fields. Follow the [contribution scope](https://github.com/morluto/rea/blob/main/CONTRIBUTING.md#contribution-scope). Unresolved scope, authority, side effects, or required verification block integration. Link the required maintainer scope decision for new providers or capabilities involving target execution, injection, mutation, or protection recovery; ordinary fixes within existing boundaries may state "not applicable". Draft PRs may leave the scope decision pending and the readiness and merge checklists unchecked. Maintainers can help resolve open questions. ## Contract and boundary impact - Semantic owner and earliest changed stage: `parseDumpsysPackageOutput`, the single parser of Package Manager id declarations; `AdbProvider` projects its parsed facts unchanged. No superseded path. - Contribution scope fit and linked maintainer decision: ordinary fix within the existing parser boundary — not applicable. - CLI and MCP/tool-catalog contract: such declarations now appear in `numeric_issues` (`invalid_format`) and make `coverage` partial instead of yielding a prefix id. No schema or tool-catalog change. - Provider, bridge, target-format, or platform compatibility: none; the accepted grammar for well-formed declarations is unchanged. - Evidence, artifact, provenance, or reconstruction contract: the original `raw_line` is retained in the issue. - 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: two scenarios in `tests/acceptance/applications/adbNumericDeclarations.test.ts`, run through both CLI and MCP. - Base reproduction or other evidence: executed. With the parser change stashed, the new scenario fails on `user_id` (expected `null`, received `10123`). - User-visible CLI/MCP output (if applicable): `userId=10123abc` alone → `user_id: null`, `numeric_issues.total: 1` (`invalid_format`, original line), `coverage: partial`. - Remaining proof gaps: synthetic `dumpsys` text through the existing adb stand-in fixture only; no real Android device or emulator, and no real-device occurrence of the attached-letter shape is claimed. Boundary regressions covered: malformed-input parsing and first-valid selection with issues on both sides. Lifecycle regressions: not applicable (no new resources). 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 - `npm run test:focused -- tests/acceptance/applications/adbNumericDeclarations.test.ts src/adb/AdbShellOutput.test.ts src/adb/AdbProvider.test.ts` — 151 passed. - `npm run check:fast` — passed. ## Compatibility, safety, and release - Breaking changes or migration steps: none. Output that previously admitted a digit prefix now reports `user_id: null` or the next valid id, with partial coverage. - Real Hopper/Ghidra, browser, or OS coverage: none; no real Android device. - Package or release metadata impact: none. - Security, privacy, process, or containment review: none. ## Version-code follow-up The same parser now rejects attached text in `versionCode` (#7534), preserving the first valid signed decimal token exactly and recording malformed lines as `version_code` numeric issues. This adds a field variant to the output schema and changes malformed-output coverage, so exhaustive consumers need to handle it. Validation on the updated branch: 48 parser and built CLI/MCP tests passed, including malformed declarations before and after a valid large signed value; `check:fast` and `git diff --check` passed. The adb responses are fixtures; no real device was tested. ## Author readiness Human owner: @kittimzhe - [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 - [ ] 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#7859
No description provided.