Skip to content

Fix FileSystemService dirent parsing on macOS#594

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

Fix FileSystemService dirent parsing on macOS#594
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/fs-dirent-parsing

Conversation

@sentry

@sentry sentry Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

This PR addresses an EXC_BAD_ACCESS (KERN_INVALID_ADDRESS) crash occurring in FileSystemService.listDirectoryWithIgnoreDetection and scandirListDirectory on macOS.

Root Cause:
On macOS, the dirent struct returned by readdir is variable-length, with its actual size determined by the filename length. The previous implementation copied direntPtr.pointee, which attempts to read a fixed-size dirent struct. This could extend beyond the kernel's allocated buffer for the specific directory entry into unmapped memory, leading to a crash.

Solution:

  1. Refactored Helper Signatures: decodeDirentName, descriptorRelativeMode, and fileTypeFallback now accept UnsafeMutablePointer<dirent> or Data (for name bytes) instead of dirent by value.
  2. Safe dirent Field Access: On macOS, decodeDirentName now uses raw pointer arithmetic to read d_namlen and d_name bytes directly from the dirent pointer, ensuring reads are strictly within the allocated bounds. This avoids copying the entire variable-length struct.
  3. Updated Call Sites: The main loops in listDirectoryWithIgnoreDetection and scandirListDirectory no longer perform direntPtr.pointee copies. Instead, they pass the dirent pointer directly to the updated helper functions and read d_type via raw pointer access on macOS.

Fixes REPOPROMPT-9V

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