Skip to content

fix(apktool): treat an EPERM launcher spawn as not executable - #5180

Closed
Yi-111-a wants to merge 6 commits into
morluto:mainfrom
Yi-111-a:fix/apktool-executable-permission
Closed

Yi-111-a wants to merge 6 commits into
morluto:mainfrom
Yi-111-a:fix/apktool-executable-permission

Conversation

@Yi-111-a

@Yi-111-a Yi-111-a commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #5177.

Problem

versionProbeFailure collapsed ENOENT and EACCES into one
command_missing failure. A launcher that exists but is not executable for
the current user therefore reported "was not found" with remediation telling
the caller to point REA_APKTOOL_COMMAND at a different launcher. After the
EACCES handling landed in main, EPERM — the other errno a refused exec can
surface (for example a launcher blocked by an operating-system security
policy) — still had no dedicated outcome.

Approach

The branch is narrowed to exactly that remaining permission outcome, per the
2026-10-26 review. It now merges current main and keeps main's EACCES
branch structure, message wording and APKTOOL_NOT_EXECUTABLE_REMEDIATION /
APKTOOL_MISSING_REMEDIATION constants byte-for-byte; the only source change
is that the launcher-spawn failure matcher accepts EPERM alongside
ENOENT/EACCES, with EPERM taking the same command_not_executable,
"Execution of the selected apktool launcher was denied" path as EACCES. A
short comment records why EPERM is a permission failure rather than a
missing launcher, as in the report.

ProviderRejectionCode is unchanged; no public tool schema or catalog
contract is widened. Refusal behavior is unchanged — only the diagnosis and
recovery advice differ.

Validation

npx vitest run src/apktool/ApktoolVersionProbe.test.ts src/apktool/ApktoolConfiguration.test.ts
 Test Files  2 passed (2)
      Tests  77 passed (77)

New regression: one added row in the existing distinguishes launcher spawn it.each (["EPERM", "command_not_executable"]), asserting EPERM maps to
the same denial outcome as EACCES and never to command_missing. The
EACCES/ENOENT rows are main's, unchanged. Ran on Linux (Node v20.19.2;
the pinned .nvmrc 24.22.1 toolchain is not installed in this sandbox, tests
are unaffected).

Coverage limits: the head was exercised on Linux; macOS arm64 and Windows
were not re-run. EPERM is covered by the shared branch rather than a
separate fixture. Real Apktool/JVM decoding is not involved — the launcher is
an inert stub, as in the report. The earlier EACCES report is recorded in
#5177; no native EPERM reproduction is available locally.

Author readiness

Unchecked for the human owner to complete.

versionProbeFailure mapped both ENOENT and EACCES to command_missing, so a
selected launcher that exists but is not executable reported
executable_missing with "was not found" and advice to point
REA_APKTOOL_COMMAND somewhere else. The errno survived on the cause but
never reached the projected availability reason or diagnostics.

Split the two: ENOENT keeps the missing-launcher diagnosis, while EACCES
and EPERM become command_unresolved with a permission reason, the
filesystem_error, and execute-access remediation - the same treatment the
Windows PATH inspection already applies to an unreadable candidate.
@morluto

morluto commented Oct 26, 2026

Copy link
Copy Markdown
Owner

Thank you for separating launcher permission failures from missing paths. Main now handles the reported EACCES case and #5177 records a public CLI/provider replay. This PR also proposes handling EPERM; main’s versionProbeFailure branch at ca3fd7b recognizes ENOENT and EACCES but does not explicitly include EPERM. I am keeping it open for that distinct case. If you would like to continue, could you narrow the change and coverage around the remaining permission outcome? I have not reproduced native EPERM in this pass.

Merge current main, which already reports EACCES as command_not_executable,
and narrow this change to the remaining permission outcome: EPERM, which a
refused exec can surface (for example a noexec mount or a security policy),
now maps to command_not_executable instead of falling through to
version_unresolved. The earlier provider-level test is dropped in favour of
an EPERM case in the existing launcher-spawn table.
@Yi-111-a Yi-111-a changed the title fix(apktool): keep a refused launcher's permission failure distinct fix(apktool): treat an EPERM launcher spawn as not executable Oct 28, 2026
@Yi-111-a

Yi-111-a commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks @morluto, narrowed in 6d2f3af (merged current main, no force-push), plus a comment-only follow-up in 8dcaee2. The PR now only touches the remaining case:

  • versionProbeFailure also accepts EPERM and maps it to command_not_executable with the same message and remediation as EACCES; ENOENT stays command_missing. Without this, an EPERM spawn falls through to version_unresolved.
  • Coverage is one more row, ["EPERM", "command_not_executable"], in the existing distinguishes launcher spawn %s table in ApktoolVersionProbe.test.ts. I dropped my earlier chmod 0o644 provider test since main now covers EACCES.

Diff against main is 2 files. Like you, I haven't reproduced a native EPERM (it's what an exec blocked by an OS security policy can return, rather than a plain mode-bit denial), so the test mocks the spawn rejection the same way the EACCES row does. I couldn't run the suite locally this time, so CI is the check here.

