Skip to content
New issue

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

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

Already on GitHub? # to your account

Fix panic when parsing improper scientific notation. #700

Merged
merged 9 commits into from
Feb 21, 2025

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);
}
}
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for the late reply. Pls go ahead and make this change. Your style definitely look better.

Feel free to close this PR and redo it your way.

Copy link
Owner

Choose a reason for hiding this comment

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

Let's merge your PR first so that you get credit for the contribution. We can always modify the style of the test afterwards (to be fair there are a few to make consistent).

@paupino paupino merged commit 722af9f into paupino:master Feb 21, 2025
15 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Panic found during fuzzing
2 participants