openai/codex · error · anyhow::Error

CopySid failed for

Error message

CopySid failed for {sid_str}

What it means

CopySid failed to copy the parsed SID into the output buffer sized by GetLengthSid. The source SID was freed before returning the error, so the caller gets no SID bytes; this is an unexpected Windows failure during a straightforward in-memory copy.

Solutions

  1. Re-run the operation; a transient copy failure is unlikely but possible with invalid SID memory
  2. Re-resolve the SID from the account name to get a fresh, valid SID buffer
  3. Check the source SID string for corruption if the failure is reproducible
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at codex-rs/windows-sandbox-rs/src/bin/setup_main/win/sandbox_users.rs:288 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of openai/codex@339751715c (2026-08-25). Data as JSON: /api/errors/f4324223162e32dc. Report an issue: GitHub.

Appendix: source

Thrown at codex-rs/windows-sandbox-rs/src/bin/setup_main/win/sandbox_users.rs:288

        return Err(anyhow::anyhow!(
            "ConvertStringSidToSidW failed for {sid_str}: {}",
            unsafe { GetLastError() }
        ));
    }
    let sid_len = unsafe { GetLengthSid(psid) };
    if sid_len == 0 {
        unsafe {
            LocalFree(psid as _);
        }
        return Err(anyhow::anyhow!("GetLengthSid failed for {sid_str}"));
    }
    let mut out = vec![0u8; sid_len as usize];
    let ok = unsafe { CopySid(sid_len, out.as_mut_ptr() as *mut c_void, psid) };
    unsafe {
        LocalFree(psid as _);
    }
    if ok == 0 {
        return Err(anyhow::anyhow!("CopySid failed for {sid_str}"));
    }
    Ok(out)
}

fn lookup_account_name_for_sid(sid_str: &str) -> Result<String> {
    let sid_w = to_wide(OsStr::new(sid_str));
    let mut psid: *mut c_void = std::ptr::null_mut();
    if unsafe { ConvertStringSidToSidW(sid_w.as_ptr(), &mut psid) } == 0 {
        return Err(anyhow::anyhow!(
            "ConvertStringSidToSidW failed for {sid_str}: {}",
            unsafe { GetLastError() }
        ));
    }
    let mut name_len: u32 = 0;
    let mut domain_len: u32 = 0;
    let mut use_type: SID_NAME_USE = 0;
    let ok = unsafe {
        LookupAccountSidW(

View on GitHub (pinned to 339751715c)