A noexec mount refuses exec with EACCES, not EPERM.
@greptile-apps

greptile-apps Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge; no blocking issues were found.

Summary

The PR reports launcher spawn error EPERM as command_not_executable, using the same message and recovery advice as EACCES.

  • Apktool version checks report denied launcher starts as non-executable.

Reviews (3) · Last reviewed commit: "style(apktool): wrap the launcher errno ..." · Reviewed by Greptile

Narrow the change to the one permission outcome main's versionProbeFailure
still misses: keep main's EACCES structure, remediation constants and
message wording, and have EPERM take the same command_not_executable path
plus the single EPERM row in the spawn-errno test.
@Yi-111-a

Yi-111-a commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @morluto — narrowed per the review, on top of a merge of current main (db9b6dac9790c58c6633cdb2a68293fe591d0b14, no force-push):

  1. Scope: the EACCES diagnosis now matches main exactly (the systemErrorCode helper, the re-ordered ENOENT-first ternaries and the inline remediation strings are gone). The only source change left is the launcher-spawn matcher accepting EPERM, which takes main's command_not_executable / "denied" path unchanged; the PR body now states that scope in its Approach section.
  2. Coverage: one added row in main's distinguishes launcher spawn it.each (["EPERM", "command_not_executable"]). The EACCES/ENOENT rows are main's, untouched. I did not add a Windows/native EPERM fixture since I still cannot reproduce it — noted in the body's coverage limits.
  3. Validation: npx vitest run src/apktool/ApktoolVersionProbe.test.ts src/apktool/ApktoolConfiguration.test.ts — 2 files, 77/77 passed on Linux (Node v20.19.2; the pinned 24.22.1 toolchain from .nvmrc is not available in this sandbox, so npm run check:fast could not run).

@CassieFox23

Copy link
Copy Markdown
Contributor

TL;DR: I ran the PR's test file on draft head edb61d6 with Node 22, 24 and 26, and all 11 tests passed on each. With the fix removed, the new test distinguishes launcher spawn EPERM failed and no other test changed result. I did not test a real EPERM or a merge with current main.

Check Node 22.23.4 Node 24.22.1 Node 26.12.1
Head edb61d6 pass: 1 file, 11 tests pass: 1 file, 11 tests pass: 1 file, 11 tests
Red run (fix removed) fail: 1 test failed, 10 passed fail: 1 test failed, 10 passed fail: 1 test failed, 10 passed
  • The red run is head edb61d6 with src/apktool/ApktoolConfiguration.ts swapped back to merge base 2ac6d3e.
  • The one failure on all three Node versions is distinguishes launcher spawn EPERM.
  • So that test fails without the fix and passes with it.
  • No other test in src/apktool/ApktoolVersionProbe.test.ts changes result.
  • On edb61d6, all 22 check runs that ran passed, including CI required, Static checks, Source tests and Portable tests.
  • CodeQL production was skipped.
  • The PR readiness workflow passed, but its commit status is pending, and GitHub's merge state is unstable.
  • The head is 363 commits behind main b81da90. GitHub says the PR is mergeable.

Not run

  • A real EPERM from an apktool launcher on a locked-down host.
  • A merge with current main, b81da90.
Test setup
  • Box: Fedora 44 VM (4 vCPUs, 8 GB) on my Nobara 44 PC, Linux 7.2.11
  • Node: 22.23.4, 24.22.1, 26.12.1
  • Head / base: edb61d6 / 2ac6d3e (merge base with main)
  • Red run: edb61d6 with src/apktool/ApktoolConfiguration.ts from 2ac6d3e
  • Install: npm ci --offline and npm run test:prepare on Node 24.22.1, exit 0, for both trees
Commands
npm ci --offline
npm run test:prepare
xvfb-run -a npm run test:focused -- src/apktool/ApktoolVersionProbe.test.ts

🤖 Written and tested with Claude Code (Sonnet 5.5, verified by Opus 5.5), posted with my OK 🦊

N0zoM1z0 pushed a commit that referenced this pull request Nov 14, 2026
A launcher whose exec is refused by an operating-system security policy
surfaces EPERM, not EACCES. It was reported as a missing launcher, so
the recovery pointed at installing apktool instead of fixing execute
permission. EPERM now joins EACCES as command_not_executable.

Squashed from #5180 and rebased onto main.

Supersedes #5180 (follow-up to #5177)

Co-Authored-By: gensokyo-dev <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@N0zoM1z0

Copy link
Copy Markdown
Collaborator

Thanks! This landed on main in #10490 as its own commit, cherry-picked with your authorship kept (rebase merge). Closing in favor of that merge.

@N0zoM1z0 N0zoM1z0 closed this Nov 14, 2026
@morluto morluto added bug Something isn't working provider: apktool Analysis provider / engine: apktool labels Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working provider: apktool Analysis provider / engine: apktool

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Apktool reports an existing non-executable launcher as missing

6 participants