pydantic/monty · error
fingerprint field length fits u32
Error message
fingerprint field length fits u32
What it means
An internal `expect` inside the FNV-1a `update` helper used by the test-only `static_strings_fingerprint()`. The helper hashes length-prefixed byte slices and asserts each slice's length fits in a `u32` before writing the prefix — trivially true for the static-string identities and small serializations it is fed. It cannot be triggered by user input; it fires only if the fingerprint function were ever pointed at data exceeding u32 length.
Source
Thrown at crates/monty/src/intern.rs:1225
#[strum(serialize = "quotetabs")]
Quotetabs,
/// `istext` parameter of `binascii.b2a_qp()`.
#[strum(serialize = "istext")]
Istext,
/// `header` parameter of the `binascii` quoted-printable pair.
#[strum(serialize = "header")]
Header,
}
/// Computes an FNV-1a hash over static-string identities and serialization.
#[cfg(test)]
pub(crate) fn static_strings_fingerprint() -> u64 {
const OFFSET_BASIS: u64 = 0xcbf2_9ce4_8422_2325;
const PRIME: u64 = 0x0100_0000_01b3;
fn update(hash: &mut u64, bytes: &[u8]) {
for byte in u32::try_from(bytes.len())
.expect("fingerprint field length fits u32")
.to_le_bytes()
{
*hash ^= u64::from(byte);
*hash = hash.wrapping_mul(PRIME);
}
for byte in bytes {
*hash ^= u64::from(*byte);
*hash = hash.wrapping_mul(PRIME);
}
}
let mut hash = OFFSET_BASIS;
for value in StaticStrings::iter() {
update(&mut hash, &(value as u16).to_le_bytes());
update(&mut hash, format!("{value:?}").as_bytes());
let string: &'static str = value.into();
update(&mut hash, string.as_bytes());
update(View on GitHub (pinned to adc986b362)
Solutions
- This u32::try_from guards hashing of byte-slice lengths; a failure means a slice longer than u32::MAX (~4 GiB) was passed, impossible for the static-string fingerprint which hashes small fixed buffers and enum serializations.
- If it ever fires, check what input grew beyond u32::MAX and switch the fingerprint's length encoding to u64 if a genuinely huge slice must be supported.
When it happens
Trigger: Thrown at crates/monty/src/intern.rs:1225 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of pydantic/monty@adc986b362 (2026-09-13).
Data as JSON: /api/errors/51cfc69985150501.
Report an issue: GitHub.