Skip to content

viewer: fix crash when viewing files with PK/ZIP magic bytes - #26

Merged
ilia-maslakov merged 2 commits into
masterfrom
fix-viewer-zip-crash-local
Mar 9, 2026
Merged

viewer: fix crash when viewing files with PK/ZIP magic bytes#26
ilia-maslakov merged 2 commits into
masterfrom
fix-viewer-zip-crash-local

Conversation

@ilia-maslakov

@ilia-maslakov ilia-maslakov commented Mar 9, 2026

Copy link
Copy Markdown
Owner

Summary

Prevent a viewer crash when VFS archive detection recognizes a file signature but decompression cannot open it.

  • Fix segfault in mcview when viewing files with PK/ZIP magic bytes (e.g. .pptx, .docx, .xlsx)
  • Fall back to the original raw file when VFS decompression fails.
  • Ensure the viewer always retains a valid datasource, including after reopening with F3.
  • Add regression tests for ZIP magic bytes, reloads, ordinary files, missing files, and gzip magic bytes.
  • Mark the required viewer functions mockable for isolated unit testing.

Auto summary

Commits: 2
Files changed: 10

Commit messages

  • viewer: fix crash when viewing files with PK/ZIP magic bytes (05c467b)
  • viewer: add unit tests for mcview_load with ZIP magic bytes (092b57e)

Changed files

added (2)

  • tests/src/viewer/Makefile.am
  • tests/src/viewer/mcview__load_zip_magic.c

modified (8)

  • configure.ac
  • lib/util.c
  • lib/widget/wtools.c
  • src/util.c
  • src/viewer/display.c
  • src/viewer/lib.c
  • src/viewer/mcviewer.c
  • tests/src/Makefile.am

This block is auto-generated. Edit outside this section.

@github-actions github-actions Bot added this to the Future Releases milestone Mar 9, 2026
@ilia-maslakov
ilia-maslakov force-pushed the fix-viewer-zip-crash-local branch from f199ff0 to 1fd3f03 Compare March 9, 2026 19:24
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
ilia-maslakov force-pushed the fix-viewer-zip-crash-local branch from 5516e1c to 092b57e Compare March 9, 2026 20:40
@ilia-maslakov
ilia-maslakov merged commit 7527d32 into master Mar 9, 2026
17 checks passed
@ilia-maslakov ilia-maslakov added Bug fix mcview Viewer (mcview) labels Jul 19, 2026
@ilia-maslakov
ilia-maslakov deleted the fix-viewer-zip-crash-local branch July 20, 2026 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug fix mcview Viewer (mcview)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant