can1357/oh-my-pi · error · io::Error
truncated NtQueryDirectoryFile record
Error message
truncated NtQueryDirectoryFile record
What it means
On Windows, records from NtQueryDirectoryFile (FILE_DIRECTORY_INFORMATION et al.) carry a NextEntryOffset; if a record's declared structure extends past the available buffer, the walker returns InvalidData with this message rather than reading out of bounds. This is a corrupt-buffer guard on the NT syscall contract.
Source
Thrown at crates/pi-walker/src/lib.rs:4153
fn file_type_from_attributes(attributes: u32) -> Option<FileType> {
if attributes & FILE_ATTRIBUTE_REPARSE_POINT != 0 {
Some(FileType::Symlink)
} else if attributes & FILE_ATTRIBUTE_DIRECTORY != 0 {
Some(FileType::Dir)
} else {
Some(FileType::File)
}
}
fn mtime_from_filetime(filetime: i64) -> Option<f64> {
let ticks = filetime.checked_sub(UNIX_EPOCH_AS_FILETIME)?;
let seconds = ticks / WINDOWS_TICK;
let nanos = (ticks % WINDOWS_TICK) * 100;
mtime_millis(seconds, nanos)
}
fn invalid_data(message: &'static str) -> io::Error {
io::Error::new(io::ErrorKind::InvalidData, message)
}
}
#[cfg(not(any(target_os = "macos", target_os = "linux", target_os = "windows")))]
mod platform {
use std::{borrow::Cow, io, path::Path};
use super::{FileType, RawDirEntry, ReadDirControl, ReadDirError, WalkDetail, WalkError};
pub const CHEAP_SIZE_HINTS: bool = false;
pub fn read_dir_entries<F, E>(
path: &Path,
detail: WalkDetail,
_buffer: &mut Vec<u8>,
mut emit: F,
) -> std::result::Result<ReadDirControl, ReadDirError<E>>
whereView on GitHub (pinned to 9690622007)
Solutions
- Retry the directory read once.
- Fall back to std::fs::read_dir for the affected directory.
- File a report with OS/filesystem details; this violates the NT directory-enumeration contract.
Defensive patterns
Strategy: fallback
Try / catch
match fast_walk(dir) {
Err(e) if e.kind() == io::ErrorKind::InvalidData && e.to_string().contains("NtQueryDirectoryFile") => std_walk(dir),
other => other,
} Prevention
- Use the portable read_dir fallback when NT enumeration reports corrupt records.
- Update or remove suspect filesystem filter drivers.
- Retry once before falling back.
When it happens
Trigger: NtQueryDirectoryFile returns a buffer where a record's fixed structure or FileNameLength exceeds the remaining bytes during a directory walk.
Common situations: Faulty filesystem/filter drivers, corrupted kernel buffers, unusual network file systems; not a caller-input problem.
Related errors
- truncated u16
- truncated getattrlistbulk record length
- GetFinalPathNameByHandleW failed with code {0}
- Failed to replace session file after EPERM (original: ${toEr
- unknown filetype: {ft_debug}
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/8063724f25cbcfec.
Report an issue: GitHub.