]> git.ipfire.org Git - thirdparty/git.git/commitdiff
hash algorithms: use size_t for section lengths
authorPhilip Oakley <philipoakley@iee.email>
Tue, 16 Jun 2026 14:49:54 +0000 (14:49 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 16 Jun 2026 16:02:33 +0000 (09:02 -0700)
Continue walking the code path for the >4GB `hash-object --literally`
test to the hash algorithm step for LLP64 systems.

This patch lets the SHA1DC code use `size_t`, making it compatible with
LLP64 data models (as used e.g. by Windows).

The interested reader of this patch will note that we adjust the
signature of the `git_SHA1DCUpdate()` function without updating _any_
call site. This certainly puzzled at least one reviewer already, so here
is an explanation:

This function is never called directly, but always via the macro
`platform_SHA1_Update`, which is usually called via the macro
`git_SHA1_Update`. However, we never call `git_SHA1_Update()` directly
in `struct git_hash_algo`. Instead, we call `git_hash_sha1_update()`,
which is defined thusly:

    static void git_hash_sha1_update(git_hash_ctx *ctx,
                                     const void *data, size_t len)
    {
        git_SHA1_Update(&ctx->sha1, data, len);
    }

i.e. it contains an implicit downcast from `size_t` to `unsigned long`
(before this here patch). With this patch, there is no downcast anymore.

With this patch, finally, the t1007-hash-object.sh "files over 4GB hash
literally" test case is fixed.

Signed-off-by: Philip Oakley <philipoakley@iee.email>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
object-file.c
sha1dc_git.c
sha1dc_git.h
t/t1007-hash-object.sh

index dccbe0fc3ea8b908c38ddf10aeeaed670b9ce755..0056c369cee036e66a98c06b3858e8b4556e6478 100644 (file)
@@ -316,7 +316,7 @@ int parse_loose_header(const char *hdr, struct object_info *oi)
 }
 
 static void hash_object_body(const struct git_hash_algo *algo, struct git_hash_ctx *c,
-                            const void *buf, unsigned long len,
+                            const void *buf, size_t len,
                             struct object_id *oid,
                             char *hdr, size_t *hdrlen)
 {
@@ -336,7 +336,7 @@ void write_object_file_prepare(const struct git_hash_algo *algo,
        /* Generate the header */
        *hdrlen = format_object_header(hdr, *hdrlen, type, len);
 
-       /* Sha1.. */
+       /* Hash (function pointers) computation */
        hash_object_body(algo, &c, buf, len, oid, hdr, hdrlen);
 }
 
index 9b675a046ee699189f54e31cf9a4e8bfc6d304a6..fe58d7962a30c93f76460ad5ad269d505172e676 100644 (file)
@@ -27,10 +27,9 @@ void git_SHA1DCFinal(unsigned char hash[20], SHA1_CTX *ctx)
 /*
  * Same as SHA1DCUpdate, but adjust types to match git's usual interface.
  */
-void git_SHA1DCUpdate(SHA1_CTX *ctx, const void *vdata, unsigned long len)
+void git_SHA1DCUpdate(SHA1_CTX *ctx, const void *vdata, size_t len)
 {
        const char *data = vdata;
-       /* We expect an unsigned long, but sha1dc only takes an int */
        while (len > INT_MAX) {
                SHA1DCUpdate(ctx, data, INT_MAX);
                data += INT_MAX;
index f6f880cabea382dfbbd4306caddc6c22e780a2c8..0bcf1aa84b7241e6029d45e2858a615310eaaea2 100644 (file)
@@ -15,7 +15,7 @@ void git_SHA1DCInit(SHA1_CTX *);
 #endif
 
 void git_SHA1DCFinal(unsigned char [20], SHA1_CTX *);
-void git_SHA1DCUpdate(SHA1_CTX *ctx, const void *data, unsigned long len);
+void git_SHA1DCUpdate(SHA1_CTX *ctx, const void *data, size_t len);
 
 #define platform_SHA_IS_SHA1DC /* used by "test-tool sha1-is-sha1dc" */
 
index 7867fd1dbf940cc9bc33c7579de642c960dcdfa4..f028a1cbcc4ae9e84283a39e5516299517c85a0c 100755 (executable)
@@ -261,7 +261,7 @@ test_expect_success '--stdin outside of repository (uses default hash)' '
        test_cmp expect actual
 '
 
-test_expect_failure EXPENSIVE,SIZE_T_IS_64BIT,!LONG_IS_64BIT \
+test_expect_success EXPENSIVE,SIZE_T_IS_64BIT \
                'files over 4GB hash literally' '
        test-tool genzeros $((5*1024*1024*1024)) >big &&
        test_oid large5GB >expect &&