unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Tomi Ollila <tomi.ollila@iki.fi>
To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org
Subject: Re: notmuch sha1 implementation broken on (some) big-endian architectures
Date: Sun, 24 Nov 2013 18:42:46 +0200	[thread overview]
Message-ID: <m2ob593g55.fsf@guru.guru-group.fi> (raw)
In-Reply-To: <87eh666mhp.fsf@zancas.localnet>

On Sun, Nov 24 2013, David Bremner <david@tethera.net> wrote:

> The following code, when linked with libnotmuch.a and libutil.a does a
> passable imitation of sha1sum on amd64 (and I guess also i386) but
> computes a different digest on powerpc and probably sparc and s390x.
>
> In the long run we should maybe outsource hash computations to
> e.g. librhash, but I'd like a simpler fix for 0.17, if possible
>
> P.S. I blame Austin for adding the "missing-headers" test which found
> this bug ;).

This is interesting problem, I would have guessed that this would
fails on LITTLE_ENDIAN machines easier, if ever...

... especially as there is line

lib/libsha1.c:52:#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)

... but...

I could not find any (other) matches for PLATFORM_BYTE_ORDER nor
IS_LITTLE_ENDIAN in source code or in /usr/include/**/*.h or
in /usr/lib/gcc/**/*.h

I did some testing and it seems that 
#if (FOOOO == BBBAAARRR)
<code>
#endif

will have <code> in output file in case neither of the above are
defined... :/

So, this could work:

#if <endian.h>  // for BYTE_ORDER && LITTLE_ENDIAN

and then

#if (BYTE_ORDER == LITTLE_ENDIAN)
...

to replace lib/libsha1.c:53 (53 now after endian.h added)


Please test on BIG_ENDIAN machine...


In case this works, then we'd need to inform users that their
long/missing Message ID:s are now coded differently in their
databases...


Tomi

  parent reply	other threads:[~2013-11-24 16:43 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-24 11:57 notmuch sha1 implementation broken on (some) big-endian architectures David Bremner
2013-11-24 12:40 ` David Bremner
2013-11-24 16:42 ` Tomi Ollila [this message]
2013-11-24 21:29   ` [PATCH 1/2] lib: fix byte order test in libsha1.c david
2013-11-24 21:29     ` [PATCH 2/2] NEWS: News for big endian sha1 bug fix david
2013-11-25  3:10       ` Austin Clements
2013-11-26 13:07       ` [PATCH] util: detect byte order david
2013-11-26 17:42         ` Tomi Ollila
2013-11-27  0:38           ` [PATCH v2] " david
2013-11-27  8:04             ` Tomi Ollila
2013-11-27 12:26               ` David Bremner
2013-11-25  9:43     ` [PATCH 1/2] lib: fix byte order test in libsha1.c Tomi Ollila

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=m2ob593g55.fsf@guru.guru-group.fi \
    --to=tomi.ollila@iki.fi \
    --cc=david@tethera.net \
    --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).