Fix: DateTimeParser trailing timezone designators & Timezone UTC offset cache invalidation#5318
Conversation
|
The ASN.1 UTCTime issue ( The other example The real issue is that case 'S':
it = skipNonDigits(it, end);
second = parseNumberN(dtStr, it, end, 2);
if (it != end && (*it == '.' || *it == ','))
{
++it;
it = skipDigits(it, end);
}
break;This way |
|
Hi matejk, Thank you for the answer. Next week I will look at that and I will try your suggestion. |
0842fcb to
fc59725
Compare
|
Hi @matejk Thank you for your help. I again retest it with last main and with fix you recemented and all tests pass now. Still need use commit |
matejk
left a comment
There was a problem hiding this comment.
Two well-described fixes for real bugs — thanks. A few suggestions inline before merge.
| _localtime_ino = 0; | ||
| _localtime_mtime = 0; | ||
| } | ||
| } |
There was a problem hiding this comment.
Out of scope for this PR, but worth noting as future follow-ups: this detection is effectively a no-op on Android, where the zone is set via the persist.sys.timezone system property rather than /etc/localtime — bionic's tzset() reads the property. The analogous Timezone_WIN32.cpp could grow a similar check by re-querying GetDynamicTimeZoneInformation and comparing TimeZoneKeyName (or watching the HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation registry key).
|
@kozemcak, I'd include the fixes to Poco 1.15.3 that is planned for release in a week. Can you take a look at the comments above? |
|
Hi @matejk, |
…time changes Poco commit 1850dc1 introduced a TZInfo cache for the UTC offset to avoid repeated tzset() syscalls. The cache is invalidated only when the TZ environment variable changes. However, the TZ variable is process-local: if a different process (e.g. a timezone configuration daemon or an init script) changes the system timezone by updating /etc/localtime, the running process is not notified and its TZ environment variable remains unchanged. On systems that switch timezone by updating /etc/localtime (a symlink) without touching the TZ env var, the cache is therefore never invalidated and Timezone::utcOffset() returns the stale value computed at startup. Fix by extending cacheTZ()/tzChanged() to also track the inode and mtime of /etc/localtime via stat(2). When either changes the cache is considered stale and reloaded, preserving the performance benefit for the common case where neither TZ nor /etc/localtime changes between calls. Signed-off-by: Andrej Kozemcak <andrej.kozemcak@siemens.com>
Parsing ISO 8601 date strings that contain both fractional seconds and a
timezone offset (e.g. "2013-10-07T08:23:19.120-04:00") with the format
"%Y-%m-%dT%H:%M:%S%z" raises a SyntaxException:
- %S consumes the integer seconds but stops at '.', leaving
".120-04:00" unconsumed.
- %z (parseTZD) is called next but sees '.' and returns without
consuming anything.
- The trailing-garbage check then raises SyntaxException.
Extend the %S case to consume and discard an optional fractional-second
suffix ('.' or ',' followed by one or more digits) immediately after
parsing the integer seconds. This mirrors the existing %s behaviour and
allows %z to see the timezone designator directly, keeping the
trailing-garbage check fully effective for truly invalid input.
Fix suggested by matejk.
Signed-off-by: Andrej Kozemcak <andrej.kozemcak@siemens.com>
Add testISO8601FracSeconds to verify that DateTimeParser correctly handles fractional-second suffixes (dot and comma separated) in ISO8601_FORMAT strings, and rejects malformed input such as a bare decimal point with no digits.
Hi all,
After we update poco to new version our applications tests start failing. We identified these issues and fix it. Some of the issues are little specific, so we are interesting what you say about that. Here are quick summary of our changes.
Thanks.
Summary
This MR contains two bug fixes for the
Foundationlibrary addressing datetime parsing and timezone handling regressions.Changes
1.
fix(Foundation): DateTimeParser: %S consume optional fractional secondsParsing ISO 8601 date strings that contain both fractional seconds and a timezone offset (e.g. "2013-10-07T08:23:19.120-04:00") with the format "%Y-%m-%dT%H:%M:%S%z" raises a SyntaxException:
Fix: Extend the %S case to consume and discard an optional fractional-second suffix (. or , followed by one or more digits) immediately after parsing the integer seconds. This mirrors the existing %s behaviour and allows %z to see the timezone designator directly, keeping the trailing-garbage check fully effective for truly invalid input.
2.
fix(Foundation): Timezone: invalidate utcOffset cache when /etc/localtime changesThe
TZInfoUTC offset cache introduced in Poco commit1850dc16is only invalidated when theTZenvironment variable changes. SinceTZis process-local, system timezone changes via/etc/localtime(symlink update) go undetected, causingTimezone::utcOffset()to return a stale value.Fix: Extend
cacheTZ()/tzChanged()to track the inode andmtimeof/etc/localtimeviastat(2). Cache is invalidated when either changes.Testing
utcOffset()reflects timezone changes after localtime is updated without modifyingTZ.