jdx/mise · error

history directory contains a NUL character

Error message

history directory contains a NUL character

What it means

On Windows, mise creates the history directory with restricted ACLs via Win32 APIs. Before calling the API it encodes the directory path as UTF-16; if the path contains an interior NUL character, the Win32 string would be silently truncated, so mise rejects it up front with this io-like error. Interior NULs indicate a corrupted or malformed path.

Solutions

  1. Check the environment variables that determine the data/state dir on Windows (`MISE_DATA_DIR`, `LOCALAPPDATA`) for corruption.
  2. Re-set the variable from a clean shell: `setx MISE_DATA_DIR "%LOCALAPPDATA%\mise"`.
  3. If the path is built programmatically, trim at the first NUL before passing it in.
  4. Restart the shell to pick up non-corrupted environment.

Example fix

// before: corrupted env value with embedded NUL
set MISE_DATA_DIR=C:\Users\me\AppData\Local\mis<0x00>e

// after
setx MISE_DATA_DIR "%LOCALAPPDATA%\mise"
Defensive patterns

Strategy: validation

Validate before calling

// Windows: reject interior NULs before invoking Win32 APIs
let wide: Vec<u16> = dir.as_os_str().encode_wide().collect();
if wide.contains(&0) {
  eprintln!("history directory path contains NUL; fix MISE_DATA_DIR/env");
}

Type guard

fn path_is_nul_free(dir: &Path) -> bool {
  use std::os::windows::ffi::OsStrExtW;
  !dir.as_os_str().encode_wide().any(|c| c == 0)
}

Try / catch

match result {
  Err(e) if e.to_string().contains("NUL character") => {
    // repair the environment variable that produced the path
  }
  other => other?,
}

Prevention

When it happens

Trigger: Resolving the history directory path from configuration/environment on Windows when the computed path string contains an embedded NUL byte (e.g. corrupted env var or misbuilt path buffer).

Common situations: A MISE_DATA_DIR / XDG-style env var corrupted on Windows; a programmatic caller constructing a path from a buffer that retained a NUL terminator; registry or env corruption.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of jdx/mise@533346cc37 (2026-09-17). Data as JSON: /api/errors/624d94bd309ba8e6. Report an issue: GitHub.

Appendix: source

Thrown at src/system/history/store.rs:144

    let sddl: Vec<u16> = "D:P(A;OICI;FA;;;OW)\0".encode_utf16().collect();
    let mut descriptor = std::ptr::null_mut();
    // SAFETY: both pointers are valid for the call; Windows allocates the
    // descriptor, released with LocalFree below on every path.
    if unsafe {
        ConvertStringSecurityDescriptorToSecurityDescriptorW(
            sddl.as_ptr(),
            1,
            &mut descriptor,
            std::ptr::null_mut(),
        )
    } == 0
    {
        return Err(std::io::Error::last_os_error().into());
    }
    let result = (|| -> Result<()> {
        let mut path: Vec<u16> = dir.as_os_str().encode_wide().collect();
        if path.contains(&0) {
            eyre::bail!("history directory contains a NUL character");
        }
        path.push(0);
        let attributes = SECURITY_ATTRIBUTES {
            nLength: std::mem::size_of::<SECURITY_ATTRIBUTES>() as u32,
            lpSecurityDescriptor: descriptor,
            bInheritHandle: 0,
        };
        if !dir.is_dir()
            // SAFETY: path is NUL-terminated and attributes/descriptor remain live.
            && unsafe { CreateDirectoryW(path.as_ptr(), &attributes) } == 0
            && !dir.is_dir()
        {
            return Err(std::io::Error::last_os_error().into());
        }
        // Also tighten an existing directory instead of trusting inherited ACLs.
        // SAFETY: path and descriptor are valid until the call returns.
        if unsafe {
            SetFileSecurityW(

View on GitHub (pinned to 533346cc37)