{"record":{"id":"12e66edd48587949","repo":"sxyazi/yazi","slug":"invalid-file-type-value-04o","errorCode":null,"errorMessage":"invalid file type: {value:04o}","messagePattern":"invalid file type: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"yazi-fs/src/cha/mode.rs","lineNumber":75,"sourceCode":"\t\t\t_ => &ChaType::Unknown,\n\t\t}\n\t}\n}\n\nimpl TryFrom<u16> for ChaMode {\n\ttype Error = anyhow::Error;\n\n\tfn try_from(value: u16) -> Result<Self, Self::Error> {\n\t\tlet me = Self::from_bits(value).ok_or_else(|| anyhow!(\"invalid file mode: {value:04o}\"))?;\n\t\tmatch me & Self::T_MASK {\n\t\t\tSelf::T_FILE\n\t\t\t| Self::T_DIR\n\t\t\t| Self::T_LINK\n\t\t\t| Self::T_BLOCK\n\t\t\t| Self::T_CHAR\n\t\t\t| Self::T_SOCK\n\t\t\t| Self::T_FIFO => Ok(me),\n\t\t\t_ => bail!(\"invalid file type: {value:04o}\"),\n\t\t}\n\t}\n}\n\n#[cfg(unix)]\nimpl From<ChaMode> for std::fs::Permissions {\n\tfn from(value: ChaMode) -> Self {\n\t\tuse std::os::unix::fs::PermissionsExt;\n\n\t\tSelf::from_mode(value.bits() as _)\n\t}\n}\n\nimpl ChaMode {\n\t// Convert a file mode to a string representation\n\t#[cfg(unix)]\n\t#[allow(clippy::collapsible_else_if)]\n\tpub(crate) fn permissions(self, dummy: bool) -> [u8; 10] {","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/sxyazi/yazi/blob/5f901b886b14de1f17460b6e52e9de5d67f8aba9/yazi-fs/src/cha/mode.rs#L57-L93","documentation":"ChaMode::try_from validates a raw st_mode value by masking off permission bits and checking that the remaining file-type bits match a known type (regular, dir, link, block, char, sock, fifo). Any other bit pattern is rejected with the octal value included in the message. This guards against corrupt or fabricated mode data entering the type system.","triggerScenarios":"Constructing a ChaMode from a raw mode value whose file-type bits are not one of S_IFREG/S_IFDIR/S_IFLNK/S_IFBLK/S_IFCHR/S_IFSOCK/S_IFIFO — e.g. passing a value already masked incorrectly or a mode from a non-POSIX source.","commonSituations":"Reading mode fields from external/serialized data (plugin-provided data, cache files) that is corrupt or from a different OS encoding; accidentally passing permission bits only (masked away type bits -> zero) into the constructor.","solutions":["Inspect the octal value in the message; verify which file-type bits it carries and where the value came from.","Only pass full stat st_mode values (with S_IFMT type bits) into ChaMode::try_from, never permission-only values.","Sanitize/validate external or cached mode data before conversion; treat failure as corrupt and re-fetch via stat."],"exampleFix":"// before\nlet mode = ChaMode::try_from(perm_bits_only)?;\n// after\nlet mode = ChaMode::try_from(raw_st_mode)?; // full mode incl. S_IFMT type bits","handlingStrategy":"validation","validationCode":"fn is_known_mode(value: u32) -> bool {\n    matches!(value & libc::S_IFMT, libc::S_IFREG | libc::S_IFDIR | libc::S_IFLNK | libc::S_IFBLK | libc::S_IFCHR | libc::S_IFSOCK | libc::S_IFIFO)\n}","typeGuard":null,"tryCatchPattern":"let mode = ChaMode::try_from(raw).with_context(|| format!(\"bad mode {raw:04o} from {source:?}\"))?;","preventionTips":["Only pass raw stat st_mode values, never pre-masked permission-only values","Validate externally sourced/cached mode data before conversion","Log the octal value and its origin to trace corruption"],"tags":["filesystem","unix","file-mode","validation"],"backgroundTag":"invalid-file-type-bits","analyzedSha":"5f901b886b14de1f17460b6e52e9de5d67f8aba9","analyzedAt":"2026-09-02T18:38:25.566Z","contentChangedAt":"2026-09-02T18:38:25.566Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}