viewer: fix crash when viewing files with PK/ZIP magic bytes - #26
Merged
Conversation
ilia-maslakov
force-pushed
the
fix-viewer-zip-crash-local
branch
from
March 9, 2026 19:24
f199ff0 to
1fd3f03
Compare
When mcview_load() opens a file whose first bytes match a known archive signature (PK for ZIP, 1f8b for gzip, etc.), the VFS layer attempts to decompress it. If decompression fails the code falls through without a usable file descriptor, leading to a segfault on the second F3 press. Close the failed VFS descriptor and reopen the original file directly via DS_FILE so the viewer always has a valid fd. Signed-off-by: Ilia Maslakov <il.smind@gmail.com>
Add tests/src/viewer/ with mcview__load_zip_magic test suite covering ZIP-magic file load, reload without crash, normal file load, nonexistent file, and gzip-magic file load. Mark mcview_compute_areas, mcview_update_bytes_per_line, mcview_set_codeset, mcview_display, mcview_show_error, file_error_message, load_file_position as MC_MOCKABLE so tests can override them with stubs. Signed-off-by: Ilia Maslakov <il.smind@gmail.com>
ilia-maslakov
force-pushed
the
fix-viewer-zip-crash-local
branch
from
March 9, 2026 20:40
5516e1c to
092b57e
Compare
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.
Summary
Prevent a viewer crash when VFS archive detection recognizes a file signature but decompression cannot open it.
Auto summary
Commits: 2
Files changed: 10
Commit messages
05c467b)092b57e)Changed files
added (2)
tests/src/viewer/Makefile.amtests/src/viewer/mcview__load_zip_magic.cmodified (8)
configure.aclib/util.clib/widget/wtools.csrc/util.csrc/viewer/display.csrc/viewer/lib.csrc/viewer/mcviewer.ctests/src/Makefile.amThis block is auto-generated. Edit outside this section.