fix: prevent SQLiteBlobTooBig crash from oversized note body on app open#838
fix: prevent SQLiteBlobTooBig crash from oversized note body on app open#838MrLawrenceKwan wants to merge 2 commits intoCrustack:mainfrom
Conversation
…eBlobTooBig crash Some legacy/imported notes can exceed CursorWindow limits and crash list loading with SQLiteBlobTooBigException. Add a targeted onOpen safety repair that truncates only oversized BaseNote.body rows to MAX_BODY_CHAR_LENGTH. This preserves app startup/readability and allows affected users to recover notes instead of getting stuck in a crash loop. Refs Crustack#837
|
No actionable comments were generated in the recent review. 🎉 📝 WalkthroughWalkthroughAdds a Room database migration (v9 → v10) and bumps the database version to 10; the migration truncates any Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@app/src/main/java/com/philkes/notallyx/data/NotallyDatabase.kt`:
- Around line 148-159: The onOpen repair in RoomDatabase.Callback (override fun
onOpen(db: SupportSQLiteDatabase)) currently runs a full-table truncation using
MAX_BODY_CHAR_LENGTH on every DB open and silently discards data; change this to
a one-shot operation (e.g., implement a Room Migration to a new schema version
or check/set a SharedPreferences flag before executing) so the UPDATE on
BaseNote only runs once, and before truncating: (1) identify affected rows and
persist their IDs/content elsewhere or set a truncated_flag column on BaseNote,
(2) emit a log entry or user-visible notification listing affected note IDs, and
(3) perform the actual substr(...) update only after backing up/persisting
overflow; reference the onOpen callback, MAX_BODY_CHAR_LENGTH, and the BaseNote
table when making these changes.
Move truncation repair from onOpen callback to Migration10 (9->10), so it runs once instead of every DB open. Addresses review feedback about repeated full-table update behavior.
|
Addressed latest review concern: moved the oversized-note repair from callback to a one-shot migration (, DB version 10).\n\nWhy:\n- avoids running full-table truncation on every DB open\n- performs the repair exactly once during schema upgrade\n\nPatch pushed in commit: b99be7f |
|
Follow-up correction: latest patch moves the oversized-note repair from database open callback to a one-shot schema migration (Migration10, version 9 -> 10). This ensures the UPDATE runs once during upgrade, not on every app open. Commit: b99be7f. |
|
Hi @MrLawrenceKwan, Thank you. This looks promising but I am unable to compile things at this time to test it (I'm overseas, far away from my computer). The app author has suggested that a the issue was addressed in 7.7.0 but updating to that manually has not fixed the error. There may be some peculiarity. If I'm able to get your fix incorporated into a package I can install, I'm very interested to try it. |
|
Hey @MrLawrenceKwan, The app author has created a hotfix which resolved the issue, and I've issued the bounty to him, but if you give me a PayPal or your osko deets (I'm also in Australia), I'd like to send you a little something just for your prompt efforts. |
|
Hey @lozzyactual — thank you, I really appreciate your kind offer 🙏 You can send via PayPal / PayID: Also, if you have any other app tasks (small fixes or larger features), I’d be happy to help. Here are our Google Play app examples for reference:
We offer very affordable pricing (well below typical agency rates) with quick turnaround. |
Summary
Fixes the crash loop reported in #837 ().
Root cause
A legacy/imported oversized row can exceed CursorWindow limits during list reads (), causing Room LiveData query failures and making notes inaccessible.
Change (targeted)
This is intentionally minimal and only touches rows above the existing app-defined size limit.
Why this helps
Notes
I could not run local Gradle compilation in this environment because Java runtime is unavailable ().
Code change is Kotlin-only, scoped to DB open safety repair.
Fixes #837
Summary by CodeRabbit