Skip to content

fread: avoid UB in leap year cycle calculation#7720

Merged
ben-schwen merged 4 commits intomasterfrom
fix7704
Apr 23, 2026
Merged

fread: avoid UB in leap year cycle calculation#7720
ben-schwen merged 4 commits intomasterfrom
fix7704

Conversation

@aitap
Copy link
Copy Markdown
Member

@aitap aitap commented Apr 23, 2026

Use the fix suggested by @kevinushey. Since R's Date class (and thus IDate) uses year zero, the resulting calculations agree with the system tzcode, although the Date class generally doesn't like to parse negative years:

$ TZ=UTC LC_ALL=C date -d '0004-02-29 -8year 12:00:00'
Thu Feb 29 12:00:00 UTC -004
$ R -q -s -e 'data.table::fread("-4-02-29 12:00:00\n")'
         V1       V2
     <IDat>   <char>
1: -4-02-29 12:00:00

Fixes: #7704

@aitap aitap requested a review from MichaelChirico as a code owner April 23, 2026 09:50
@aitap aitap added this to the 1.18.4 milestone Apr 23, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.04%. Comparing base (8364344) to head (ac14cd5).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7720      +/-   ##
==========================================
- Coverage   99.04%   99.04%   -0.01%     
==========================================
  Files          87       87              
  Lines       17037    17123      +86     
==========================================
+ Hits        16874    16959      +85     
- Misses        163      164       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Member

@ben-schwen ben-schwen left a comment

Choose a reason for hiding this comment

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

LGTM TY! Also TY to @kevinushey

@ben-schwen ben-schwen merged commit 3a45206 into master Apr 23, 2026
14 of 15 checks passed
aitap added a commit that referenced this pull request Apr 23, 2026
* Test case

* NEWS item

* Don't rely on exact string formatting

Co-Authored-By: Kevin Ushey <kevinushey@gmail.com>
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

Successfully merging this pull request may close these issues.

fread: undefined behavior in parse_iso8601_date_core for negative years

2 participants