Repository navigation
fix(dua-core): avoid reading past HEADER_SIZE in Windows ReadDir::entry_at - #416
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The focused changes address the reported memory-access errors, cover the boundary cases, and have no identified blocking issues.
No open issues 🎉
What changed in this PR
This PR fixes out-of-bounds reads in the Windows directory-entry parser while preserving support for short filenames at the end of the buffer.
Changes:
- Copies only the fixed header and computes the filename pointer directly from the buffer.
- Uses checked arithmetic to validate current and next-entry header bounds.
- Adds regression coverage for a short filename at the buffer boundary and an undersized buffer.
| File | Description |
|---|---|
crates/dua-lib/src/windows.rs |
Bounds directory-record reads and adds boundary-case tests. |
Review effort: Balanced
…ry_at `FILE_ID_BOTH_DIR_INFO` has a 104-byte fixed header (`HEADER_SIZE`) followed by `FileName: [u16; 1]` (2 bytes) and 6 bytes of trailing alignment padding (`size_of::<FILE_ID_BOTH_DIR_INFO>() == 112`). `ReadDir::entry_at` validated `offset <= buffer_len.saturating_sub(HEADER_SIZE)` and then called `info_ptr.read_unaligned()`, which reads 112 bytes and can read up to 8 bytes past the end of `self.buffer` when a valid entry with a 1-3 UTF-16 code unit filename (106-110 bytes) sits at the end of the buffer. Copy only `HEADER_SIZE` bytes into `FILE_ID_BOTH_DIR_INFO::default()` via `std::ptr::copy_nonoverlapping`, compute `name_ptr` directly from `offset + HEADER_SIZE`, and use `checked_add(HEADER_SIZE)` instead of `saturating_sub(HEADER_SIZE)` so buffers smaller than `HEADER_SIZE` are also rejected.
Byron
force-pushed
the
fix-windows-entry-at-oob-read
branch
from
October 24, 2026 03:21
c0db977 to
b5ef287
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
In
windows_sys,FILE_ID_BOTH_DIR_INFOhas a 104-byte fixed header (HEADER_SIZE = std::mem::offset_of!(FILE_ID_BOTH_DIR_INFO, FileName) == 104) followed bypub FileName: [u16; 1](2 bytes) and 6 bytes of trailing alignment padding (align_of::<FILE_ID_BOTH_DIR_INFO>() == 8, sosize_of::<FILE_ID_BOTH_DIR_INFO>() == 112).In
ReadDir::entry_at:offset > buffer_len.saturating_sub(HEADER_SIZE)verified that 104 bytes were available starting atoffset, and then calledinfo_ptr.read_unaligned(), which readssize_of::<FILE_ID_BOTH_DIR_INFO>()(112 bytes). When a valid directory entry with a 1–3 UTF-16 code unit filename (106,108, or110bytes total) sits at the end ofself.buffer,read_unaligned()reads up to 8 bytes past the end of theVec<u64>allocation.(&raw const (*info_ptr).FileName).cast::<u16>()projected through*const FILE_ID_BOTH_DIR_INFOwhose 112-byte struct extent could exceedself.buffer.offset > buffer_len.saturating_sub(HEADER_SIZE)saturated to0whenbuffer_len < HEADER_SIZE, allowingoffset == 0on a buffer smaller thanHEADER_SIZE.Fix
HEADER_SIZE(104) bytes intoFILE_ID_BOTH_DIR_INFO::default()usingstd::ptr::copy_nonoverlappinginstead of reading 112 bytes withinfo_ptr.read_unaligned(). Unlike widening the bounds check tosize_of::<FILE_ID_BOTH_DIR_INFO>()(112 bytes), this still accepts valid 106–110 byte entries (1–3 character filenames) at the end of the buffer without reading pastHEADER_SIZE.name_ptrdirectly viaself.buffer.as_ptr().byte_add(offset + HEADER_SIZE).cast::<u16>().checked_add(HEADER_SIZE)instead ofsaturating_sub(HEADER_SIZE).HEADER_SIZE.