From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id KB/6DjEm+14xaQAA0tVLHw (envelope-from ) for ; Tue, 30 Jun 2020 11:46:57 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id aMrRCjEm+15UfgAAB5/wlQ (envelope-from ) for ; Tue, 30 Jun 2020 11:46:57 +0000 Received: from arlo.cworth.org (arlo.cworth.org [50.126.95.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 4101F94013C for ; Tue, 30 Jun 2020 11:46:54 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 108856DE0F0C; Tue, 30 Jun 2020 04:46:50 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id R35KjzvUlAzB; Tue, 30 Jun 2020 04:46:48 -0700 (PDT) Received: from arlo.cworth.org (localhost [IPv6:::1]) by arlo.cworth.org (Postfix) with ESMTP id 1E9C76DE0E83; Tue, 30 Jun 2020 04:46:48 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 3DDE06DE0E83 for ; Tue, 30 Jun 2020 04:46:46 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id EGkO982rhtCQ for ; Tue, 30 Jun 2020 04:46:44 -0700 (PDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by arlo.cworth.org (Postfix) with ESMTP id 32B326DE0E7F for ; Tue, 30 Jun 2020 04:46:44 -0700 (PDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id 768A5613AC; Tue, 30 Jun 2020 07:46:43 -0400 (EDT) Received: (nullmailer pid 630266 invoked by uid 1000); Tue, 30 Jun 2020 11:46:41 -0000 Resent-To: notmuch@notmuchmail.org Resent-From: David Bremner Resent-Date: Tue, 30 Jun 2020 08:46:41 -0300 Resent-Message-ID: <878sg4ojxa.fsf@zancas> Received: by fethera.tethera.net (Postfix, from userid 1001) id 235EC613A9; Wed, 24 Jun 2020 07:04:33 -0400 (EDT) Received: (nullmailer pid 178087 invoked by uid 1000); Wed, 24 Jun 2020 11:04:31 -0000 From: David Bremner To: David Bremner , notmuch@notmuchmail.org Subject: [PATCH] lib: avoid casting gint64 to time_t Date: Wed, 24 Jun 2020 08:04:29 -0300 Message-Id: <20200624110429.178032-1-david@tethera.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <87o8p9nvq2.fsf@tethera.net> References: <87o8p9nvq2.fsf@tethera.net> MIME-Version: 1.0 X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: notmuch-bounces@notmuchmail.org Sender: "notmuch" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 50.126.95.6 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Spam-Score: 0.99 X-TUID: MKF0k5O2UwmW This is a partial fix for problems with 64 bit timestamps on 32 bit architectures. In certain (not completely understood by me) cases this casting causes 32bit overflows and yields negative timestamps for times in the far future. In g_mime_utils_header_decode_date_unix, there is really no reason to cast to and from time_t. In _notmuch_message_set_header_values, we rely on implicit casting of the argument to Xapian::sortable_serialise to double. --- This is not a complete fix, but at least the timestamp ends up aparently correct in the database. It looks like there are still wonky conversions on reading the large timestamp from the database. lib/message.cc | 2 +- util/gmime-extra.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/message.cc b/lib/message.cc index 0fa0eb3a..948626bd 100644 --- a/lib/message.cc +++ b/lib/message.cc @@ -1217,7 +1217,7 @@ _notmuch_message_set_header_values (notmuch_message_t *message, const char *from, const char *subject) { - time_t time_value; + gint64 time_value; /* GMime really doesn't want to see a NULL date, so protect its * sensibilities. */ diff --git a/util/gmime-extra.c b/util/gmime-extra.c index 04d8ed3d..af7b6d52 100644 --- a/util/gmime-extra.c +++ b/util/gmime-extra.c @@ -192,7 +192,7 @@ gint64 g_mime_utils_header_decode_date_unix (const char *date) { GDateTime *parsed_date = g_mime_utils_header_decode_date (date); - time_t ret; + gint64 ret; if (parsed_date) { ret = g_date_time_to_unix (parsed_date); -- 2.27.0