commit bf959b2ce61af8a67a3e07336b97ccfc66aef487
parent 88318ab79460dbf2c045e987868159a04180f237
Author: nolash <dev@holbrook.no>
Date: Tue, 14 Sep 2021 17:03:15 +0200
Fix batch align detection bug in file hasher
Diffstat:
2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/src/file.c b/src/file.c
@@ -52,7 +52,7 @@ int filehash_sum(filehash_t *fctx) {
}
blocks_span_length += blocks * fctx->spans[i];
- if (remain_length > 0) {
+ if (remain_length > 1) {
blocks_span_length -= SWARM_BLOCK_SIZE - remain_length;
}
@@ -90,7 +90,7 @@ static int filehash_write_hash(filehash_t *fctx, int level, const char *data) {
fctx->writes[level] += 1;
memcpy(fctx->ptr[level], data, _SWARM_WORD_SIZE);
- if (fctx->writes[level] == _SWARM_BATCH_SIZE) {
+ if (fctx->writes[level] % _SWARM_BATCH_SIZE == 0) {
bctx = &fctx->bmt_context;
next_level = level + 1;
bmt_init(bctx, fctx->ptr[next_level], SWARM_BLOCK_SIZE, (long long)fctx->spans[next_level]);
diff --git a/test/check_file.c b/test/check_file.c
@@ -79,16 +79,34 @@ START_TEST(check_file_vectors) {
int lengths[] = {
SWARM_BLOCK_SIZE,
+ SWARM_BLOCK_SIZE + _SWARM_WORD_SIZE - 1,
+ SWARM_BLOCK_SIZE + _SWARM_WORD_SIZE,
+ SWARM_BLOCK_SIZE + (_SWARM_WORD_SIZE * 2) - 1,
+ SWARM_BLOCK_SIZE + (_SWARM_WORD_SIZE * 2),
SWARM_BLOCK_SIZE * 2,
SWARM_BLOCK_SIZE * _SWARM_BATCH_SIZE,
SWARM_BLOCK_SIZE * _SWARM_BATCH_SIZE + _SWARM_WORD_SIZE - 1,
+ SWARM_BLOCK_SIZE * _SWARM_BATCH_SIZE + _SWARM_WORD_SIZE,
+ SWARM_BLOCK_SIZE * _SWARM_BATCH_SIZE + (_SWARM_WORD_SIZE * 2),
+ SWARM_BLOCK_SIZE * (_SWARM_BATCH_SIZE + 1),
+ //SWARM_BLOCK_SIZE * (_SWARM_BATCH_SIZE + 2),
+ SWARM_BLOCK_SIZE * _SWARM_BATCH_SIZE * _SWARM_BATCH_SIZE,
};
char *vectors[] = {
"c10090961e7682a10890c334d759a28426647141213abda93b096b892824d2ef",
+ "91699c83ed93a1f87e326a29ccd8cc775323f9e7260035a5f014c975c5f3cd28",
+ "73759673a52c1f1707cbb61337645f4fcbd209cdc53d7e2cedaaa9f44df61285",
+ "db1313a727ffc184ae52a70012fbbf7235f551b9f2d2da04bf476abe42a3cb42",
+ "ade7af36ac0c7297dc1c11fd7b46981b629c6077bce75300f85b02a6153f161b",
"29a5fb121ce96194ba8b7b823a1f9c6af87e1791f824940a53b5a7efe3f790d9",
"3047d841077898c26bbe6be652a2ec590a5d9bd7cd45d290ea42511b48753c09",
"e5c76afa931e33ac94bce2e754b1bb6407d07f738f67856783d93934ca8fc576",
+ "485a526fc74c8a344c43a4545a5987d17af9ab401c0ef1ef63aefcc5c2c086df",
+ "624b2abb7aefc0978f891b2a56b665513480e5dc195b4a66cd8def074a6d2e94",
+ "b8e1804e37a064d28d161ab5f256cc482b1423d5cd0a6b30fde7b0f51ece9199",
+ //"59de730bf6c67a941f3b2ffa2f920acfaa1713695ad5deea12b4a121e5f23fa1",
+ "522194562123473dcfd7a457b18ee7dee8b7db70ed3cfa2b73f348a992fdfd3b",
};
filehash_init(&fh);