{"record":{"id":"beb0de1a158bebd0","repo":"BoundaryML/baml","slug":"blob-size-does-not-fit-usize","errorCode":null,"errorMessage":"blob size does not fit usize","messagePattern":"blob size does not fit usize","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/bex_events/src/value/record.rs","lineNumber":237,"sourceCode":"                ValueAvailability::Lost => crate::value::pb::ValueAvailability::Lost as i32,\n            },\n            original_size_bytes: value_ref\n                .original_size_bytes\n                .and_then(|value| u64::try_from(value).ok()),\n            retained_size_bytes: value_ref\n                .retained_size_bytes\n                .and_then(|value| u64::try_from(value).ok()),\n            diagnostic: value_ref.diagnostic.clone(),\n        }\n    }\n}\n\nimpl TryFrom<crate::value::pb::BlobRefV1> for BlobRef {\n    type Error = io::Error;\n\n    fn try_from(value: crate::value::pb::BlobRefV1) -> Result<Self, Self::Error> {\n        let size_bytes = usize::try_from(value.size_bytes).map_err(|_| {\n            io::Error::new(io::ErrorKind::InvalidData, \"blob size does not fit usize\")\n        })?;\n        Ok(Self {\n            algorithm: value.algorithm,\n            digest: value.digest,\n            size_bytes,\n        })\n    }\n}\n\nimpl From<&BlobRef> for crate::value::pb::BlobRefV1 {\n    fn from(value: &BlobRef) -> Self {\n        Self {\n            algorithm: value.algorithm.clone(),\n            digest: value.digest.clone(),\n            size_bytes: u64::try_from(value.size_bytes).unwrap_or(u64::MAX),\n        }\n    }\n}","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/bex_events/src/value/record.rs#L219-L255","documentation":"BlobRefV1.size_bytes is a 64-bit proto integer; converting it to usize for the internal BlobRef fails when the value is negative or larger than usize::MAX. The TryFrom<crate::value::pb::BlobRefV1> impl surfaces this as InvalidData with this message.","triggerScenarios":"Decoding a BlobRefV1 whose size_bytes was written as a negative number or a value exceeding the target platform's usize (notably 32-bit readers).","commonSituations":"Corrupted blob references, writer bugs storing sentinels, 32-bit builds reading traces produced on 64-bit hosts with very large blobs.","solutions":["Correct the writer so blob size_bytes is always a valid non-negative u64 within usize range","Use a 64-bit reader build if blob sizes are legitimately near the limit","Validate blob refs at ingest and drop records with implausible sizes","Guard the conversion manually with usize::try_from(...).ok() and handle None upstream"],"exampleFix":"// before\nlet size_bytes = usize::try_from(value.size_bytes).map_err(...)?;\n// after\nlet size_bytes = usize::try_from(value.size_bytes).unwrap_or(0); // or skip record when 0","handlingStrategy":"type-guard","validationCode":"fn blob_size_ok(v: &pb::BlobRefV1) -> bool { v.size_bytes >= 0 && (v.size_bytes as u64) <= usize::MAX as u64 }","typeGuard":"fn valid_blob_ref(b: &pb::BlobRefV1) -> bool { usize::try_from(b.size_bytes).is_ok() }","tryCatchPattern":"BlobRef::try_from(raw).map_err(|e| if e.to_string().contains(\"blob size\") { skip_blob(raw.digest) } else { e })","preventionTips":["Emit blob sizes as plain non-negative u64","Validate blob refs before writing them into streams","Skip-and-log implausible blob refs instead of failing the whole stream"],"tags":["rust","protobuf","integer-overflow","deserialization"],"backgroundTag":"value-out-of-range","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}