{"record":{"id":"bc7a4e1e75516ed7","repo":"AprilNEA/OpenLogi","slug":"captured-profile-has-too-many-identities-to-sanitize","errorCode":null,"errorMessage":"captured profile has too many identities to sanitize","messagePattern":"captured profile has too many identities to sanitize","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/openlogi-cli/src/cmd/fixture/record_profile/sanitize.rs","lineNumber":55,"sourceCode":"pub(super) fn standalone(device: &mut StandaloneDevice) -> Result<()> {\n    let ordinal = ordinal(0)?;\n    device.address.identity =\n        profile_identity(SyntheticIdentityKind::RawHidProfileIdentity, ordinal)?;\n    if device.serial_number.is_some() {\n        device.serial_number = Some(profile_identity(\n            SyntheticIdentityKind::DeviceSerialNumber,\n            ordinal,\n        )?);\n    }\n    if device.unit_id != [0; 4] {\n        device.unit_id = unit_id(ordinal)?;\n    }\n    Ok(())\n}\n\nfn ordinal(index: usize) -> Result<SyntheticIdentityOrdinal> {\n    let value = u16::try_from(index.saturating_add(1))\n        .map_err(|_| anyhow!(\"captured profile has too many identities to sanitize\"))?;\n    SyntheticIdentityOrdinal::new(value)\n        .map_err(|_| anyhow!(\"captured profile has too many identities to sanitize\"))\n}\n\nfn profile_identity(\n    kind: SyntheticIdentityKind,\n    ordinal: SyntheticIdentityOrdinal,\n) -> Result<String> {\n    generate_synthetic_identity(kind, ordinal)\n        .as_profile_str()\n        .map(str::to_string)\n        .ok_or_else(|| anyhow!(\"fixture identity policy returned the wrong representation\"))\n}\n\nfn unit_id(ordinal: SyntheticIdentityOrdinal) -> Result<[u8; 4]> {\n    match generate_synthetic_identity(SyntheticIdentityKind::DeviceUnitId, ordinal) {\n        SyntheticIdentityValue::DeviceUnitId(value) => Ok(value),\n        _ => Err(anyhow!(","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/AprilNEA/OpenLogi/blob/e846e6f4b4405e33bd6a9aaf949a482ce34cb6d8/crates/openlogi-cli/src/cmd/fixture/record_profile/sanitize.rs#L37-L73","documentation":"Raised by `ordinal` in `record_profile/sanitize.rs` when converting a device's index (index+1) into a `SyntheticIdentityOrdinal` fails — either the value overflows `u16` or the candidate ordinal is rejected by `SyntheticIdentityOrdinal::new` (e.g. zero is invalid). It means the captured inventory contains more paired devices than the synthetic-identity scheme can name (65,535), or an index arithmetic bug produced zero.","triggerScenarios":"Calling `inventory` or `standalone` sanitization on a `DeviceInventory`/`StandaloneDevice` whose `paired`/device list length exceeds `u16::MAX - 1` entries, or an index wrap (via `saturating_add` on `usize::MAX`) yields 0 which `SyntheticIdentityOrdinal::new` rejects.","commonSituations":"Effectively only reachable with a corrupted or hostile agent snapshot reporting an absurd number of paired devices, or a sanitizer indexing bug; real receivers hold far fewer devices, so this is a defensive overflow guard.","solutions":["Inspect the snapshot's `paired` length — if it is absurd, the agent snapshot is corrupt; restart the agent.","Verify the sanitizer iterates indices from 0 without a pre-increment bug that could push the ordinal out of range.","If a legit large inventory is intended, the synthetic-identity ordinal width in `openlogi-fixture` would need widening — propose that upstream rather than bypassing the guard."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if inventory.paired.len() > u16::MAX as usize { eprintln!(\"inventory too large to sanitize\"); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat absurdly large paired lists as corrupt agent snapshots and restart the agent.","Keep the ordinal guard in place — do not bypass it; widen `SyntheticIdentityOrdinal` upstream if ever needed.","Add a sanitizer test with maximum-size input to pin the overflow behavior."],"tags":["rust","cli","sanitization","overflow","fixtures"],"backgroundTag":"value-out-of-range","analyzedSha":"e846e6f4b4405e33bd6a9aaf949a482ce34cb6d8","analyzedAt":"2026-09-13T03:07:16.451Z","contentChangedAt":"2026-09-13T03:07:16.451Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}