From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id DD6296DE145D for ; Wed, 15 Mar 2017 13:09:54 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0.499 X-Spam-Level: X-Spam-Status: No, score=0.499 tagged_above=-999 required=5 tests=[AWL=-0.153, SPF_NEUTRAL=0.652] autolearn=disabled 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 ZICFwxHmF3Ks for ; Wed, 15 Mar 2017 13:09:54 -0700 (PDT) Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) by arlo.cworth.org (Postfix) with ESMTP id BB6936DE1457 for ; Wed, 15 Mar 2017 13:09:53 -0700 (PDT) Received: from guru.guru-group.fi (localhost [IPv6:::1]) by guru.guru-group.fi (Postfix) with ESMTP id 359B410008D; Wed, 15 Mar 2017 22:09:19 +0200 (EET) From: Tomi Ollila To: David Bremner , Johannes Schauer , notmuch@notmuchmail.org Subject: Re: [PATCH 2/2] lib: clamp return value of g_mime_utils_header_decode_date to >=0 In-Reply-To: <20170312125101.21656-2-david@tethera.net> References: <20150422065630.6330.90536@hoothoot> <20170312125101.21656-1-david@tethera.net> <20170312125101.21656-2-david@tethera.net> User-Agent: Notmuch/0.24+38~g4a0f2a1 (https://notmuchmail.org) Emacs/24.5.1 (x86_64-unknown-linux-gnu) X-Face: HhBM'cA~ MIME-Version: 1.0 Content-Type: text/plain X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Mar 2017 20:09:55 -0000 On Sun, Mar 12 2017, David Bremner wrote: > For reasons not completely understood at this time, gmime (as of > 2.6.22) is returning a date before 1900 on bad date input. Since this > confuses some other software, we clamp such dates to 0, > i.e. 1970-01-01. > --- > lib/message.cc | 9 +++++++-- > 1 file changed, 7 insertions(+), 2 deletions(-) > > diff --git a/lib/message.cc b/lib/message.cc > index 007f1171..8a8a25b4 100644 > --- a/lib/message.cc > +++ b/lib/message.cc > @@ -1034,10 +1034,15 @@ _notmuch_message_set_header_values (notmuch_message_t *message, > > /* GMime really doesn't want to see a NULL date, so protect its > * sensibilities. */ > - if (date == NULL || *date == '\0') > + if (date == NULL || *date == '\0') { > time_value = 0; "Too bad" we already do this time_value = 0, otherwise I'd suggested -2111111111 $ perl -le 'print scalar localtime -2111111111' Sat Feb 7 21:54:38 1903 That is something where Julian calendar is also in 20th century ;) > - else > + } else { > time_value = g_mime_utils_header_decode_date (date, NULL); > + /* > + * Workaround for https://bugzilla.gnome.org/show_bug.cgi?id=779923 > + */ > + time_value = (time_value < 0) ? 0 : time_value; Although the above probably realizes as..., I'd propose (IMO for clarity) if (time_value < 0) time_value = 0; Anyway, LGTM. Tomi Btw: I Added notmuch show --format=json '*' >&6 to the test script, and it printed: [[[{"id": "msg-001@notmuch-test-suite", "match": true, "excluded": false, "filename": ["/home/too/vc/ext/notmuch/test/tmp.T111-x/mail/msg-001"], "timestamp": 2085892096, "date_relative": "1899-12-31", "tags": ["inbox", "unread"], "headers": {"Subject": "Test message #1", "From": "Notmuch Test Suite ", "To": "Notmuch Test Suite ", "Date": "Sun, 31 Dec 1899 00:00:00 +0000"}, "body": [{"id": 1, "content-type": "text/plain", "content": "This is just a test message (#1)\n"}]}, []]]] (... which one can see I just pasted to a new file... ;) $ perl -le 'print scalar localtime 2085892096' Wed Feb 6 08:28:16 2036 So, it looks like we store the large negative time_value to a 32-bit signed integer... > + } > > message->doc.add_value (NOTMUCH_VALUE_TIMESTAMP, > Xapian::sortable_serialise (time_value)); > -- > 2.11.0 > > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > https://notmuchmail.org/mailman/listinfo/notmuch