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

Return error rather than panic in FromSql when overflow #652

Closed
xiangjinwu opened this issue Mar 26, 2024 · 1 comment · Fixed by #653
Closed

Return error rather than panic in FromSql when overflow #652

xiangjinwu opened this issue Mar 26, 2024 · 1 comment · Fixed by #653
Labels

Comments

@xiangjinwu
Copy link

Get binary encoding from PostgreSQL:

test=# select numeric_send(1e28);
      numeric_send      
------------------------
 \x00010007000000000001
(1 row)

test=# select numeric_send(1e29);
      numeric_send      
------------------------
 \x0001000700000000000a
(1 row)

Call FromSql on Decimal:

    println!(
        "{:?}",
        Decimal::from_sql(
            &Type::NUMERIC,
            &[0x00, 0x01, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01]
        )
    );
    println!(
        "{:?}",
        Decimal::from_sql(
            &Type::NUMERIC,
            &[0x00, 0x01, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a]
        )
    );

Expected:

Ok(100000000000000000000)
Err(overflow error)

Actual:

Ok(100000000000000000000)
thread 'main' panicked at rust_decimal-1.34.3/src/arithmetic_impls.rs:232:18:
Multiplication overflowed
@paupino
Copy link
Owner

paupino commented Mar 27, 2024

Thank you for raising this! It is fortunately an easy issue to fix - I'll see if I can get something out shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants