Skip to content

Strip fractional seconds in ParseDockerTimestamp#40495

Closed
benhillis wants to merge 5 commits into
microsoft:masterfrom
benhillis:user/benhill/fix-docker-timestamp-fractional
Closed

Strip fractional seconds in ParseDockerTimestamp#40495
benhillis wants to merge 5 commits into
microsoft:masterfrom
benhillis:user/benhill/fix-docker-timestamp-fractional

Conversation

@benhillis
Copy link
Copy Markdown
Member

Split out from #40489.

The chrono parse format %FT%H:%M:%S%Z does not consume the optional fractional seconds component that Docker emits in ISO 8601 timestamps (e.g. 2026-03-05T10:30:00.123456789Z). For timestamps with a fractional component the parse fails and the call throws E_INVALIDARG for what is actually a valid Docker timestamp.

Change

  • src/windows/wslcsession/WSLCContainer.cpp: strip the optional fractional component (between . and the timezone marker Z / + / -) before parsing. The function returns epoch seconds, so dropping sub-second precision is correct.

Validation

  • Mechanical normalization; %Z parse for Z / abbreviated zones still runs unchanged.
  • Manual review of representative inputs:
    • 2026-03-05T10:30:00Z — no ., unchanged
    • 2026-03-05T10:30:00.123456789Z — fractional stripped before Z
    • 2026-03-05T10:30:00.123+05:00 — fractional stripped before +

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Fixes parsing of Docker ISO 8601 timestamps that include fractional seconds by normalizing the input before std::chrono::parse, preventing valid timestamps (e.g. ...00.123456789Z) from throwing E_INVALIDARG.

Changes:

  • Normalize Docker timestamps by stripping the optional fractional seconds portion before parsing.
  • Keep existing %Z-based parsing behavior while ensuring epoch-second precision remains correct.

Comment thread src/windows/wslcsession/WSLCContainer.cpp Outdated
@benhillis
Copy link
Copy Markdown
Member Author

I'm not totally sold on this one.

@benhillis
Copy link
Copy Markdown
Member Author

I'm not totally sold on this one.

Ok, I think I've convinced myself this is real and worth doing.

@benhillis benhillis marked this pull request as ready for review May 12, 2026 21:53
@benhillis benhillis requested a review from a team as a code owner May 12, 2026 21:53
Copilot AI review requested due to automatic review settings May 12, 2026 21:53
@benhillis benhillis force-pushed the user/benhill/fix-docker-timestamp-fractional branch from 3bf072e to 1a4c4b3 Compare May 12, 2026 21:53
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread src/windows/wslcsession/WSLCContainer.cpp Outdated
Comment thread src/windows/wslcsession/WSLCContainer.cpp Outdated
benhillis and others added 2 commits May 28, 2026 15:48
The chrono parse format `%FT%H:%M:%S%Z` does not consume the optional
fractional seconds component that Docker emits in ISO 8601 timestamps
(e.g. `2026-03-05T10:30:00.123456789Z`). For timestamps with a
fractional component the parse fails and `THROW_HR_IF_MSG` reports an
`E_INVALIDARG` for what is in fact a valid Docker timestamp.

Strip the fractional component (between `.` and the timezone marker
`Z` / `+` / `-`) before parsing. The function returns epoch
seconds, so the dropped sub-second precision is irrelevant.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The '.' itself can't match 'Z', '+' or '-', so starting find_first_of
one past dot makes the intent slightly clearer and avoids an
unnecessary comparison.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@benhillis benhillis force-pushed the user/benhill/fix-docker-timestamp-fractional branch from 1a4c4b3 to 9d8a0dd Compare May 28, 2026 22:48
Copilot AI review requested due to automatic review settings May 28, 2026 22:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread src/windows/wslcsession/WSLCContainer.cpp
Drop the %Z portion of the chrono parse format string and remove the
fractional-component normalization. std::chrono::parse does not treat
unread trailing input as a failure, so '%FT%H:%M:%S' parses Docker
timestamps with or without a fractional component and with or without
the trailing 'Z' without any pre-processing.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@benhillis benhillis force-pushed the user/benhill/fix-docker-timestamp-fractional branch from c8ed5fc to d7cc83a Compare May 28, 2026 23:01
Per review feedback from Copilot: with the format string '%FT%H:%M:%S'
chrono::parse silently stops at the seconds field, so an input like
'2026-03-05T10:30:00+05:00' would have been treated as UTC and yielded
the wrong epoch seconds (this was also the behavior of the original
'%Z' parse). Require a trailing 'Z' so non-UTC offsets are rejected.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 28, 2026 23:02
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment on lines 370 to 373
// chrono::parse leaves the trailing fractional component (if any) and the 'Z'
// unread; that is not treated as a parse failure.
std::chrono::sys_seconds utcSeconds;
std::istringstream stream(timestamp);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good catch -- e5a98ba validates the tail is exactly Z or .<digits>Z so garbage between the seconds field and trailing Z is rejected.

Per review feedback from Copilot: simply checking the last character is
'Z' admits malformed suffixes between the seconds field and the trailing
'Z' (e.g. '2026-03-05T10:30:00garbageZ') because std::chrono::parse stops
silently at the end of the seconds. Instead, verify that the unconsumed
tail after parsing is exactly 'Z' or '.<digits>Z'.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@benhillis
Copy link
Copy Markdown
Member Author

Closing -- could not reproduce the claimed parse failure against current MSVC. The existing %FT%H:%M:%S%Z format already accepts fractional Docker timestamps without throwing. Will reopen if an actual repro surfaces.

@benhillis benhillis closed this May 29, 2026
@benhillis benhillis deleted the user/benhill/fix-docker-timestamp-fractional branch May 29, 2026 15:38
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.

3 participants