From b7b2b72a2e58fc68b4ce977edf5f0ca05ce9be36 Mon Sep 17 00:00:00 2001 From: Jared Reyes Date: Sun, 8 Feb 2026 20:20:32 +1100 Subject: [PATCH 1/2] Fix panic in JSONB decoder on invalid version byte Replace assert_eq! with proper error handling to prevent panic on untrusted database input. The Decode trait contract requires returning Result, but the assertion would cause a panic instead. This issue was discovered through fuzzing and can be triggered by: - Malformed JSONB data in the database - Database corruption - Future PostgreSQL versions with different JSONB formats The fix replaces the assertion with a conditional check that returns an appropriate error, maintaining the Decode trait contract and allowing applications to handle the error gracefully. Signed-off-by: Jared Reyes --- sqlx-postgres/src/types/json.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/sqlx-postgres/src/types/json.rs b/sqlx-postgres/src/types/json.rs index 32f886c781..32549ee649 100644 --- a/sqlx-postgres/src/types/json.rs +++ b/sqlx-postgres/src/types/json.rs @@ -85,11 +85,14 @@ where let mut buf = value.as_bytes()?; if value.format() == PgValueFormat::Binary && value.type_info == PgTypeInfo::JSONB { - assert_eq!( - buf[0], 1, - "unsupported JSONB format version {}; please open an issue", - buf[0] - ); + // Check JSONB version byte - PostgreSQL currently only supports version 1 + if buf[0] != 1 { + return Err(format!( + "unsupported JSONB format version {} (expected 1)", + buf[0] + ) + .into()); + } buf = &buf[1..]; } From b7ab16bd0d35afb3488c1b53365a4600d415df10 Mon Sep 17 00:00:00 2001 From: Jared Reyes Date: Mon, 9 Feb 2026 08:11:38 +1100 Subject: [PATCH 2/2] Fix formatting Signed-off-by: Jared Reyes --- sqlx-postgres/src/types/json.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/sqlx-postgres/src/types/json.rs b/sqlx-postgres/src/types/json.rs index 32549ee649..88e4b8468a 100644 --- a/sqlx-postgres/src/types/json.rs +++ b/sqlx-postgres/src/types/json.rs @@ -87,11 +87,9 @@ where if value.format() == PgValueFormat::Binary && value.type_info == PgTypeInfo::JSONB { // Check JSONB version byte - PostgreSQL currently only supports version 1 if buf[0] != 1 { - return Err(format!( - "unsupported JSONB format version {} (expected 1)", - buf[0] - ) - .into()); + return Err( + format!("unsupported JSONB format version {} (expected 1)", buf[0]).into(), + ); } buf = &buf[1..];