{"record":{"id":"930f09b932a8bd38","repo":"pydantic/monty","slug":"nibble-fits-usize","errorCode":null,"errorMessage":"nibble fits usize","messagePattern":"nibble fits usize","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"info","filePath":"crates/monty/src/modules/binascii.rs","lineNumber":554,"sourceCode":"        0x26d9_30ac,\n        0x76dc_4190,\n        0x6b6b_51f4,\n        0x4db2_6158,\n        0x5005_713c,\n        0xedb8_8320,\n        0xf00f_9344,\n        0xd6d6_a3e8,\n        0xcb61_b38c,\n        0x9b64_c2b0,\n        0x86d3_d2d4,\n        0xa00a_e278,\n        0xbdbd_f21c,\n    ];\n\n    let mut crc = !seed;\n    for byte in data {\n        crc ^= u32::from(*byte);\n        crc = (crc >> 4) ^ NIBBLE_TABLE[usize::try_from(crc & 0x0f).expect(\"nibble fits usize\")];\n        crc = (crc >> 4) ^ NIBBLE_TABLE[usize::try_from(crc & 0x0f).expect(\"nibble fits usize\")];\n    }\n    !crc\n}\n\n/// Computes the CRC-16 of `data`, continuing from `seed`.\n///\n/// CRC-16/XMODEM: polynomial `0x1021`, unreflected, no final xor — the\n/// checksum BinHex 4.0 carried, which `crc_hqx` outlived.\nfn crc_hqx(data: &[u8], seed: u16) -> u16 {\n    let mut crc = seed;\n    for byte in data {\n        crc ^= u16::from(*byte) << 8;\n        for _ in 0..8 {\n            crc = if crc & 0x8000 == 0 {\n                crc << 1\n            } else {\n                (crc << 1) ^ 0x1021","sourceCodeStart":536,"sourceCodeEnd":572,"githubUrl":"https://github.com/pydantic/monty/blob/adc986b362e3961f407868cb118a99fe831b9e61/crates/monty/src/modules/binascii.rs#L536-L572","documentation":"Internal `expect` in the table-driven `crc32`: `crc & 0x0f` yields a value in 0..=15, which always fits `usize`, so indexing `NIBBLE_TABLE` cannot fail. The message ('nibble fits usize') documents why the conversion is infallible. Users cannot trigger it via `binascii.crc32` with any input data or seed.","triggerScenarios":"Unreachable; would require the mask `0x0f` and the table size (16) to fall out of sync in an edit.","commonSituations":"Contributor-only, e.g. swapping to a different nibble-table width.","solutions":["No runtime action; keep the `& 0x0f` mask matched to the 16-entry table."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep nibble masks and lookup-table sizes derived from one constant (e.g. `const NIBBLES: usize = 16;` sized from the mask)."],"tags":["rust","internal-invariant","crc32"],"backgroundTag":"internal-invariant-violation","analyzedSha":"adc986b362e3961f407868cb118a99fe831b9e61","analyzedAt":"2026-09-13T19:19:18.698Z","contentChangedAt":"2026-09-13T19:19:18.698Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}