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

[PATCH] sha1dc: fix issues with a big endian platform

From
Junio C Hamano <gitster@pobox.com>
Date
May 17, 2017, 05:39 UTC
Message-ID
<xmqq37c4xcr6.fsf_-_@gitster.mtv.corp.google.com>
In-Reply-To
<CAKKM46sS_5bVe5a6wNN7SdVoGvwmVxnLAZTxJ+tSftXfZKeGWg@mail.gmail.com>
From: Marc Stevens <marc@marc-stevens.nl>

Some big-endian platforms define _BIG_ENDIAN, which the test at the beginning of file has missed. Also, when the input is not aligned, some platforms trigger SIGBUS.

This change corresponds to 33a694a9 ("Fix issues with a big endian platform", 2017-05-15) in the history of the upstream repository https://github.com/cr-marcstevens/sha1collisiondetection

---
 * So here is my attempt to clarify the log message (I left the
   title as-is, but this change deals both with endianness and
   alignment requirement).
   Please look it over, and then sign-off your patch ;-)
   Thanks.
   P.S. I wonder how often "buf" is not aligned---could we somehow
   optimize out memcpy when it is not necessary, or is it not worth
   it?
 sha1dc/sha1.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/sha1dc/sha1.c b/sha1dc/sha1.c
index 35e9dd5bf4..ae25318c47 100644
--- a/sha1dc/sha1.c
+++ b/sha1dc/sha1.c
@@ -20,7 +20,7 @@
  */
 #if (defined(__BYTE_ORDER) && (__BYTE_ORDER == __BIG_ENDIAN)) || \
     (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __BIG_ENDIAN__)) || \
-    defined(__BIG_ENDIAN__) || defined(__ARMEB__) || defined(__THUMBEB__) ||  defined(__AARCH64EB__) || \
+    defined(_BIG_ENDIAN) || defined(__BIG_ENDIAN__) || defined(__ARMEB__) || defined(__THUMBEB__) ||  defined(__AARCH64EB__) || \
     defined(_MIPSEB) || defined(__MIPSEB) || defined(__MIPSEB__)
 
 #define SHA1DC_BIGENDIAN	1
@@ -1728,7 +1728,8 @@ void SHA1DCUpdate(SHA1_CTX* ctx, const char* buf, size_t len)
 	while (len >= 64)
 	{
 		ctx->total += 64;
-		sha1_process(ctx, (uint32_t*)(buf));
+		memcpy(ctx->buffer, buf, 64);
+		sha1_process(ctx, (uint32_t*)(ctx->buffer));
 		buf += 64;
 		len -= 64;
 	}
-- 
2.13.0-416-g4c6b804423
Previous: Michael KebeNext: Ævar Arnfjörð Bjarmason
Message 7 of 17 in “Git 2.13.0 segfaults on Solaris SPARC due to DC_SHA1=YesPlease being on by default”
  1. Ævar Arnfjörð BjarmasonMay 15, 2017
  2. Marc StevensMay 15, 2017
  3. Ævar Arnfjörð BjarmasonMay 15, 2017
  4. Jeff KingMay 15, 2017
  5. demerphqJun 1, 2017
  6. Michael KebeMay 16, 2017
  7. sha1dc: fix issues with a big endian platformJunio C Hamano, May 17, 2017
  8. Ævar Arnfjörð BjarmasonMay 17, 2017
  9. Junio C HamanoMay 17, 2017
  10. 0/3 Use sha1collisiondetection as a submoduleÆvar Arnfjörð Bjarmason, May 17, 2017
  11. 1/3 sha1dc: update from my fork of upstreamÆvar Arnfjörð Bjarmason, May 17, 2017
  12. 2/3 sha1dc: use sha1collisiondetection as a submoduleÆvar Arnfjörð Bjarmason, May 17, 2017
  13. Stefan BellerMay 17, 2017
  14. Ævar Arnfjörð BjarmasonMay 17, 2017
  15. Stefan BellerMay 17, 2017
  16. Brandon WilliamsMay 18, 2017
  17. Johannes SchindelinMay 17, 2017

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.