Skip to content

Fix dirent struct copy causing EXC_BAD_ACCESS in FileSystemService#602

Open
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/dirent-read-crash
Open

Fix dirent struct copy causing EXC_BAD_ACCESS in FileSystemService#602
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/dirent-read-crash

Conversation

@sentry

@sentry sentry Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

This PR addresses an EXC_BAD_ACCESS crash occurring in FileSystemService.listDirectoryWithIgnoreDetection.

Root Cause:
The readdir system call can return a pointer to a dirent record that is located near the end of a memory page. The original code copied the entire dirent struct (which is over 1024 bytes) by value using direntPtr.pointee. When the record was near a page boundary, this copy operation would attempt to read past the end of the mapped memory page into unmapped memory, triggering a KERN_INVALID_ADDRESS page fault.

Solution:
To prevent the full struct copy, the decodeDirentName function has been refactored to accept an UnsafePointer<dirent> instead of a dirent value. Inside decodeDirentName, UnsafeRawPointer and byte offsets are now used to read only the necessary fields (d_namlen, d_reclen, d_type, and d_name) directly from the pointer, avoiding any large memory copy that could cross a page boundary. The DecodedDirentName struct was updated to include dType.

Additionally, fileTypeFallback and descriptorRelativeMode functions, which also accepted dirent by value, have been updated to accept UnsafePointer<dirent> and read d_name bytes via raw pointer offsets. All call sites for these functions have been updated to pass the UnsafePointer<dirent> directly, eliminating the problematic .pointee dereference.

Fixes REPOPROMPT-A9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants