Fix panic in JSONB decoder on invalid version byte#4158
Open
jrey8343 wants to merge 2 commits intolaunchbadge:mainfrom
Open
Fix panic in JSONB decoder on invalid version byte#4158jrey8343 wants to merge 2 commits intolaunchbadge:mainfrom
jrey8343 wants to merge 2 commits intolaunchbadge:mainfrom
Conversation
Replace assert_eq! with proper error handling to prevent panic on untrusted database input. The Decode trait contract requires returning Result<T, Error>, 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 <jaredreyespt@gmail.com>
Signed-off-by: Jared Reyes <jaredreyespt@gmail.com>
c8d5da8 to
b7ab16b
Compare
This was referenced Feb 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4157
Summary
Replaces
assert_eq!with proper error handling in the JSONB decoder to prevent panics on untrusted database input.Changes
sqlx-postgres/src/types/json.rsWhy This Fix Is Needed
The
Decodetrait contract requires implementations to returnResult<T, Error>, but the current code usesassert_eq!which panics on invalid input. This violates the trait contract and prevents applications from handling errors gracefully.Before
After
Testing
cargo check -p sqlx-postgres)Impact
This fix prevents denial-of-service scenarios where malformed JSONB data could crash applications. It allows applications to handle database errors gracefully through the standard
Resulterror handling pattern.