mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #728] [Issue]: File-native recovery can overwrite a valid .bak with corrupt JSON #347
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#347
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @NeoKazuya on GitHub (May 12, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/728
Summary
File-native storage currently uses matching
.bakfiles to recover corrupted table and manifest JSON. If the primary file is malformed but still contains ordinary bytes (for example, after a truncated write or manual edit), Marinara completes the recovery from.bak, but the repair save also overwrites the valid.bakwith the corrupt file it just recovered from.The result is that the main file looks fixed, but the fallback backup is no longer usable until a later normal save refreshes it.
Expected behavior
After Marinara recovers a table or manifest from
.bak, the repair write should keep that known-good.bakin place while the main file is being repaired.Actual behavior
If
tables/<name>.jsonormanifest.jsoncontains malformed JSON that is not NUL-filled, such as a truncated file containing{"id":, Marinara currently recovers from.bakand marks the file for rewrite.On the next flush,
atomicWriteFile()sees that the primary file exists and is not NUL-filled, so it refreshes.bakfrom that still-corrupt primary before writing the recovered data back to the main file.After a successful repair, the main file is valid again, but
.bakcan contain the old malformed JSON.Steps to reproduce
tables/chats.jsoncontaining{"id":.tables/chats.json.bak, for example[].FILE_STORAGE_DIRpointed at that storage directory..bak, then close Marinara or otherwise let file-native storage flush.Observed on current
main:The primary was repaired, but the valid backup was replaced with malformed JSON.
The same pattern reproduces with
manifest.json:Environment
mainated0285f52011f3e89e87263a76c6b2168d2e8827Logs, screenshots, or video
Startup logs show the expected recovery path:
After startup and flush, the files were:
Control checks showed the existing NUL/empty guard still works: when the primary starts with NUL bytes or is empty, the main file is repaired and
.bakremains parseable.Additional context
This is a narrow follow-up to #631 / #634.
#634 made
.bakrefresh durable and skips backup refresh when the existing primary is NUL-filled or empty. This remaining case is a malformed primary that starts with printable bytes, solooksNulFilled()returns false even though startup already proved the file is not valid JSON.The repair path can preserve the valid
.bakfor files that were just recovered from backup, then allow later normal saves to refresh.bakfrom the repaired primary.Template check