{"record":{"id":"a311b9256c630d41","repo":"jdx/mise","slug":"cannot-relocate-replacement-for-does-not-fi","errorCode":null,"errorMessage":"cannot relocate {}: replacement for {} does not fit ({} > {} bytes)","messagePattern":"cannot relocate (.+?): replacement for (.+?) does not fit \\((.+?) > (.+?) bytes\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/packages/brew/relocate.rs","lineNumber":178,"sourceCode":"            // keep); find the end at the next NUL\n            let str_end = content[start..]\n                .iter()\n                .position(|&b| b == 0)\n                .map(|p| start + p)\n                .unwrap_or(content.len());\n            // available slot: the string plus the run of NULs after it,\n            // minus one NUL that must remain as terminator\n            let slot_end = content[str_end..]\n                .iter()\n                .position(|&b| b != 0)\n                .map(|p| str_end + p)\n                .unwrap_or(content.len());\n            let old = content[start..str_end].to_vec();\n            let mut new = r.value.clone();\n            new.extend_from_slice(&old[r.placeholder.len()..]);\n            let slot = slot_end.saturating_sub(start);\n            if new.len() + 1 > slot {\n                bail!(\n                    \"cannot relocate {}: replacement for {} does not fit ({} > {} bytes)\",\n                    path.display(),\n                    String::from_utf8_lossy(r.placeholder),\n                    new.len() + 1,\n                    slot,\n                );\n            }\n            content[start..start + new.len()].copy_from_slice(&new);\n            for b in &mut content[start + new.len()..slot_end] {\n                *b = 0;\n            }\n            changed = true;\n            search_from = start + new.len();\n        }\n    }\n    Ok(changed)\n}\n","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/packages/brew/relocate.rs#L160-L196","documentation":"Binary relocation rewrites embedded absolute paths (e.g. the brew prefix) in place inside binaries. In-place replacement can only grow a string into the NUL padding that follows it in its slot; when the replacement (new value + remaining suffix + terminator) exceeds the available slot bytes, replace_in_binary bails, because overwriting past the slot would corrupt adjacent data in the binary.","triggerScenarios":"replace_in_binary (called by relocate_keg_with_replacements during pour) finds a placeholder occurrence whose replacement value is longer than the C-string slot (string + trailing NUL run minus one terminator) — e.g. relocating a bottle built with a short install path (like /opt/brew) into a much longer custom MISE_SYSTEM_BREW_PREFIX.","commonSituations":"Choosing an unusually long brew prefix (deep directory names, long usernames) when the bottle was built for the short default /home/linuxbrew/.linuxbrew or /opt/homebrew; relocation between prefixes of very different lengths.","solutions":["Use a prefix no longer than the bottle's original install path (default /opt/homebrew on macOS, /home/linuxbrew/.linuxbrew on Linux)","Set MISE_SYSTEM_BREW_PREFIX to the standard short location and place brew there, then re-apply the package","Reinstall/re-pour the affected formula so the bottle is re-extracted and relocated fresh (a partially relocated keg must be removed first)"],"exampleFix":"# before\nexport MISE_SYSTEM_BREW_PREFIX=/very/long/nested/path/to/my/super/long/brew/prefix\n# after\nexport MISE_SYSTEM_BREW_PREFIX=/home/linuxbrew/.linuxbrew","handlingStrategy":"validation","validationCode":"defaultPrefix=$(grep -ao '/[a-z/]*\\.linuxbrew\\|[a-z/]*brew' one-binary-from-bottle | head -1)\nif [ ${#MISE_SYSTEM_BREW_PREFIX} -gt ${#defaultPrefix} ]; then\n  echo \"custom prefix longer than bottle's build prefix — relocation may not fit\"\nfi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep the brew prefix at (or shorter than) the bottle's default install path","Avoid very long custom MISE_SYSTEM_BREW_PREFIX values when pouring bottles","Remove and re-pour a keg if a previous relocation attempt partially modified its binaries"],"tags":["brew","relocation","binary-patching"],"backgroundTag":"value-out-of-range","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}