unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Carl Worth <cworth@cworth.org>
To: Mike Hommey <mh+notmuch@glandium.org>
Cc: notmuch@notmuchmail.org
Subject: Re: Segfault with weird Message-ID
Date: Sun, 22 Nov 2009 04:12:26 +0100	[thread overview]
Message-ID: <87k4xj2qxx.fsf@yoom.home.cworth.org> (raw)
In-Reply-To: <20091121222615.GA4925@glandium.org>

On Sat, 21 Nov 2009 23:26:15 +0100, Mike Hommey <mh+notmuch@glandium.org> wrote:
> I just was able to reproduce after starting over.

Thanks Mike. I was able to reproduce this as well by eliminating the
spurious blank line I had on the 2nd or 3rd line. (So maybe that managed
to sneak in when you sent me the message.)

> header isn't "", and message_id is correctly filled. I can also confirm
> the exception is thrown from notmuch->xapian_db->add_document.

Yes. We were trying to add a term that is too long for Xapian. I've
fixed this by simply falling back to our existing sha-1 code when a
message ID is long.

Thanks so much for the bug report!

-Carl

commit 5d56e931b99d575dbb0b936d24aae5e9903861ad
Author: Carl Worth <cworth@cworth.org>
Date:   Sun Nov 22 04:03:49 2009 +0100

    add_message: Use sha-1 in place of overly long message ID.
    
    Since Xapian has a limit on the maximum length of a term, we have
    to check for that before trying to add the message ID as a term.
    
    This fixes the bug reported by Mike Hommey here:
    
        <20091120132625.GA19246@glandium.org>
    
    I've also constructed 20 files with a range of message ID lengths
    centered around the Xapian term-length limit which I'll use to seed a
    new test suite soon.

diff --git a/lib/database.cc b/lib/database.cc
index 169dc5e..f4a445a 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -892,7 +892,7 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
 
     const char *date, *header;
     const char *from, *to, *subject;
-    char *message_id;
+    char *message_id = NULL;
 
     if (message_ret)
        *message_ret = NULL;
@@ -937,11 +937,20 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
        header = notmuch_message_file_get_header (message_file, "message-id");
        if (header && *header != '\0') {
            message_id = _parse_message_id (message_file, header, NULL);
+
            /* So the header value isn't RFC-compliant, but it's
             * better than no message-id at all. */
            if (message_id == NULL)
                message_id = talloc_strdup (message_file, header);
-       } else {
+
+           /* Reject a Message ID that's too long. */
+           if (message_id && strlen (message_id) + 1 > NOTMUCH_TERM_MAX) {
+               talloc_free (message_id);
+               message_id = NULL;
+           }
+       }
+
+       if (message_id == NULL ) {
            /* No message-id at all, let's generate one by taking a
             * hash over the file's contents. */
            char *sha1 = notmuch_sha1_of_file (filename);

      reply	other threads:[~2009-11-22  3:12 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-20 13:26 Segfault with weird Message-ID Mike Hommey
2009-11-20 17:04 ` Carl Worth
2009-11-20 20:53 ` Carl Worth
2009-11-20 21:05   ` Mike Hommey
2009-11-21 22:26     ` Mike Hommey
2009-11-22  3:12       ` Carl Worth [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87k4xj2qxx.fsf@yoom.home.cworth.org \
    --to=cworth@cworth.org \
    --cc=mh+notmuch@glandium.org \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).