{"record":{"id":"873be93c6ab3b6ae","repo":"astrid-runtime/astrid","slug":"target-kib-must-be-a-power-of-two-in-8-256","errorCode":null,"errorMessage":"target KiB must be a power of two in 8..=256","messagePattern":"target KiB must be a power of two in 8\\.\\.=256","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/astrid-storage-chunker-evidence/src/algorithm.rs","lineNumber":148,"sourceCode":"                        visit(segment.dedup_key())?;\n                    }\n                }\n            },\n        }\n        Ok(())\n    }\n\n    fn fastcdc_target_bytes(&self) -> Result<u32> {\n        match self.parameters {\n            Parameters::FastCdc2020 { target_bytes, .. } => Ok(target_bytes),\n            _ => bail!(\"FastCDC candidate has non-FastCDC parameters\"),\n        }\n    }\n}\n\npub fn candidates(target_kib: u32) -> Result<Vec<Candidate>> {\n    if !(8..=256).contains(&target_kib) || !target_kib.is_power_of_two() {\n        bail!(\"target KiB must be a power of two in 8..=256\");\n    }\n    let target = target_kib\n        .checked_mul(1024)\n        .ok_or_else(|| anyhow::anyhow!(\"target byte size overflow\"))?;\n\n    let fast_minimum = target / 4;\n    let fast_maximum = target\n        .checked_mul(4)\n        .ok_or_else(|| anyhow::anyhow!(\"FastCDC maximum overflow\"))?;\n    let narrow_minimum = checked_ratio(target, 3, 4, \"narrow MinCDC minimum\")?;\n    let narrow_maximum = checked_ratio(target, 5, 4, \"narrow MinCDC maximum\")?;\n    let wide_minimum = target / 2;\n    let wide_maximum = checked_ratio(target, 3, 2, \"wide MinCDC maximum\")?;\n    let empirical_compromise_minimum = target / 2;\n    let empirical_compromise_maximum =\n        checked_ratio(target, 5, 2, \"empirical-compromise MinCDC maximum\")?;\n    let empirical_compromise_kib = target_kib\n        .checked_mul(3)","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-storage-chunker-evidence/src/algorithm.rs#L130-L166","documentation":"`candidates(target_kib)` validates that the requested chunk target is a power of two between 8 and 256 KiB inclusive before computing derived sizes. Passing anything else (e.g. 10, 0, 512) fails this validation and the function bails immediately.","triggerScenarios":"Calling the public `candidates(target_kib)` with a value outside 8..=256 or not a power of two (e.g. `candidates(10)`, `candidates(4)`, `candidates(512)`).","commonSituations":"Hand-tuned chunk sizes from config not constrained to powers of two; unit tests probing boundary values; a caller forwarding user-supplied target sizes without validation.","solutions":["Clamp/normalize the requested target to the nearest power of two within 8..=256 before calling.","Validate user/config-supplied target sizes at config load time.","Use one of the supported sizes: 8, 16, 32, 64, 128, or 256 KiB."],"exampleFix":"// before\nlet cands = candidates(100)?;\n// after\nlet target_kib = 100u32.next_power_of_two().clamp(8, 256); // 128\nlet cands = candidates(target_kib)?;","handlingStrategy":"validation","validationCode":"fn valid_target_kib(kib: u32) -> bool {\n    (8..=256).contains(&kib) && kib.is_power_of_two()\n}\nassert!(valid_target_kib(target_kib), \"target KiB must be a power of two in 8..=256\");","typeGuard":null,"tryCatchPattern":"match candidates(target_kib) {\n    Ok(cands) => cands,\n    Err(e) => { log::warn!(\"invalid target {target_kib}: {e}\"); candidates(default_target_kib)? }\n}","preventionTips":["Clamp user/config chunk sizes to the nearest supported power of two","Validate chunk-size config at load time, before benchmark/encode calls","Restrict UI/config options to the enumerated set 8/16/32/64/128/256"],"tags":["validation","chunker","arguments","range"],"backgroundTag":"invalid-argument-value","analyzedSha":"affd8760f44190dbdfbec23403f4c4b642c33112","analyzedAt":"2026-09-09T21:28:12.402Z","contentChangedAt":"2026-09-09T21:28:12.402Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}