can1357/oh-my-pi · error · io::Error

truncated u16

Error message

truncated u16

What it means

On Windows, pi-walker reads fixed-size fields (e.g. a u16 length or name-length field) out of NtQueryDirectoryFile record buffers via byte slices; a slice shorter than u16 bytes means the record is malformed, so the walker returns InvalidData with this static message.

Source

Thrown at crates/pi-walker/src/lib.rs:3974

	const fn file_type_from_mode(mode: libc::mode_t) -> Option<FileType> {
		match mode & libc::S_IFMT {
			libc::S_IFREG => Some(FileType::File),
			libc::S_IFDIR => Some(FileType::Dir),
			libc::S_IFLNK => Some(FileType::Symlink),
			_ => None,
		}
	}

	fn is_skippable_entry_error(err: &io::Error) -> bool {
		matches!(
			err.kind(),
			io::ErrorKind::NotFound | io::ErrorKind::PermissionDenied | io::ErrorKind::NotADirectory
		)
	}

	fn invalid_data(message: &'static str) -> io::Error {
		io::Error::new(io::ErrorKind::InvalidData, message)
	}
}

#[cfg(target_os = "windows")]
mod platform {
	use std::{
		ffi::OsString,
		io,
		os::windows::ffi::{OsStrExt, OsStringExt},
		path::Path,
	};

	use windows_sys::{
		Wdk::Storage::FileSystem::{
			FILE_ID_FULL_DIR_INFORMATION, FileIdFullDirectoryInformation, NtQueryDirectoryFile,
		},
		Win32::{
			Foundation::{CloseHandle, HANDLE, INVALID_HANDLE_VALUE, STATUS_NO_MORE_FILES},

View on GitHub (pinned to 9690622007)

Solutions

  1. Retry the enumeration; if transient it may succeed.
  2. Fall back to std::fs::read_dir for that directory.
  3. Report to the walker maintainers with the path/filesystem — indicates a broken record stream from the OS.
Defensive patterns

Strategy: fallback

Try / catch

const result = fastWalk(dir).catch((e) =>
  e.code === "EINVAL" || e.kind === "InvalidData" ? stdWalk(dir) : Promise.reject(e)
);

Prevention

When it happens

Trigger: Directory enumeration on Windows encounters a directory-information record whose declared field offset/length leaves fewer than 2 bytes for a u16 field.

Common situations: Filesystem driver or filter-driver bugs, exotic mounts, or memory corruption; effectively never caused by caller configuration.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/465b551b43ebf613. Report an issue: GitHub.