From 8e4546b42f699c915d9b3049f86e59f1435c4fc7 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 19 Apr 2021 13:35:17 +0200 Subject: [PATCH] Make deserialization of QTimeZone less promiscuous When asked to read an OffsetFromUtc record, it was trying the IANA ID it read in as a possible zone name. If the backend accepted the given ID as a zone name, however, the result might not be an offset-from-UTC zone. So extend the isValid() check it was doing on the result to at least check the zone has no DST and matches the record's offset. Change-Id: I46a95aeb2a4d66887fd56a58fa72fe5d3b568a00 Reviewed-by: Thiago Macieira --- src/corelib/time/qtimezone.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/corelib/time/qtimezone.cpp b/src/corelib/time/qtimezone.cpp index 5a5cd1dd101..8baa4cb592d 100644 --- a/src/corelib/time/qtimezone.cpp +++ b/src/corelib/time/qtimezone.cpp @@ -994,12 +994,15 @@ QDataStream &operator>>(QDataStream &ds, QTimeZone &tz) QString comment; ds >> ianaId >> utcOffset >> name >> abbreviation >> territory >> comment; // Try creating as a system timezone, which succeeds (producing a valid - // zone) iff ianaId is valid; we can then ignore the other data. + // zone) iff ianaId is valid; use this if it is a plain offset from UTC + // zone, with the right offset, ignoring the other data: tz = QTimeZone(ianaId.toUtf8()); - // If not, then construct a custom timezone using all the saved values: - if (!tz.isValid()) + if (!tz.isValid() || tz.hasDaylightTime() + || tz.offsetFromUtc(QDateTime::fromMSecsSinceEpoch(0, Qt::UTC)) != utcOffset) { + // Construct a custom timezone using the saved values: tz = QTimeZone(ianaId.toUtf8(), utcOffset, name, abbreviation, QLocale::Territory(territory), comment); + } } else { tz = QTimeZone(ianaId.toUtf8()); }