Strip fractional seconds in ParseDockerTimestamp#40495
Conversation
There was a problem hiding this comment.
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.
|
I'm not totally sold on this one. |
Ok, I think I've convinced myself this is real and worth doing. |
3bf072e to
1a4c4b3
Compare
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>
1a4c4b3 to
9d8a0dd
Compare
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>
c8ed5fc to
d7cc83a
Compare
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>
| // 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); |
There was a problem hiding this comment.
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>
|
Closing -- could not reproduce the claimed parse failure against current MSVC. The existing |
Split out from #40489.
The chrono parse format
%FT%H:%M:%S%Zdoes 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 throwsE_INVALIDARGfor what is actually a valid Docker timestamp.Change
src/windows/wslcsession/WSLCContainer.cpp: strip the optional fractional component (between.and the timezone markerZ/+/-) before parsing. The function returns epoch seconds, so dropping sub-second precision is correct.Validation
%Zparse forZ/ abbreviated zones still runs unchanged.2026-03-05T10:30:00Z— no., unchanged2026-03-05T10:30:00.123456789Z— fractional stripped beforeZ2026-03-05T10:30:00.123+05:00— fractional stripped before+