Skip to content

worker: harden archive member validation on restore - #16

Draft
ash-iir wants to merge 1 commit into
mainfrom
fix-tar-member-scope
Draft

ash-iir wants to merge 1 commit into
mainfrom
fix-tar-member-scope

Conversation

@ash-iir

@ash-iir ash-iir commented Nov 19, 2026

Copy link
Copy Markdown
Owner

App archives are extracted into a shared parent directory (/data/user/<u>, /data/user_de/<u>, Android/data|obb|media, /data/misc/profiles). This tightens the pre-extraction member check so every member must stay under the app's own top-level entry.

  • scan_members [<base>...]: besides the existing absolute-path and .. check, when bases are given each member must be <base> or <base>/... (a leading ./ is accepted).
  • archive_safe <archive> <enc> [<base>...] passes the bases through.
  • App restore and restore-test: $PKG for data, data_de, external, obb and media; ref/$PKG and cur/$U/$PKG for profiles. These match how archive_dir (-C "$(dirname src)" -c "$PKG") and archive_profiles (-C /data/misc/profiles -c ref/$PKG cur/$U/$PKG) create them.
  • DataBackup import (db_item): $PKG, matching its <pkg>/... layout.
  • Unchanged: Neo import (extracts into the package dir itself, ./-relative), DataBackup apk archive (temp dir), special, path and adb restores (their own guards).

Overlaps the archive_safe/list_safe change in #2; whichever merges second needs a small rebase.

Testing

  • sh -n, mksh -n, busybox sh -n on worker.sh; shellcheck -s sh: no new warnings (96 before and after).
  • scan_members/archive_safe extracted and run under mksh R59, busybox 1.37 ash and dash, with GNU tar 1.35 and busybox tar listings, on 12 hand-built archives (own app only, extra sibling app dir, name-prefix sibling, ./-relative, ./<pkg>, profile members for another package, whole ref/, plain and gzip). All expected results with GNU tar; with busybox tar one pre-existing no-base case differs because busybox normalises names in tar -t (the base check still rejects that archive).
  • Not tested on a rooted device.

App archives are extracted into a shared parent directory (the user's
data dir, Android/data, the profiles dir). Validate that every member of
such an archive stays under the app's own top-level entry before it is
extracted: <pkg> for data, data_de, external, obb and media archives,
ref/<pkg> and cur/<user>/<pkg> for ART profiles. The same check is used
by restore-test and the DataBackup import. Archives without a base keep
the existing absolute-path and '..' check.

Signed-off-by: ash-iir <254348575+ash-iir@users.noreply.github.com>
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.

1 participant