[GH-ISSUE #3683] [Issue]: Profile import can fail after partially overwriting live data and assets #1990

Closed
opened 2026-10-21 05:44:25 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @Xelvanis on GitHub (Jul 16, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3683

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Severity: High — restore integrity / partial failure. A native profile import updates live file-storage rows before it fully reads, decompresses, CRC-checks, and writes the archive assets. If a later asset is corrupt or cannot be written, Marinara reports that the import failed but leaves the earlier row updates and any already-written assets in place.

Expected behavior

A fatal profile-import error should leave the existing profile unchanged, or restore it to its pre-import state. All present archive assets should be validated before live rows or files are modified.

Missing assets may remain an explicit best-effort exception: the documented behavior is to warn and import everything else when an asset is absent.

Actual behavior

importProfileStorageSnapshot() processes the import in this order:

  1. Upsert every row from every file-backed table.
  2. Read and restore assets one by one.
  3. Flush storage only after both phases finish.

Relevant paths on staging:

  • packages/server/src/routes/backup.routes.ts:656-702 mutates every table before asset processing starts.
  • packages/server/src/routes/backup.routes.ts:704-729 reads and writes assets afterward.
  • packages/server/src/routes/backup.routes.ts:1502-1557 preflights ZIP headers and declared sizes, but decompression and CRC validation happen later in readProfileArchiveAsset() / readProfileArchiveEntryBuffer().
  • packages/server/src/routes/backup.routes.ts:2328-2348 reports the later exception as Invalid profile export or Profile import failed without rollback.

File-storage inserts/updates mutate the in-memory tables immediately and schedule debounced persistence, so skipping the final explicit flushDB() does not undo or reliably contain the partial changes. Earlier asset writes are also direct writes to their final paths.

Steps to reproduce

  1. Export a native profile ZIP containing at least one existing row that will be updated on re-import and at least one asset.
  2. Change the live copy of that row so a successful restore would produce an observable update.
  3. Corrupt the archived asset payload while retaining the ZIP entry and its declared size, causing decompression or CRC validation to fail.
  4. Import the corrupted profile ZIP.
  5. Observe that Marinara reports the import as failed.
  6. Inspect the previously changed row and any assets processed before the corrupt entry. The row has already been restored from the archive, and earlier assets may already have been overwritten despite the failure response.

Environment

  • Marinara Engine version: staging at 77f9f2a61e3647cad9f41399430648a00a735210
  • Install type: source
  • OS + version: not OS-specific; identified by source inspection
  • Browser or app shell: n/a

Logs, screenshots, or video

Static source trace; the corrupt-archive scenario was not executed against a live profile.

Additional context

This is distinct from the intentionally tolerant missing-asset behavior added in #1019 and documented in docs/data/backup-and-restore.md: a missing media file produces a warning and successful partial import. A present but corrupt/unreadable asset is instead treated as a fatal error, yet its fatal validation occurs after live data has changed.

This is also distinct from #1250, which covered ST/direct import paths in the former Tauri/refactor implementation.

Smallest safe direction:

  1. Fully read/decompress/CRC-check all present archive assets and validate table inputs before the first mutation.
  2. Stage asset output under a temporary directory rather than writing directly to final paths.
  3. Apply table changes inside a serialized transaction.
  4. Promote staged assets only after validation succeeds; if cross-filesystem atomicity is unavailable, keep an explicit rollback journal.

Tradeoff: preflight requires temporary disk space and delays the first visible import mutation, but avoids leaving a mixed old/new profile after a failed recovery operation.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @Xelvanis on GitHub (Jul 16, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3683 Originally assigned to: @SpicyMarinara on GitHub. ## Summary **Severity: High — restore integrity / partial failure.** A native profile import updates live file-storage rows before it fully reads, decompresses, CRC-checks, and writes the archive assets. If a later asset is corrupt or cannot be written, Marinara reports that the import failed but leaves the earlier row updates and any already-written assets in place. ## Expected behavior A fatal profile-import error should leave the existing profile unchanged, or restore it to its pre-import state. All present archive assets should be validated before live rows or files are modified. Missing assets may remain an explicit best-effort exception: the documented behavior is to warn and import everything else when an asset is absent. ## Actual behavior `importProfileStorageSnapshot()` processes the import in this order: 1. Upsert every row from every file-backed table. 2. Read and restore assets one by one. 3. Flush storage only after both phases finish. Relevant paths on `staging`: - `packages/server/src/routes/backup.routes.ts:656-702` mutates every table before asset processing starts. - `packages/server/src/routes/backup.routes.ts:704-729` reads and writes assets afterward. - `packages/server/src/routes/backup.routes.ts:1502-1557` preflights ZIP headers and declared sizes, but decompression and CRC validation happen later in `readProfileArchiveAsset()` / `readProfileArchiveEntryBuffer()`. - `packages/server/src/routes/backup.routes.ts:2328-2348` reports the later exception as `Invalid profile export` or `Profile import failed` without rollback. File-storage inserts/updates mutate the in-memory tables immediately and schedule debounced persistence, so skipping the final explicit `flushDB()` does not undo or reliably contain the partial changes. Earlier asset writes are also direct writes to their final paths. ## Steps to reproduce 1. Export a native profile ZIP containing at least one existing row that will be updated on re-import and at least one asset. 2. Change the live copy of that row so a successful restore would produce an observable update. 3. Corrupt the archived asset payload while retaining the ZIP entry and its declared size, causing decompression or CRC validation to fail. 4. Import the corrupted profile ZIP. 5. Observe that Marinara reports the import as failed. 6. Inspect the previously changed row and any assets processed before the corrupt entry. The row has already been restored from the archive, and earlier assets may already have been overwritten despite the failure response. ## Environment - Marinara Engine version: `staging` at `77f9f2a61e3647cad9f41399430648a00a735210` - Install type: source - OS + version: not OS-specific; identified by source inspection - Browser or app shell: n/a ## Logs, screenshots, or video Static source trace; the corrupt-archive scenario was not executed against a live profile. ## Additional context This is distinct from the intentionally tolerant missing-asset behavior added in #1019 and documented in `docs/data/backup-and-restore.md`: a missing media file produces a warning and successful partial import. A present but corrupt/unreadable asset is instead treated as a fatal error, yet its fatal validation occurs after live data has changed. This is also distinct from #1250, which covered ST/direct import paths in the former Tauri/refactor implementation. Smallest safe direction: 1. Fully read/decompress/CRC-check all present archive assets and validate table inputs before the first mutation. 2. Stage asset output under a temporary directory rather than writing directly to final paths. 3. Apply table changes inside a serialized transaction. 4. Promote staged assets only after validation succeeds; if cross-filesystem atomicity is unavailable, keep an explicit rollback journal. Tradeoff: preflight requires temporary disk space and delays the first visible import mutation, but avoids leaving a mixed old/new profile after a failed recovery operation. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:44:25 +07:00
  • closed this issue
  • added the
    in-pr
    label
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
Pasta-Devs/Marinara-Engine#1990
No description provided.