filemax: Fix crash when undoing a page deletion - #88
Open
sjg20 wants to merge 1 commit into
Open
Conversation
Deleting pages from a stack and then pressing Ctrl-Z to undo crashes with a segfault in fseek() with a NULL stream. restorePages() calls restore_page(), which reads each deleted page's chunk data back from disc through max_read_data(), but unlike removePages() it never opens the file first. The stream _fin is left NULL between operations, so the read dereferences a NULL FILE *. Open the file around restore_page(), mirroring how removePages() opens it around free_page(), and close it again afterwards. As a safety net, make max_read_data() and max_write_data() return an error instead of calling fseek() on a NULL stream, so a similar mistake can no longer crash the program. Also drop a stray debug printf() that fired on every restored page. Add a Filemax test that removes a page and then restores it, checking the page count round-trips and the restored page still decodes. Co-developed-by: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix segfault when undoing a page deletion
Deleting pages from a stack (untick the green "keep" arrows) and then
pressing Ctrl-Z to undo crashes with a segfault:
Root cause
restorePages()callsrestore_page(), which reads each deleted page'schunk data back from disc via
max_read_data(). Unlike the matchingremovePages()— which wrapsfree_page()inensure_open()/ensure_closed()—restorePages()never opens the file first._finis NULL between operations, so
fseek(NULL, …)crashes.Fix
restore_page()and close it afterwards,mirroring
removePages().max_read_data()/max_write_data()return anerror instead of calling
fseek()on a NULL stream, so a similaromission can't crash again.
printf()that fired on every restored page.Test
Adds
TestFile::testRemoveRestorePages: removes a page then restoresit, checking the page count round-trips and the restored page still
decodes (this is the path that used to crash).