Skip to content
Fossil Changes To checkin/384705b56ac5adb3e33ecbc5a4dd8e33393caed8b96f02afbb7799667afffe07
Login

Changes To checkin/384705b56ac5adb3e33ecbc5a4dd8e33393caed8b96f02afbb7799667afffe07

Initial version of "checkin/384705b56ac5adb3e33ecbc5a4dd8e33393caed8b96f02afbb7799667afffe07"























































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
# SHA1 hashes wrong on big-endian hosts

## Symptom

On a big-endian host (reported on a PowerPC iBook), `fossil update`
in both the SQLite and Fossil repositories aborted with:

```
hash of rid 19096 does not match its uuid (
Abort trap
```

That message comes from `verify_rid()` in `src/verify.c`. Every artifact
gets checked against its stored hash before a commit, and this one failed.

## Cause

The cause is check-in [d243deba6a] (2026-10-16), which updated
`src/sha1hard.c` to the current upstream sha1dc code.

SHA1 reads its input as big-endian 32-bit words. Little-endian hosts
have to byte-swap each word, and big-endian hosts must not. The previous
`sha1hard.c` checked the host byte order at runtime (`ctx->bigendian`)
and skipped the swap on big-endian hosts. The updated code makes that
choice at compile time instead:

```
#if defined(BIGENDIAN)
  #define sha1_load(m, t) (m[t])
#else
  #define sha1_load(m, t, temp)  { temp = m[t]; sha1_bswap32(temp); }
#endif
```

That code has two defects:

  1. Nothing in the build defines `BIGENDIAN`, so every platform takes
     the byte-swapping branch. Upstream sha1dc decides this with a large
     block of `SHA1DC_BIGENDIAN` detection, which didn't come over in
     the update.
  2. The big-endian branch couldn't have compiled anyway. Its macro takes
     two arguments, but its only caller passes three.

The result is that every SHA1 hash computed on a big-endian host is
wrong. The first SHA1-named artifact that gets checked fails in
`verify_rid()`. SHA3 hashing doesn't use this code and isn't affected.
That's why the failure shows up as a hash mismatch on older artifacts
instead of some more general breakage.

## Fix

All of the changes are in `src/sha1hard.c`:

  *  Add a condensed version of upstream's byte-order detection. It uses
     `__BYTE_ORDER__` / `__ORDER_BIG_ENDIAN__` when the compiler provides
     them. Otherwise it falls back to well-known big-endian
     architecture macros (`__BIG_ENDIAN__`, `__ppc__`, `__powerpc__`,
     `__ARMEB__`, the MIPS-EB family, SPARC, HPPA, s390 and m68k). The
     fallback matters for old compilers such as Apple's PowerPC gcc,
     which may not define `__BYTE_ORDER__`. Defining `SHA1DC_BIGENDIAN`
     or `SHA1DC_LITTLEENDIAN` at build time overrides the detection.
  *  Fix the big-endian `sha1_load()` macro so that it takes the same
     three arguments as its little-endian counterpart.
  *  Add a runtime check to `SHA1DCInit()` that compares the compile-time
     answer with the actual byte order. If they disagree, Fossil prints
     an error and aborts. A wrong guess on some platform we haven't
     thought of then fails loudly instead of silently producing wrong
     hashes.

## Testing Performed

  *  On x86_64 Linux, `fossil sha1sum` output matches the system
     `sha1sum`.
  *  On x86_64 Linux, `fossil test-integrity` on the Fossil repository
     checked 68649 blobs with 0 errors.
  *  The big-endian code path compiles cleanly when forced with
     `-DSHA1DC_BIGENDIAN`.
  *  Confirmed on PowerPC iBook by drh.

## Note for affected installations

A big-endian build from between [d243deba6a] and this fix computes
wrong SHA1 hashes. Because the check before each commit aborts the
operation, it's unlikely that bad data was stored. Even so, it would
be worth running `fossil test-integrity` with a fixed build on any
repositories that such a binary used.