-
Notifications
You must be signed in to change notification settings - Fork 205
Fix parsing dates with more than 9 contiguous digits #967
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
Merged
saghul
merged 1 commit into
quickjs-ng:master
from
nickva:fix-parsing-more-than-9-date-digits
Mar 20, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe removing the limit actually introduces a subtle bug.
val
is an int, i.e., it stores numbers between-2**31
and2**31-1
, INT32_MIN and INT32_MAX.Nine digits is
10**9
and fits in INT32_MAX but10**10
does not.Easy fix: upgrade it from an int to
int64_t
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great point. I'll update it
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, it does make a bit of a mess as the types don't match any longer. What if we check for the next character if it is a digit return
false
as an overflow error. That is we hit the maximum limit (9 in this case) and there are more digits left, so something is wrong, so to speak. Or, maybe even simpler make the accumulatedv
value insidestring_get_digits
auint64_t
and check for>= INT32_MAX
and returnfalse
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Went with the idea of making the temp accumulator ,
v
auint64_t
, and adding a guard forINT32_MAX
overflow. It seemed a bit more general. Would that work?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a big fan of that approach.
It produces NaN for
Date.parse("946684800000")
if I read the changes correctly, but only because of a check in a utility function two or three levels away from where that decision ought to to be made.How about a different approach if you don't want int->int64 changes to percolate out?
string_get_digits()
is called with max=9 in just three places, to read the timezone offset, the year and the hour. In all three it can probably be lowered to either 2 or 4.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems fine. If Fabrice merged that, @saghul can just cherry-pick it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what this PR was updated to, just has the a few extra tests and uses C bools instead of TRUE/FALSE defines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll land this one then 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! For reference the commit from upstream is: bellard/quickjs@030333c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you also mentioned it in the commit message, thank you!