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

Fix panic when parsing improper scientific notation. #700

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

schungx
Copy link
Contributor

@schungx schungx commented Feb 6, 2025

This fixes #697

Copy link
Owner

@paupino paupino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for fixing this!

@@ -3373,10 +3373,18 @@ fn it_can_parse_scientific_notation() {
("12345E-28", "0.0000000000000000000000012345"),
("1.2345E0", "1.2345"),
("1E28", "10000000000000000000000000000"),
(
"-20165.4676_e-+4294967292",
"ERR:Scale exceeds the maximum precision allowed: 4294967292 > 28",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Stylistically, I'd probably shift this test case to use a Result instead - just to keep "the way to write tests" consistent (e.g. like this:

fn it_can_parse_exact_highly_significant_numbers() {
use rust_decimal::Error;
let tests = &[
(
"11.111111111111111111111111111",
Ok("11.111111111111111111111111111".to_string()),
),
("11.11111111111111111111111111111", Err(Error::Underflow)),
("11.1111111111111111111111111115", Err(Error::Underflow)),
("115.111111111111111111111111111", Err(Error::Underflow)),
("1115.11111111111111111111111111", Err(Error::Underflow)),
("11.1111111111111111111111111195", Err(Error::Underflow)),
("99.9999999999999999999999999995", Err(Error::Underflow)),
("-11.1111111111111111111111111195", Err(Error::Underflow)),
("-99.9999999999999999999999999995", Err(Error::Underflow)),
(
"3.1415926535897932384626433832",
Ok("3.1415926535897932384626433832".to_string()),
),
("8808257419827262908.5944405087133154018", Err(Error::Underflow)),
("8097370036018690744.2590371109596744091", Err(Error::Underflow)),
("8097370036018690744.2590371149596744091", Err(Error::Underflow)),
("8097370036018690744.2590371159596744091", Err(Error::Underflow)),
("1.234567890123456789012345678949999", Err(Error::Underflow)),
(".00000000000000000000000000001", Err(Error::Underflow)),
(".10000000000000000000000000000", Err(Error::Underflow)),
];
for &(value, ref expected) in tests.iter() {
let actual = Decimal::from_str_exact(value).map(|d| d.to_string());
assert_eq!(*expected, actual);
}
}
)

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.

Panic found during fuzzing
2 participants