fix: prevent SIGBUS crash when reading images from external volumes#1387
Open
olegsatov wants to merge 1 commit into
Open
fix: prevent SIGBUS crash when reading images from external volumes#1387olegsatov wants to merge 1 commit into
olegsatov wants to merge 1 commit into
Conversation
Owner
|
What do you think about performance? Will this have a huge effect on NAS drives? For context see #347 |
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
RapidRAW crashes with
SIGBUS(EXC_BAD_ACCESS/KERN_MEMORY_ERROR) when an image file is memory-mapped and the kernel later fails to page it in — e.g. an external/USB drive disconnects or returns an I/O error, a network share drops, or the file is truncated/replaced by another process after mapping.Crash report (macOS 26.4, ARM64), faulting thread:
Kernel triage:
VM - Page has error bit set, and the faulting address lies inside a validmapped fileregion — i.e. not a bad pointer, but a failed page-in from the backing file. In my case two worker threads faulted simultaneously on two different mapped files when the external drive the library lives on glitched.Since this is a signal, not a panic,
catch_unwindcan't contain it and the whole app dies. The existing "fall back tofs::read" branches only trigger when creating the mapping fails — they can't help once a page-in fails later.Fix
Replace
read_file_mappedwithread_file_bytes— a plainfs::readwith the same pre-checks — at all call sites (image load, thumbnails, EXIF batch read, preview, export, negative conversion). I/O errors now surface as regularErrresults that the UI already handles, instead of killing the process.No performance regression is expected: every consumer (
rawler::RawSource::new_from_slice, image decoders) immediately copies the entire buffer into an owned allocation anyway, so mmap never saved a copy here — it only added the SIGBUS risk.Also removes the now-unused
memmap2dependency and theReadFileError::Lockedvariant (the advisorytry_lock_sharednever meaningfully protected these reads).Testing
cargo checkclean, no new warnings (on top of currentmain).