Skip to content

fix(app): fix package config change crash and harden config handling - #1648

Merged
Admirepowered merged 2 commits into
bmax121:mainfrom
lizehui2025:main
Oct 10, 2026
Merged

Admirepowered merged 2 commits into
bmax121:mainfrom
lizehui2025:main

Conversation

@lizehui2025

Copy link
Copy Markdown
Contributor

Follow-up fixes for the package config rework in #1592:

  • app: open the config lock only after Natives.su(); the lock lives in root-only /data/adb/ap, so opening it before elevation always failed with EACCES and crashed changeConfig; degrade to unlocked on failure
  • app: abort changeConfig when su fails instead of silently doing nothing
  • app: match the CSV header field-by-field; a data row whose package name is literally "pkg" was swallowed by a startsWith("pkg,") check
  • apd: treat 0-byte/blank package_config as a legitimately empty config (touch-created on install, writers are atomic, kernel reads 0 bytes as "no entries") instead of a torn read, which stalled every uid event by 5-10s on fresh installs

Follow-up fixes for the package config rework in bmax121#1592:
- app: open the config lock only after Natives.su(); the lock lives in
  root-only /data/adb/ap, so opening it before elevation always failed
  with EACCES and crashed changeConfig; degrade to unlocked on failure
- app: abort changeConfig when su fails instead of silently doing nothing
- app: match the CSV header field-by-field; a data row whose package name
  is literally "pkg" was swallowed by a startsWith("pkg,") check
- apd: treat 0-byte/blank package_config as a legitimately empty config
  (touch-created on install, writers are atomic, kernel reads 0 bytes as
  "no entries") instead of a torn read, which stalled every uid event by
  5-10s on fresh installs

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The app lock does not coordinate with apd’s writer, allowing concurrent updates to overwrite each other.

1 open finding
What changed in this PR

Hardens package configuration parsing, privilege handling, locking, and empty-config behavior.

Changes:

  • Validates CSV headers field-by-field.
  • Elevates before locking and aborts when elevation fails.
  • Treats blank package configs as valid empty configurations.
File Description
PkgConfig.kt Improves header parsing and privileged lock handling.
package.rs Accepts zero-byte and blank configs as valid empty states.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +126 to +127
val lock = try {
r.channel.lock()
Address review feedback on the package config lock:
- synchronize_package_uid(): take the same fcntl record lock the app
  uses around the whole read-modify-write. Java FileChannel.lock()
  is a POSIX fcntl lock, so flock(2) would not exclude the app;
  fail-open on lock errors, mirroring the app
- write_ap_package_config(): fsync the temp file before rename (the
  app already does), so a crash right after the rename cannot leave
  a truncated config
@Admirepowered
Admirepowered merged commit e78e7b3 into bmax121:main Oct 10, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants