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 integer overflow on libstdc++ #30

Open
grievejia opened this issue Sep 3, 2017 · 4 comments
Open

Signed integer overflow on libstdc++ #30

grievejia opened this issue Sep 3, 2017 · 4 comments

Comments

@grievejia
Copy link

grievejia commented Sep 3, 2017

Here's the input that will trigger the issue:
int_overflow.txt
Feed it into master(c2444ed) parse_stdin built with UndefinedBehaviorSanitizer and linked with libstdc++(shipped with gcc 7.1.1) will crash the parser:

> cat int_overflow.txt | ./parse_stdin
/usr/lib64/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../include/c++/7.1.1/chrono:176:38: runtime error: signed integer overflow: -61948886400 * 1000000000 cannot be represented in type 'long'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /usr/lib64/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../include/c++/7.1.1/chrono:176:38 in

Interestingly, the issue would disappear if I choose to use libc++ instead.

@mayah
Copy link
Owner

mayah commented Sep 4, 2017

Thanks for reporting.

d = 7-0-2

It's parsed as Time type. I think this is not a valid Time value, so this should be rejected in the parser, maybe 😢

mayah added a commit that referenced this issue Sep 8, 2017
If MM is out of month, integer overflow could happen.

BUG=#30
@mayah
Copy link
Owner

mayah commented Sep 8, 2017

I've added a workaround, but this is not a complete fix, I believe.

@grievejia
Copy link
Author

Unfortunately, it is not :( It neither rejects nonsensical date like "2000-2-30", nor accepts valid date like "1800-1-1".
I admit that parsing datetime format in a RFC3339-conforming way is quite hard, though...

@mayah
Copy link
Owner

mayah commented Sep 11, 2017

I know that does not reject nonsense date.
Also, since we're using std::chrono::time_point to represent a time, date before unix epoch is not considered well.
Supporting older date will cause a conversion problem between Gregorian calendar and Julian calendar, which I really don't want to touch.

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

No branches or pull requests

2 participants