Skip to content

worker: stop restores from wiping data they cannot restore - #2

Draft
ash-iir wants to merge 2 commits into
mainfrom
fix-restore-data-loss
Draft

ash-iir wants to merge 2 commits into
mainfrom
fix-restore-data-loss

Conversation

@ash-iir

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

Copy link
Copy Markdown
Owner

Fixes three cases where a restore or a finishing op deletes data it should not.

Encrypted special restore (SMS, contacts, calendar, Wi-Fi, Bluetooth): the decrypted stream went into decomp, which reads its file argument and ignores stdin, so tar got no input after the live data was already removed. New decomp_in decompresses stdin and picks the codec by filename; archive_safe reuses it.

Restore guard: archive_safe only checked member paths. A listing that failed or came back empty (wrong passphrase, unreadable archive) passed, and the target was wiped before extraction failed. list_safe now also requires tar -t to succeed and list at least one member. The Neo import check uses it too.

cleanup(): removed staging/*$OPID*, so op op-1 also removed staging files of running op-10/op-11. Now matches *.$OPID and *.$OPID.*, which covers every staging name in worker.sh.

Testing

  • sh -n on worker.sh.
  • list_safe under mksh and busybox sh: valid tar accepted; empty and garbage input rejected.
  • decomp_in with a zstd stream under mksh and busybox sh.
  • cleanup glob: op-1 removes its own files and leaves op-10/op-11.
  • Not tested on a rooted device.

Known limits

  • A tar truncated exactly at a block boundary can still list cleanly; the compressed formats usually fail earlier.
  • A wrong passphrase now ends as ERR_UNSAFE_ARCHIVE rather than a passphrase error.

- Encrypted special restore piped the decrypted stream into decomp, which
  reads its file argument and ignores stdin, so tar got no input after the
  live data was already removed. Add decomp_in (stdin, codec by filename)
  and use it there and in archive_safe.
- archive_safe only checked member paths, so a listing that failed or was
  empty (wrong passphrase, unreadable archive) passed and the target was
  wiped before extraction failed. list_safe now also requires tar -t to
  succeed and list at least one member; the Neo import check uses it too.
- cleanup() removed staging files matching *$OPID*, so op-1 also removed
  op-10/op-11 files of running workers. Match .$OPID and .$OPID.* only.

Signed-off-by: ash-iir <254348575+ash-iir@users.noreply.github.com>
Under mksh printf is an external command, so a large listing passed as
one argument hit ARG_MAX, printf failed and scan_members read an empty
stdin and returned 0. Read the listing from a here-doc instead, and fail
on an empty listing directly.

Signed-off-by: ash-iir <254348575+ash-iir@users.noreply.github.com>
@ash-iir

ash-iir commented Nov 19, 2026

Copy link
Copy Markdown
Owner Author

Follow-up commit: list_safe now gives the listing to scan_members through a here-doc instead of printf '%s\n' "$_ls" |. Under mksh printf is external, so a listing above ARG_MAX (tested with 30,000 members) made printf fail, and scan_members then read nothing and returned 0. With the here-doc the same archive is checked fully under mksh, busybox ash and dash. Not tested on a rooted device.

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