Skip to content

GH-31374: [C++] Prevent strptime from normalizing invalid dates - #50747

Open
fallintoplace wants to merge 1 commit into
apache:mainfrom
fallintoplace:fix/strptime-invalid-calendar-dates
Open

GH-31374: [C++] Prevent strptime from normalizing invalid dates#50747
fallintoplace wants to merge 1 commit into
apache:mainfrom
fallintoplace:fix/strptime-invalid-calendar-dates

Conversation

@fallintoplace

@fallintoplace fallintoplace commented Jul 30, 2026

Copy link
Copy Markdown

Rationale for this change

After strptime populates a tm, Arrow converts its calendar fields directly to sys_days. Since sys_days normalizes invalid dates, an input such as 1999-02-30 becomes March 2 instead of failing to parse.

What changes are included in this PR?

Validate the parsed year_month_day before converting it to sys_days. Invalid dates now use the existing parse-failure path.

The regression test covers invalid month lengths and leap days. It also verifies the exact timestamps produced for valid leap-year and month-end boundaries.

Are these changes tested?

Yes. The regression test fails against the original implementation and passes with this change. Both the focused TimestampParser.StrptimeParser* tests and the complete arrow-utility-test suite pass locally.

Are there any user-facing changes?

Invalid calendar dates passed to strptime now fail instead of producing normalized timestamps. Valid dates retain their existing results.

This PR contains a "Critical Fix". Invalid input could previously produce an incorrect timestamp.

@fallintoplace
fallintoplace requested a review from pitrou as a code owner July 30, 2026 17:51
@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #31374 has been automatically assigned in GitHub to PR creator.

@fallintoplace
fallintoplace force-pushed the fix/strptime-invalid-calendar-dates branch from 047180d to 9e2fca7 Compare July 30, 2026 17:55
@fallintoplace fallintoplace changed the title GH-31374: [C++] Reject invalid calendar dates in strptime GH-31374: [C++] Reject invalid calendar dates parsed by strptime Jul 30, 2026
@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #31374 has been automatically assigned in GitHub to PR creator.

@fallintoplace
fallintoplace force-pushed the fix/strptime-invalid-calendar-dates branch from 9e2fca7 to d4ec27c Compare July 30, 2026 17:59
@fallintoplace fallintoplace changed the title GH-31374: [C++] Reject invalid calendar dates parsed by strptime GH-31374: [C++] Prevent strptime from normalizing invalid dates Jul 30, 2026
@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #31374 has been automatically assigned in GitHub to PR creator.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant