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

Signed decimal e-notation parsing bug #6728

Closed
gruuya opened this issue Nov 13, 2024 · 1 comment · Fixed by #6729
Closed

Signed decimal e-notation parsing bug #6728

gruuya opened this issue Nov 13, 2024 · 1 comment · Fixed by #6729
Labels
arrow Changes to the arrow crate bug

Comments

@gruuya
Copy link
Contributor

gruuya commented Nov 13, 2024

Describe the bug
Parsing signed decimal numbers in e-notation has a bug, whereby the parsed values is magnified by an order of magnitude (leading to potential false overflows).

To Reproduce
Run the following test (e.g. in arrow-cast/src/parse.rs)

    #[test]
    fn test_negative_decimal_e_notation() {
        assert_eq!(
            parse_decimal::<Decimal128Type>("-1e3", 38, 6).unwrap(),
            -1000000000i128,
        );

        assert_eq!(
            parse_decimal::<Decimal128Type>("-1e31", 38, 6).unwrap(),
            -10000000000000000000000000000000000000i128,
        );
    }

The first assertion will fail, as the parsed value is erroneously -11000000000, while the second example will panic with parse decimal overflow (-1e31), even though the value fits in the specified precision/scale range.

Expected behavior
The first test case above should return -1000000000i128 (i.e. 3 zeros from e3 + additional 6 zeros from the scale).

The seconds case shouldn't overflow and should instead return -10000000000000000000000000000000000000i128 (i.e. 31 zeros from e31 + additional 6 zeros from the scale).

Additional context

@gruuya gruuya added the bug label Nov 13, 2024
@gruuya gruuya changed the title Negative decimal e-notation parsing bug Signed decimal e-notation parsing bug Nov 13, 2024
@alamb alamb added the arrow Changes to the arrow crate label Nov 16, 2024
@alamb
Copy link
Contributor

alamb commented Nov 16, 2024

label_issue.py automatically added labels {'arrow'} from #6729

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

Successfully merging a pull request may close this issue.

2 participants