[GH-ISSUE #4378] [Issue]: One malformed row in any file-backed table JSON crashes server bootstrap #2374

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

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

Originally assigned to: @SpicyMarinara on GitHub.

Summary

A single malformed entry (null, a string, a number) inside any file-backed table JSON file crashes server bootstrap with a TypeError. parseJsonFile validates only that the parsed value is an array; the element shape is never checked before rows are dereferenced.

Expected behavior

A corrupt individual row should be handled the way a corrupt file already is: reported, quarantined or skipped with a clear log line naming the table and file, and the rest of the table loaded normally. The user should be able to start the app and recover.

Actual behavior

normalizeRow calls Object.prototype.hasOwnProperty.call(row, column.key) on every element unconditionally (packages/server/src/db/file-backed-store.ts:680). For a null element that throws TypeError: Cannot convert undefined or null to object, which propagates out of the load loop and aborts startup. The table's per-row migrations (migrateLegacyNoodleAccountRow, migrateRetiredChatModeRow) sit on the same path and would throw on the same inputs.

This affects every table in FILE_BACKED_TABLES (~60), not one specific feature.

Steps to reproduce

  1. Stop Marinara Engine.
  2. Edit any file-backed table JSON in the data directory (for example chats.json) and insert a bare null into the array.
  3. Start Marinara Engine.

Environment

  • Marinara Engine version: 2.3.5 / staging
  • Install type: source
  • OS + version: any
  • Browser or app shell: n/a (server-side bootstrap)

Logs, screenshots, or video

TypeError: Cannot convert undefined or null to object
    at Function.hasOwnProperty (<anonymous>)
    at normalizeRow (packages/server/src/db/file-backed-store.ts:680)

Additional context

Surfaced while reviewing #4377 (visual_novel startup crash). It was deliberately left out of that PR: it is pre-existing rather than introduced there, and fixing it for only the three tables that PR touches would be inconsistent and would trade a loud failure for silent data loss.

Design note worth settling before implementation: dropping a bad row silently loses user data, where today the load fails loudly with the file intact on disk. The existing quarantineUnrecoverableFiles path is probably the right model — preserve the original file, load what is valid, log loudly — but it currently operates at file granularity, not row.

Related: #4375, #4377

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 @Gunterlie on GitHub (Jul 31, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/4378 Originally assigned to: @SpicyMarinara on GitHub. ## Summary A single malformed entry (`null`, a string, a number) inside any file-backed table JSON file crashes server bootstrap with a `TypeError`. `parseJsonFile` validates only that the parsed value is an array; the element shape is never checked before rows are dereferenced. ## Expected behavior A corrupt individual row should be handled the way a corrupt *file* already is: reported, quarantined or skipped with a clear log line naming the table and file, and the rest of the table loaded normally. The user should be able to start the app and recover. ## Actual behavior `normalizeRow` calls `Object.prototype.hasOwnProperty.call(row, column.key)` on every element unconditionally (`packages/server/src/db/file-backed-store.ts:680`). For a `null` element that throws `TypeError: Cannot convert undefined or null to object`, which propagates out of the load loop and aborts startup. The table's per-row migrations (`migrateLegacyNoodleAccountRow`, `migrateRetiredChatModeRow`) sit on the same path and would throw on the same inputs. This affects every table in `FILE_BACKED_TABLES` (~60), not one specific feature. ## Steps to reproduce 1. Stop Marinara Engine. 2. Edit any file-backed table JSON in the data directory (for example `chats.json`) and insert a bare `null` into the array. 3. Start Marinara Engine. ## Environment - Marinara Engine version: `2.3.5` / staging - Install type: source - OS + version: any - Browser or app shell: n/a (server-side bootstrap) ## Logs, screenshots, or video ```text TypeError: Cannot convert undefined or null to object at Function.hasOwnProperty (<anonymous>) at normalizeRow (packages/server/src/db/file-backed-store.ts:680) ``` ## Additional context Surfaced while reviewing #4377 (`visual_novel` startup crash). It was deliberately left out of that PR: it is pre-existing rather than introduced there, and fixing it for only the three tables that PR touches would be inconsistent and would trade a loud failure for silent data loss. Design note worth settling before implementation: dropping a bad row silently loses user data, where today the load fails loudly with the file intact on disk. The existing `quarantineUnrecoverableFiles` path is probably the right model — preserve the original file, load what is valid, log loudly — but it currently operates at file granularity, not row. Related: #4375, #4377 ## 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:47:43 +07:00
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#2374
No description provided.