Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent scale of 29 when hydrating from unbound numeric data types in Postgresql #647

Merged
merged 1 commit into from
Feb 10, 2024

Conversation

paupino
Copy link
Owner

@paupino paupino commented Feb 10, 2024

This fixes #645

The way this fixes things is to avoid scale of 29 being represented internally via the postgres driver. A scale of 29, while technically available in some very minimal use cases is considered undefined behavior in rust-decimal and typically guarded against (i.e. it's very difficult, if not impossible, to reproduce this without going through the postgres driver).

Consequently, applying a ceiling to the rescale operation in this case is appropriate.

Added a couple of tests which both fail without the fix (i.e. reproducing the bug):

---- postgres::driver::test::read_small_unconstrained_numeric_type_addition stdout ----
thread 'postgres::driver::test::read_small_unconstrained_numeric_type_addition' panicked at src/postgres/driver.rs:292:9:
assertion `left == right` failed
  left: 10000000000014780214000000000
 right: 0.1000000000001478021400000000
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

---- postgres::driver::test::read_small_unconstrained_numeric_type stdout ----
thread 'postgres::driver::test::read_small_unconstrained_numeric_type' panicked at src/postgres/driver.rs:271:9:
assertion `left == right` failed
  left: "0.10000000000000000000000000000"
 right: "0.1000000000000000000000000000"

@paupino paupino changed the title Prevent scale of 29 from postgresql hydration Prevent scale of 29 when hydrating from unbound numeric data types in Postgresql Feb 10, 2024
@paupino paupino enabled auto-merge (squash) February 10, 2024 20:16
@paupino paupino merged commit 1a119c7 into master Feb 10, 2024
5 checks passed
@paupino paupino deleted the issue/645 branch February 10, 2024 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deserializing Decimals from Postgres using the db-postgres feature can lead to invalid Decimal instances
1 participant