git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tomas Carnecky <tom@dbservice.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Nathaniel W Filardo <nwf@cs.jhu.edu>, git@vger.kernel.org
Subject: Re: [RESEND] [PATCH] Endianness bug in index cache logic
Date: Sun, 27 Dec 2009 20:12:37 +0100	[thread overview]
Message-ID: <4B37B1A5.5030209@dbservice.com> (raw)
In-Reply-To: <7veimgxolb.fsf@alter.siamese.dyndns.org>

On 12/27/09 7:24 PM, Junio C Hamano wrote:
> Nathaniel W Filardo<nwf@cs.jhu.edu>  writes:
>
>> I got some free time and tracked it down.  The following one-line delta
>> fixes this issue for me; AIUI on sparc64 "unsigned long" is 8 bits and in
>> the wrong endianness for the memcpy trick to work as written?  I could be
>> sligntly off in my assessment of the problem, tho'.
>>
>> index 1bbaf1c..9033dd3 100644
>> --- a/read-cache.c
>> +++ b/read-cache.c
>> @@ -1322,7 +1322,7 @@ int read_index_from(struct index_state *istate, const char *path)
>>                   * extension name (4-byte) and section length
>>                   * in 4-byte network byte order.
>>                   */
>> -               unsigned long extsize;
>> +               uint32_t extsize;
>>                  memcpy(&extsize, (char *)mmap + src_offset + 4, 4);
>>                  extsize = ntohl(extsize);
>>                  if (read_index_extension(istate,
>
> Good catch.
>
> The original is broken on big endian 64-bit platforms, and your sparc64
> indeed is one.  The code expects to see a signature (4-byte) at src_offset
> followed by length (4-byte int in network byte order) and it is trying to
> read read the latter in extsize.
>
> Thanks for the fix.  The bug dates back to late April 2006, and I am kind
> of surprised that nobody reported this since then (perhaps nobody runs git
> on big endian 64-bit boxes?).

Both the native Sun compiler as well as GCC default to 32bit binaries, 
even if the system is capable of running 64bit binaries (unlike for 
example Linux where x86_64-pc-linux-gnu-gcc produces 64bit binaries by 
default). And the git makefile doesn't use -m64, so my guess is that 
nobody bothered changing CFLAGS on sparc64 systems (I have access to a 
couple such systems and I never changed CFLAGS because git always worked 
out of the box). Though I don't know what the default is on other big 
endian systems.

tom

      reply	other threads:[~2009-12-27 19:12 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-04 17:44 Endianness bug in git-svn or called component? Nathaniel W Filardo
2009-12-04 20:16 ` Andreas Schwab
2009-12-04 20:29   ` Nathaniel W Filardo
2009-12-18  9:05     ` Nathaniel W Filardo
2009-12-27  6:11     ` [RESEND] [PATCH] Endianness bug in index cache logic Nathaniel W Filardo
2009-12-27 12:39       ` Erik Faye-Lund
2009-12-27 16:12         ` Nathaniel W Filardo
2009-12-27 18:24       ` Junio C Hamano
2009-12-27 19:12         ` Tomas Carnecky [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

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

  git send-email \
    --in-reply-to=4B37B1A5.5030209@dbservice.com \
    --to=tom@dbservice.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=nwf@cs.jhu.edu \
    /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.
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 NNTP newsgroup(s).