diff --git a/hdrcache.c b/hdrcache.c index 5bcef1a..b0e16bc 100644 --- a/hdrcache.c +++ b/hdrcache.c @@ -95,6 +95,15 @@ int make_key(const char *path, const struct stat *st, char *key) static const int hdrsize_max = (256 << 10); +static +unsigned hash(const unsigned char *blob, int size) +{ + unsigned h = 5381; + while (size-- > 0) + h = h * 33 + *blob++; + return h; +} + Header hdrcache_get(const char *path, const struct stat *st, unsigned *off) { if (initialize() < 0) @@ -117,9 +126,9 @@ Header hdrcache_get(const char *path, const struct stat *st, unsigned *off) mcdb_put(env, key, keysize, data, datasize); } void *blob = data->blob; + int blobsize = datasize - sizeof(struct cache_ent) + 1; char ublob[hdrsize_max]; if (data->vflags & V_LZO) { - int blobsize = datasize - sizeof(struct cache_ent) + 1; lzo_uint ublobsize = 0; int rc = lzo1x_decompress(blob, blobsize, ublob, &ublobsize, NULL); if (rc != LZO_E_OK || ublobsize < 1 || ublobsize > hdrsize_max) { @@ -127,8 +136,11 @@ Header hdrcache_get(const char *path, const struct stat *st, unsigned *off) return NULL; } blob = ublob; + blobsize = ublobsize; } + fprintf(stderr, "blob %x (%d) hash 1: %x\n", *(unsigned *) blob, blobsize, hash(blob, blobsize)); Header h = headerLoad(blob); + fprintf(stderr, "blob %x (%d) hash 2: %x\n", *(unsigned *) blob, blobsize, hash(blob, blobsize)); if (h == NULL) { fprintf(stderr, "%s %s: headerLoad failed\n", __func__, key); return NULL;