git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RESEND] [PATCH] Endianness bug in index cache logic

From
Tomas Carnecky <tom@dbservice.com>
Date
Dec 27, 2009, 19:12 UTC
Message-ID
<4B37B1A5.5030209@dbservice.com>
In-Reply-To
<7veimgxolb.fsf@alter.siamese.dyndns.org>
On 12/27/09 7:24 PM, Junio C Hamano wrote:
Show 30 quoted lines
> 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
Previous: Junio C Hamano
Message 9 of 9 in “Endianness bug in git-svn or called component?”
  1. Nathaniel W FilardoDec 4, 2009
  2. Andreas SchwabDec 4, 2009
  3. Nathaniel W FilardoDec 4, 2009
  4. Nathaniel W FilardoDec 18, 2009
  5. [RESEND] [PATCH] Endianness bug in index cache logicNathaniel W Filardo, Dec 27, 2009
  6. Erik Faye-LundDec 27, 2009
  7. Nathaniel W FilardoDec 27, 2009
  8. Junio C HamanoDec 27, 2009
  9. Tomas CarneckyDec 27, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.