Alexander Zangerl | 14 Jun 2012 10:28
Picon

nmh 1.5 doesn't work on 64-bit big-endian archs (+patch)

i've run into another gotcha: the base64-decoder doesn't
work on 64-bit big-endian architectures: mhstore and co. write
files of the correct length but which consist only of \0s.

the culprit is uip/mhparse.c, which contains a pretty ugly base64
decoder (in two places). that thing allocates a "long int" as a container
for the 24 bits that you get from four base-64 chars. the container is then
accessed both as a single entity and as a byte array, which naturally 
depends on how wide the long int is and in what order things end up in there.

the code distinguishes between big- and little-endian systems but wrongly 
assumes that sizeof(long int) == 4, which isn't universally 
true (quel surprise...).

the attached patch fixes the issue, but in the long run we should
insist on posix and use a64l().

regards
az

--

-- 
Alexander Zangerl + GnuPG Keys 0x42BD645D or 0x5B586291 + http://snafu.priv.at/
Perl is like vise grips. You can do anything with it but it is 
the wrong tool for every job. -- Bruce Eckel
_______________________________________________
(Continue reading)

Ken Hornstein | 14 Jun 2012 14:15
X-Face
Picon
Favicon

Re: nmh 1.5 doesn't work on 64-bit big-endian archs (+patch)

>i've run into another gotcha: the base64-decoder doesn't
>work on 64-bit big-endian architectures: mhstore and co. write
>files of the correct length but which consist only of \0s.

Just curious ... did the test suite catch this?  Because if it didn't, then
we should DEFINITELY have a test for it.

--Ken

_______________________________________________
Nmh-workers mailing list
Nmh-workers <at> nongnu.org
https://lists.nongnu.org/mailman/listinfo/nmh-workers

Alexander Zangerl | 14 Jun 2012 14:24
Picon

Re: nmh 1.5 doesn't work on 64-bit big-endian archs (+patch)

On Thu, 14 Jun 2012 08:15:29 -0400, Ken Hornstein writes:
>>i've run into another gotcha: the base64-decoder doesn't
>>work on 64-bit big-endian architectures: mhstore and co. write
>>files of the correct length but which consist only of \0s.
>
>Just curious ... did the test suite catch this?  Because if it didn't, then
>we should DEFINITELY have a test for it.

it did, but the info that it provided was not overly helpful - just some
mhlists and mhstore 'contents of expected and actual differ' 
and indications of faulty content-md5 hashes. it took me most of a day 
with printf and the source to figure out what was *really* going on...

regards
az

--

-- 
Alexander Zangerl + GnuPG Keys 0x42BD645D or 0x5B586291 + http://snafu.priv.at/
"Alas I've yet to find a gig which offers "control of Orbital Anvil
Delivery System at weekends" as a fringe-benefit." -- Tanuki
_______________________________________________
Nmh-workers mailing list
Nmh-workers <at> nongnu.org
https://lists.nongnu.org/mailman/listinfo/nmh-workers
David Levine | 14 Jun 2012 15:20
Picon
Favicon

Re: nmh 1.5 doesn't work on 64-bit big-endian archs(+patch)

az wrote:

> i've run into another gotcha: the base64-decoder doesn't
> work on 64-bit big-endian architectures: mhstore and co. write
> files of the correct length but which consist only of \0s.
>
> the culprit is uip/mhparse.c, which contains a pretty ugly
> base64 decoder (in two places). that thing allocates a
> "long int" as a container for the 24 bits that you get
> from four base-64 chars. the container is then accessed
> both as a single entity and as a byte array, which
> naturally depends on how wide the long int is and in what
> order things end up in there.
>
> the code distinguishes between big- and little-endian
> systems but wrongly assumes that sizeof(long int) == 4,
> which isn't universally true (quel surprise...).
>
> the attached patch fixes the issue, but in the long run we
> should insist on posix and use a64l().

Patch applied, thank you.

uip/mhparse.c has the only explicit dependencies on endian-ness.
Cleanup would be most welcome.

David

_______________________________________________
Nmh-workers mailing list
(Continue reading)

Ken Hornstein | 14 Jun 2012 16:37
X-Face
Picon
Favicon

Re: nmh 1.5 doesn't work on 64-bit big-endian archs(+patch)

>uip/mhparse.c has the only explicit dependencies on endian-ness.
>Cleanup would be most welcome.

I took a look at it and I decided that it wasn't that hard, so I think
the code I just pushed to master should take care of it.

Alex, if you wanted to give that a try on 64-bit big-endian system, that
would be very helpful.

--Ken

_______________________________________________
Nmh-workers mailing list
Nmh-workers <at> nongnu.org
https://lists.nongnu.org/mailman/listinfo/nmh-workers


Gmane