{"record":{"id":"c0fffd153b5c9a89","repo":"tursodatabase/turso","slug":"payload-size-too-large-for-encoding","errorCode":null,"errorMessage":"Payload size too large for encoding","messagePattern":"Payload size too large for encoding","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/json/jsonb.rs","lineNumber":904,"sourceCode":"                    size_bytes[0],\n                    size_bytes[1],\n                ])\n            }\n\n            // Extra large payload (fits in 4 bytes)\n            size if size <= 0xFFFFFFFF => {\n                let size_bytes = (size as u32).to_be_bytes();\n                HeaderFormat::FourBytes([\n                    (element_type as u8) | (SIZE_MARKER_32BIT << 4),\n                    size_bytes[0],\n                    size_bytes[1],\n                    size_bytes[2],\n                    size_bytes[3],\n                ])\n            }\n\n            // Payload too large\n            _ => panic!(\"Payload size too large for encoding\"),\n        }\n    }\n\n    fn get_size_bytes(slice: &[u8], start: usize, count: usize) -> Result<&[u8]> {\n        match slice.get(start..start + count) {\n            Some(bytes) => Ok(bytes),\n            None => bail_parse_error!(\"Failed to read header size\"),\n        }\n    }\n}\n\npub struct ArrayIteratorState {\n    cursor: usize,\n    end: usize,\n    index: usize,\n}\n\npub struct ObjectIteratorState {","sourceCodeStart":886,"sourceCodeEnd":922,"githubUrl":"https://github.com/tursodatabase/turso/blob/0e69fa4af1a4ff174ecb61d19f728df0ab41c218/core/json/jsonb.rs#L886-L922","documentation":"JSONB encoding sizes each element payload with a header supporting at most 0xFFFFFFFF bytes (a 32-bit size marker). A single payload larger than 4 GiB cannot be represented, so the header builder panics.","triggerScenarios":"Storing or parsing a JSON document whose single string/number payload (or container payload) exceeds 4 GiB: json_insert of a giant string, JSONB parsing of a huge document built by concatenating logs or base64 blobs.","commonSituations":"Event/log blobs accumulated into one JSON value; tests synthesizing huge literals; importing machine-generated JSON without size checks.","solutions":["Keep individual JSON values under 4 GiB; split large content across rows","Validate serialized size before inserting or parsing JSONB","Store oversized payloads as plain BLOBs outside the JSON document"],"exampleFix":"-- before\nINSERT INTO events VALUES (json(?)); -- ? is a 5 GiB JSON string -> panic\n\n-- after\n-- guard at the application boundary:\n-- assert!(value.len() <= 0xFFFF_FFFF, \"json value exceeds 4 GiB JSONB limit\");\nINSERT INTO blobs VALUES (?); -- oversized content as a plain blob","handlingStrategy":"validation","validationCode":"const JSONB_MAX_PAYLOAD: usize = 0xFFFF_FFFF;\nfn fits_jsonb(v: &str) -> bool { v.len() <= JSONB_MAX_PAYLOAD }\nassert!(fits_jsonb(&json_text), \"json value exceeds 4 GiB JSONB limit\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Cap JSON values at 4 GiB in application validation","Store huge payloads as BLOB columns, not as members of one JSON document"],"tags":["json","jsonb","size-limit","encoding","panic"],"backgroundTag":"payload-too-large","analyzedSha":"0e69fa4af1a4ff174ecb61d19f728df0ab41c218","analyzedAt":"2026-08-20T07:02:18.389Z","contentChangedAt":"2026-08-20T07:02:18.389Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}