gh-155175: Reject fractional seconds without a decimal mark in C fromisoformat - #155177
Open
SEPURI-SAI-KRISHNA wants to merge 1 commit into
Open
gh-155175: Reject fractional seconds without a decimal mark in C fromisoformat#155177SEPURI-SAI-KRISHNA wants to merge 1 commit into
SEPURI-SAI-KRISHNA wants to merge 1 commit into
Conversation
SEPURI-SAI-KRISHNA
requested review from
StanFromIreland and
pganssle
as code owners
August 4, 2026 15:00
Author
|
CIFuzz has no datetime target, Modules/_xxtestfuzz/fuzz_tests.txt lists 11 targets and none reach _datetimemodule.c. All three sanitizer variants failed identically, which points to an OSS-Fuzz infra issue rather than this change. |
aisk
approved these changes
Aug 4, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
parse_hh_mm_ss_ff()inModules/_datetimemodule.cparsed any characters leftover after
HHMMSSin the ISO 8601 basic format as a fractional secondscomponent, without requiring the decimal mark that ISO 8601 mandates:
The
HH/MM/SSloop onlybreaks into the fraction-parsing code when itsees
.or,. In the basic format it can also fall out of the loop normallywith input still unconsumed, the
else if (!has_separator) { --p; }branchun-consumes the character and the loop ends, after which the code below
parses whatever remains as a fraction, never checking that a decimal mark
introduced it.
This tracks whether a decimal mark was actually seen and rejects the string
otherwise, matching
_pydatetime._parse_hh_mm_ss_ff(), which performs thecheck explicitly:
Because the same helper also parses the UTC offset, this fixes malformed
offsets being accepted with the trailing digits silently discarded:
Valid inputs are unaffected,
'123456','123456.78','123456,78','123456.123456789','12:34:56.123456','1234','12','123456+0000','123456Z','12:34:56+00:00:00.123456','20200101T123456.789'and'20200101T123456+0530'all parse exactly as before, and identically to thepure-Python implementation.
This is the same class of C/pure-Python divergence as gh-152157 (empty fraction
before a timezone designator) and gh-152079.
Tests
Five cases added to each of the
timeanddatetimebad_strslists inLib/test/datetimetester.py, covering the fraction and the UTC offset paths.They run under both the
_Fast(C) and_Pure(pure Python) test classes.test_datetimepasses (1160 tests), and the full suite passes(
run=48,806,Result: SUCCESS).