mirror of
https://github.com/git-for-windows/git.git
synced 2025-12-11 19:22:58 -06:00
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>
40 lines
869 B
C
40 lines
869 B
C
#include "git-compat-util.h"
|
|
#include "sha1dc_git.h"
|
|
#include "hex.h"
|
|
|
|
#ifdef DC_SHA1_EXTERNAL
|
|
/*
|
|
* Same as SHA1DCInit, but with default save_hash=0
|
|
*/
|
|
void git_SHA1DCInit(SHA1_CTX *ctx)
|
|
{
|
|
SHA1DCInit(ctx);
|
|
SHA1DCSetSafeHash(ctx, 0);
|
|
}
|
|
#endif
|
|
|
|
/*
|
|
* Same as SHA1DCFinal, but convert collision attack case into a verbose die().
|
|
*/
|
|
void git_SHA1DCFinal(unsigned char hash[20], SHA1_CTX *ctx)
|
|
{
|
|
if (!SHA1DCFinal(hash, ctx))
|
|
return;
|
|
die("SHA-1 appears to be part of a collision attack: %s",
|
|
hash_to_hex_algop(hash, &hash_algos[GIT_HASH_SHA1]));
|
|
}
|
|
|
|
/*
|
|
* Same as SHA1DCUpdate, but adjust types to match git's usual interface.
|
|
*/
|
|
void git_SHA1DCUpdate(SHA1_CTX *ctx, const void *vdata, size_t len)
|
|
{
|
|
const char *data = vdata;
|
|
while (len > INT_MAX) {
|
|
SHA1DCUpdate(ctx, data, INT_MAX);
|
|
data += INT_MAX;
|
|
len -= INT_MAX;
|
|
}
|
|
SHA1DCUpdate(ctx, data, len);
|
|
}
|