do not fail digest computation that often
authorHelmut Grohne <helmut@subdivi.de>
Sun, 24 Mar 2013 19:39:00 +0000 (20:39 +0100)
committerHelmut Grohne <helmut@subdivi.de>
Sun, 24 Mar 2013 19:39:00 +0000 (20:39 +0100)
fuzzy.c

diff --git a/fuzzy.c b/fuzzy.c
index 19ba00b..c82d3c1 100644 (file)
--- a/fuzzy.c
+++ b/fuzzy.c
@@ -222,11 +222,13 @@ int fuzzy_digest(const struct fuzzy_state *self, /*@out@*/ char *result) {
        /* Initial blocksize guess. */
        while((size_t)SSDEEP_BS(bi) * SPAMSUM_LENGTH < self->total_size) {
                ++bi;
-               if(bi >= self->bhend)
+               if(bi >= SSDEEP_BS(NUM_BLOCKHASHES))
                        /* The input exceeds data types. */
                        return -1;
        }
        /* Adapt blocksize guess to actual digest length. */
+       while(bi >= self->bhend)
+               --bi;
        while(bi > self->bhstart && self->bh[bi].dlen < SPAMSUM_LENGTH / 2)
                --bi;
        assert(!(bi > 0 && self->bh[bi].dlen < SPAMSUM_LENGTH / 2));