-
Notifications
You must be signed in to change notification settings - Fork 154
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
Integer overflow when parsing atom count in molecular formula #733
Comments
That is more atoms than the largest known molecule, I think it's fine. C169719H270466N45688O52238S911 Even if we use a long instead of an integer you are likely to Run out of RAM as the parse actually constructs the atoms. |
I pushed commit before I saw your answer :) Anyway thank you for explanation. |
Almost there, but why not just return out of the loop:
You do the check after the loop but you can overflow back to 0 |
In this case, if overflow will happen in the middle of a number - iterator will stay there and we can't get the other part of the string. |
If it overflows it should be an error non? "Unexpected input" |
So the rest of the string doesn't matter, if someone wants to handle formulas with more than 2 billion hydrogens I think they can write their own parser for that :-) |
I think it should
btw, it is possible to overflow from positive to positive e.g. 4294967298 will be 429496729 and then 2
Absolutely agree:) |
What are the advantages to return 1 if amount of atom is negative value? MolecularFormulaManipulator#parseIsotope
Maybe we could return false? |
I'd have to remember what the old code did but yes count < 0 should probably just be an error |
Fixed via #808 |
If molecular formula has huge amount of atoms then parser calculates it improperly.
Molecular formula: H4294967296
AR: 0 atoms
ER: 1 atom
Molecular formula: H4294967298
AR: 2 atoms
ER: 1 atom
The text was updated successfully, but these errors were encountered: