pydantic/monty · info
nibble fits usize
Error message
nibble fits usize
What it means
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.
Source
Thrown at crates/monty/src/modules/binascii.rs:554
0x26d9_30ac,
0x76dc_4190,
0x6b6b_51f4,
0x4db2_6158,
0x5005_713c,
0xedb8_8320,
0xf00f_9344,
0xd6d6_a3e8,
0xcb61_b38c,
0x9b64_c2b0,
0x86d3_d2d4,
0xa00a_e278,
0xbdbd_f21c,
];
let mut crc = !seed;
for byte in data {
crc ^= u32::from(*byte);
crc = (crc >> 4) ^ NIBBLE_TABLE[usize::try_from(crc & 0x0f).expect("nibble fits usize")];
crc = (crc >> 4) ^ NIBBLE_TABLE[usize::try_from(crc & 0x0f).expect("nibble fits usize")];
}
!crc
}
/// Computes the CRC-16 of `data`, continuing from `seed`.
///
/// CRC-16/XMODEM: polynomial `0x1021`, unreflected, no final xor — the
/// checksum BinHex 4.0 carried, which `crc_hqx` outlived.
fn crc_hqx(data: &[u8], seed: u16) -> u16 {
let mut crc = seed;
for byte in data {
crc ^= u16::from(*byte) << 8;
for _ in 0..8 {
crc = if crc & 0x8000 == 0 {
crc << 1
} else {
(crc << 1) ^ 0x1021View on GitHub (pinned to adc986b362)
Solutions
- No runtime action; keep the `& 0x0f` mask matched to the 16-entry table.
Defensive patterns
Strategy: validation
Prevention
- Keep nibble masks and lookup-table sizes derived from one constant (e.g. `const NIBBLES: usize = 16;` sized from the mask).
When it happens
Trigger: Unreachable; would require the mask `0x0f` and the table size (16) to fall out of sync in an edit.
Common situations: Contributor-only, e.g. swapping to a different nibble-table width.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- reduced below 2**32
- gather commit frame id is not a GatherFuture
- gather item is not a Coroutine, ExternalFuture, or GatherFut
- Cannot get identity of Dereferenced object
- invalid ascii byte
AI-assisted analysis of pydantic/monty@adc986b362 (2026-09-13).
Data as JSON: /api/errors/930f09b932a8bd38.
Report an issue: GitHub.