{"record":{"id":"51cfc69985150501","repo":"pydantic/monty","slug":"fingerprint-field-length-fits-u32","errorCode":null,"errorMessage":"fingerprint field length fits u32","messagePattern":"fingerprint field length fits u32","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/monty/src/intern.rs","lineNumber":1225,"sourceCode":"    #[strum(serialize = \"quotetabs\")]\n    Quotetabs,\n    /// `istext` parameter of `binascii.b2a_qp()`.\n    #[strum(serialize = \"istext\")]\n    Istext,\n    /// `header` parameter of the `binascii` quoted-printable pair.\n    #[strum(serialize = \"header\")]\n    Header,\n}\n\n/// Computes an FNV-1a hash over static-string identities and serialization.\n#[cfg(test)]\npub(crate) fn static_strings_fingerprint() -> u64 {\n    const OFFSET_BASIS: u64 = 0xcbf2_9ce4_8422_2325;\n    const PRIME: u64 = 0x0100_0000_01b3;\n\n    fn update(hash: &mut u64, bytes: &[u8]) {\n        for byte in u32::try_from(bytes.len())\n            .expect(\"fingerprint field length fits u32\")\n            .to_le_bytes()\n        {\n            *hash ^= u64::from(byte);\n            *hash = hash.wrapping_mul(PRIME);\n        }\n        for byte in bytes {\n            *hash ^= u64::from(*byte);\n            *hash = hash.wrapping_mul(PRIME);\n        }\n    }\n\n    let mut hash = OFFSET_BASIS;\n    for value in StaticStrings::iter() {\n        update(&mut hash, &(value as u16).to_le_bytes());\n        update(&mut hash, format!(\"{value:?}\").as_bytes());\n        let string: &'static str = value.into();\n        update(&mut hash, string.as_bytes());\n        update(","sourceCodeStart":1207,"sourceCodeEnd":1243,"githubUrl":"https://github.com/pydantic/monty/blob/adc986b362e3961f407868cb118a99fe831b9e61/crates/monty/src/intern.rs#L1207-L1243","documentation":"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.","triggerScenarios":"Thrown at crates/monty/src/intern.rs:1225 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"adc986b362e3961f407868cb118a99fe831b9e61","analyzedAt":"2026-09-13T19:19:18.698Z","contentChangedAt":"2026-09-13T19:19:18.698Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}