{"record":{"id":"c99ccf56162a58a6","repo":"BoundaryML/baml","slug":"invalid-bigint-hex-string-len-bytes","errorCode":null,"errorMessage":"Invalid bigint hex string ({len} bytes)","messagePattern":"Invalid bigint hex string \\((.+?) bytes\\)","errorType":"error_code","errorClass":"CtypesError","httpStatus":null,"severity":"error","filePath":"baml_language/crates/bridge_ctypes/src/error.rs","lineNumber":23,"sourceCode":"/// Errors that can occur during value encoding/decoding for the bridge.\n#[derive(Debug, Error)]\npub enum CtypesError {\n    #[error(\"Protobuf decode error: {0}\")]\n    ProtobufDecode(#[from] prost::DecodeError),\n\n    #[error(\"Null buffer pointer\")]\n    NullBuffer,\n\n    #[error(\"Invalid handle key: {0}\")]\n    InvalidHandleKey(u64),\n\n    #[error(\"Map entry missing key\")]\n    MapEntryMissingKey,\n\n    /// Carries only the input length, not the input itself — untrusted hex\n    /// blobs can be up to the FFI decode cap (~67M chars), and embedding\n    /// them in error messages bloats logs and exposes payload contents.\n    #[error(\"Invalid bigint hex string ({len} bytes)\")]\n    InvalidBigint { len: usize },\n\n    /// Carries only the input length for over-cap decimal type literals, so a\n    /// hostile descriptor cannot amplify logs by echoing its full payload.\n    #[error(\"Invalid decimal bigint literal ({len} bytes)\")]\n    InvalidBigintLiteral { len: usize },\n\n    #[error(\n        \"Invalid InboundValue.value_type: a root union or optional does not identify one exact selected type\"\n    )]\n    InvalidInboundValueTypeRootUnion,\n\n    #[error(\"Union selected type `{selected}` is not a member of declared union `{union}`\")]\n    UnionSelectedTypeNotMember { selected: String, union: String },\n\n    #[error(\"Internal error: {0}\")]\n    InternalError(String),\n}","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/bridge_ctypes/src/error.rs#L5-L41","documentation":"CtypesError::InvalidBigint { len } signals a bigint value decoded over the bridge was not a valid hex string. Per the source comment, the error deliberately carries only the input's byte length — not the payload — because untrusted hex blobs can reach the ~67M-char FFI cap and embedding them would bloat logs and leak payload contents.","triggerScenarios":"Passing an InboundValue for a bigint/integer field whose bytes are not valid hex (e.g. non-hex characters, odd length, empty, or raw binary instead of hex-encoded text).","commonSituations":"Host code sending raw integer bytes instead of hex text; lower/uppercase or 0x-prefix mismatches the decoder doesn't accept; corrupted payloads truncated mid-hex-digit; user-supplied numbers passed through unvalidated.","solutions":["Hex-encode bigints as clean hex text (no 0x prefix, even number of hex digits) before the FFI call.","Validate hex in the host: check every char is [0-9a-fA-F] and len % 2 == 0, and log the length (the error only reports len).","Trim whitespace/control characters from the payload before encoding.","Check for encoding bugs (e.g. accidentally sending base64 or raw bytes)."],"exampleFix":"// before\npayload = str(value).encode()  # \"12345\" decimal, not hex -> InvalidBigint\n// after\npayload = format(\"{:x}\", value).encode()  # proper hex\nassert len(payload) % 2 == 0 and all(c in b\"0123456789abcdef\" for c in payload)","handlingStrategy":"validation","validationCode":"import re\nHEX_RE = re.compile(r\"^[0-9a-fA-F]+$\")\ndef ensure_hex_bigint(b: bytes):\n    if not b or len(b) % 2 != 0 or not HEX_RE.match(b.decode(\"ascii\", \"strict\")):\n        raise ValueError(\"bigint payload must be even-length hex\")","typeGuard":null,"tryCatchPattern":"try:\n    send_inbound_bigint(payload)\nexcept BridgeError as e:\n    if \"Invalid bigint hex string\" in str(e):\n        raise ValueError(f\"bad hex bigint (len={len(payload)}); check encoding\") from e\n    raise","preventionTips":["Hex-encode bigints (no 0x prefix, even length) before crossing FFI","Never send raw integer bytes where hex text is expected","Log only lengths for untrusted payloads, mirroring the library's own practice"],"tags":["bigint","hex","validation","ffi"],"backgroundTag":"invalid-argument-format","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}