{"record":{"id":"a129f044e5091805","repo":"risingwavelabs/risingwave","slug":"invalid-jsonb-encoding","errorCode":null,"errorMessage":"Invalid jsonb encoding","messagePattern":"Invalid jsonb encoding","errorType":"error_code","errorClass":"ValueEncodingError","httpStatus":null,"severity":"error","filePath":"src/common/src/util/value_encoding/error.rs","lineNumber":31,"sourceCode":"// limitations under the License.\n\nuse thiserror::Error;\n\n#[derive(Error, Debug)]\npub enum ValueEncodingError {\n    #[error(\"Invalid bool value encoding: {0}\")]\n    InvalidBoolEncoding(u8),\n    #[error(\"Invalid UTF8 value encoding: {0}\")]\n    InvalidUtf8(#[from] std::string::FromUtf8Error),\n    #[error(\"Invalid Date value encoding: days: {0}\")]\n    InvalidDateEncoding(i32),\n    #[error(\"invalid Timestamp value encoding: secs: {0} nsecs: {1}\")]\n    InvalidTimestampEncoding(i64, u32),\n    #[error(\"invalid Time value encoding: secs: {0} nano: {1}\")]\n    InvalidTimeEncoding(u32, u32),\n    #[error(\"Invalid null tag value encoding: {0}\")]\n    InvalidTagEncoding(u8),\n    #[error(\"Invalid jsonb encoding\")]\n    InvalidJsonbEncoding,\n    #[error(\"Invalid variant encoding\")]\n    InvalidVariantEncoding,\n    #[error(\"Invalid struct encoding: {0}\")]\n    InvalidStructEncoding(\n        #[source]\n        #[backtrace]\n        crate::array::ArrayError,\n    ),\n    #[error(\"Invalid list encoding: {0}\")]\n    InvalidListEncoding(\n        #[source]\n        #[backtrace]\n        crate::array::ArrayError,\n    ),\n    #[error(\"Invalid flag: {0:b}\")]\n    InvalidFlag(u8),\n    #[error(\"Invalid vector item: {0} {1}\")]","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/common/src/util/value_encoding/error.rs#L13-L49","documentation":"ValueEncodingError::InvalidJsonbEncoding is thrown by RisingWave's value_encoding module when a Jsonb column's stored bytes cannot be deserialized back into a JsonbVal. During deserialize_value for DataType::Jsonb (src/common/src/util/value_encoding/mod.rs:382-385), JsonbVal::value_deserialize returns None on malformed bytes, and the code converts that into this error. It indicates the persisted or transmitted encoding of a jsonb datum is corrupt or was written by an incompatible format version.","triggerScenarios":"Calling deserialize_value/deserialize_datum on DataType::Jsonb where the length-prefixed bytea payload is not valid jsonb binary (truncated data, wrong version writer, or bytes produced by a different serializer).","commonSituations":"Reading rows written by an older/newer RisingWave version whose jsonb binary layout changed; manual or external writes to storage that bypass the serializer; corrupted state-store bytes; mixing row encodings (memcompatible vs column-aware) when decoding.","solutions":["Verify the bytes being decoded were produced by JsonbVal::value_serialize with the same encoding version","Check for version skew between the writer and reader clusters and upgrade/downgrade so both use the same value-encoding format","Re-ingest or re-materialize the affected data to rewrite the jsonb bytes","If it comes from user input, validate jsonb input before persisting"],"exampleFix":"// before: decoding untrusted bytes directly\nlet val = JsonbVal::value_deserialize(bytes).ok_or(ValueEncodingError::InvalidJsonbEncoding)?;\n// after: validate the payload round-trips before use\nlet val = JsonbVal::value_deserialize(bytes)\n    .filter(|v| serde_json::to_vec(v.as_scalar_ref().0).is_ok())\n    .ok_or_else(|| ValueEncodingError::InvalidJsonbEncoding)?;","handlingStrategy":"try-catch","validationCode":"fn valid_jsonb_payload(bytes: &[u8]) -> bool {\n    !bytes.is_empty() && JsonbVal::value_deserialize(bytes).is_some()\n}","typeGuard":"fn is_decodable_jsonb(bytes: &[u8]) -> Option<JsonbVal> {\n    JsonbVal::value_deserialize(bytes)\n}","tryCatchPattern":"match deserialize_datum(&DataType::Jsonb, data) {\n    Ok(Some(datum)) => { /* use datum */ }\n    Ok(None) => { /* NULL datum */ }\n    Err(ValueEncodingError::InvalidJsonbEncoding) => {\n        tracing::error!(\"corrupt jsonb bytes; skip or rewrite row\");\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Always serialize jsonb with JsonbVal::value_serialize; never hand-roll the binary layout","Keep writer and reader cluster versions aligned on the value-encoding format","Round-trip test jsonb encode/decode in CI for custom data paths","Guard length prefixes against actual buffer length before decoding"],"tags":["rust","value-encoding","jsonb","deserialization","risingwave"],"backgroundTag":"json-decode-failed","analyzedSha":"6469eb736d691e8e9b8a419a57edd6429ca77417","analyzedAt":"2026-09-11T21:06:21.487Z","contentChangedAt":"2026-09-11T21:06:21.487Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}