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 #77, integer overflow when parsing JSON scientific notation number. #80

Merged
merged 2 commits into from
Jun 8, 2015
Merged

Fix #77, integer overflow when parsing JSON scientific notation number. #80

merged 2 commits into from
Jun 8, 2015

Conversation

ProtectedMode
Copy link
Contributor

I think this should fix it, but make sure to review it. 😃

@@ -267,8 +267,16 @@ impl<Iter> Deserializer<Iter>
while !self.eof() {
match self.ch_or_null() {
c @ b'0' ... b'9' => {
exp *= 10;
exp += (c as i32) - (b'0' as i32);
macro_rules! try_or_invalid {
Copy link
Member

Choose a reason for hiding this comment

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

Could you pull this macro out to the top level since I also use it for parse_decimal?

@erickt
Copy link
Member

erickt commented May 20, 2015

Thanks! Could you also add a test for this?

@tomprogrammer
Copy link
Contributor

Could you expand your patch to include Lines 238 & 239 please. I guess they can panic on invalid input also.

@ProtectedMode
Copy link
Contributor Author

@erickt, I'm unsure about how test_de works. Does it convert the given Rust value to JSON, and then match it with the expected token output? If so, how do you let it output the scientific notation for a given number?

@tomprogrammer, since dec and res there are floating-point numbers, they can't overflow as far as I am aware.

@tomprogrammer
Copy link
Contributor

@ProtectedMode You are right, there can't be a panic in these lines.

@erickt
Copy link
Member

erickt commented May 20, 2015

@ProtectedMode: Check out https://github.com/serde-rs/serde/blob/master/serde_tests/tests/test_json.rs#L705, which was the test I added for parsing decimal overflow. You probably could just add

("1e777777777777777777777777777", Error::SyntaxError(ErrorCode::InvalidNumber, 1, 22)),

@ProtectedMode
Copy link
Contributor Author

@erickt, it seems I was confused and missed that file, now it makes sense.

I added your test, I will squash the commits if you want.

erickt added a commit that referenced this pull request Jun 8, 2015
Fix #77, integer overflow when parsing JSON scientific notation number.
@erickt erickt merged commit 7dc1a64 into serde-rs:master Jun 8, 2015
@frewsxcv
Copy link
Contributor

frewsxcv commented Jun 8, 2015

👏

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

Successfully merging this pull request may close these issues.

None yet

4 participants