pydantic/monty · error
BytesId overflow
Error message
BytesId overflow
What it means
An internal overflow guard in `Interns::intern_bytes`, which assigns sequential `BytesId`s to interned byte strings. The assertion fires if the interned-bytes table grows beyond the `BytesId` representation limit — i.e. more distinct byte objects than the id space allows within a single compilation/execution. It is effectively unreachable for real workloads; it exists so exhaustion is a clear panic rather than silent id wraparound.
Source
Thrown at crates/monty/src/intern.rs:1413
/// * If the string was already interned, returns the existing string id
/// * Otherwise, stores the string and returns a new string id
pub fn intern(&mut self, s: &str) -> StringId {
intern_str(&mut self.string_map, &mut self.strings, s)
}
/// Looks up the `StringId` for a string already interned (or ascii/static).
///
/// Mirrors [`Interns::get_string_id_by_name`] so the compiler can resolve
/// builtin names before the runtime table is built.
pub fn get_string_id_by_name(&self, s: &str) -> Option<StringId> {
get_string_id_by_name(&self.string_map, s)
}
/// Interns bytes, returning its `BytesId`.
///
/// Unlike interns, bytes are not deduplicated (bytes literals are rare).
pub fn intern_bytes(&mut self, b: &[u8]) -> BytesId {
let id = BytesId(self.bytes.len().try_into().expect("BytesId overflow"));
self.bytes.push(WithHash::for_bytes(b.to_vec()));
id
}
/// Interns a long integer, returning its `LongIntId`.
///
/// Big integers are not deduplicated since literals exceeding i64 are rare.
pub fn intern_long_int(&mut self, bi: BigInt) -> LongIntId {
let id = LongIntId(self.long_ints.len().try_into().expect("LongIntId overflow"));
self.long_ints.push(WithHash::for_long_int(bi));
id
}
/// Looks up a string by its `StringId`.
#[inline]
pub fn get_str(&self, id: StringId) -> &str {
get_str(&self.strings, id)
}View on GitHub (pinned to adc986b362)
Solutions
- Interning a byte string exceeded the StringId/BytesId capacity (index space exhausted); typical fix is widening the id type or enforcing an explicit intern limit before allocation.
- Callers cannot recover mid-compilation: the table indexes are baked into bytecode; the error should abort compilation with a clear resource-limit message rather than be retried.
- Prevent by bounding the number of distinct byte strings accepted per compilation via ResourceLimits.
When it happens
Trigger: Thrown at crates/monty/src/intern.rs:1413 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/42da6f242aef1742.
Report an issue: GitHub.