{"record":{"id":"f98ffef1c70801a0","repo":"jdx/mise","slug":"brew-cask-binary-target-contains-nul-f98ffe","errorCode":null,"errorMessage":"brew-cask: binary target contains NUL","messagePattern":"brew-cask: binary target contains NUL","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/packages/brew/cask/paths.rs","lineNumber":270,"sourceCode":"    }\n    Ok(roots)\n}\n\npub(super) fn is_appdir_binary_target(target_name: &str) -> bool {\n    target_name.starts_with(\"$APPDIR/\")\n}\n\npub(super) fn allowed_binary_target_roots_display(roots: &[PathBuf]) -> String {\n    roots\n        .iter()\n        .map(|root| root.display().to_string())\n        .collect::<Vec<_>>()\n        .join(\" or \")\n}\n\npub(super) fn binary_target_path(target_name: &str, appdir: &Path) -> Result<PathBuf> {\n    if target_name.contains('\\0') {\n        bail!(\"brew-cask: binary target contains NUL\");\n    }\n    if let Some(relative) = target_name.strip_prefix(\"$APPDIR/\") {\n        let relative = Path::new(relative);\n        reject_appdir_escape(relative, \"binary $APPDIR target\", target_name)?;\n        if !allowed_appdir_roots()?.iter().any(|root| root == appdir) {\n            bail!(\"brew-cask: invalid appdir '{}'\", appdir.display());\n        }\n        return Ok(appdir.join(relative));\n    }\n    if target_name.contains(\"$APPDIR\") {\n        bail!(\"brew-cask: $APPDIR must prefix a binary target\");\n    }\n    let prefix = prefix::prefix();\n    let prefix_str = prefix.to_string_lossy();\n    let target_name = target_name.replace(\"$HOMEBREW_PREFIX\", prefix_str.as_ref());\n    let path = PathBuf::from(&target_name);\n    let target = if path.is_absolute() {\n        path","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/jdx/mise/blob/afd2eddd3a50c16190efc1c7e94404b48f72af57/src/system/packages/brew/cask/paths.rs#L252-L288","documentation":"`binary_target_path` rejects a cask `binary` target string containing a NUL byte. NUL is not a valid character in Unix paths and would otherwise truncate the path or indicate a corrupt/hostile cask definition, so it fails fast with this error.","triggerScenarios":"Calling `target_path` or `binary_targets_must_stay_under_an_allowed_root` with a cask whose `binary` stanza value embeds `\\0` — typically from corrupted cask data, bad decoding of the cask source, or programmatically constructed target strings.","commonSituations":"Cask file fetched/downloaded incorrectly and containing binary junk; custom tooling that builds target strings with a NUL terminator from C-style buffers; malicious cask attempting path manipulation.","solutions":["Re-fetch/refresh the cask definition so the corrupted stanza is replaced with valid text","Inspect the cask's `binary` value for stray control characters and remove them","Fix custom generation code that embeds NUL (e.g. passing a C buffer without trimming the terminator)","Sanitize/validate target strings before passing them into the install path"],"exampleFix":"// before (Rust, constructing targets)\nlet target = cstring.to_string_lossy(); // keeps trailing '\\0'\n// after\nlet target = cstring.to_string_lossy().trim_end_matches('\\0').to_string();","handlingStrategy":"validation","validationCode":"fn binary_target_ok(t: &str) -> bool {\n    !t.contains('\\0')\n}","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"binary target contains NUL\") => {\n        eprintln!(\"cask binary target is corrupt; re-fetch the cask definition\");\n    }\n    r => r?,\n}","preventionTips":["Sanitize cask source decoding so control bytes never enter target strings","Trim C-string terminators when building targets programmatically","Re-download casks that arrive with binary junk","Validate stanza strings with a simple control-character check before install"],"tags":["path-validation","brew-cask","sanitization"],"backgroundTag":"invalid-argument-format","analyzedSha":"afd2eddd3a50c16190efc1c7e94404b48f72af57","analyzedAt":"2026-09-09T01:38:25.179Z","contentChangedAt":"2026-09-09T01:38:25.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}