Skip to content

Commit 80ce38c

Browse files
authored
Merge pull request #6996 from libgit2/ethomson/sha256_int
hash: allow `unsigned int` != `size_t` in sha256
2 parents 9961198 + fb7fef0 commit 80ce38c

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/util/hash/builtin.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,23 @@ int git_hash_sha256_init(git_hash_sha256_ctx *ctx)
3232
return 0;
3333
}
3434

35-
int git_hash_sha256_update(git_hash_sha256_ctx *ctx, const void *data, size_t len)
35+
int git_hash_sha256_update(git_hash_sha256_ctx *ctx, const void *_data, size_t len)
3636
{
37+
const unsigned char *data = _data;
3738
GIT_ASSERT_ARG(ctx);
38-
if (SHA256Input(&ctx->c, data, len)) {
39-
git_error_set(GIT_ERROR_SHA, "SHA256 error");
40-
return -1;
39+
40+
while (len > 0) {
41+
unsigned int chunk = (len > UINT_MAX) ? UINT_MAX : (unsigned int)len;
42+
43+
if (SHA256Input(&ctx->c, data, chunk)) {
44+
git_error_set(GIT_ERROR_SHA, "SHA256 error");
45+
return -1;
46+
}
47+
48+
data += chunk;
49+
len -= chunk;
4150
}
51+
4252
return 0;
4353
}
4454

0 commit comments

Comments
 (0)