diff options
author | Uoti Urpala <uau@glyph.nonexistent.invalid> | 2009-06-19 19:26:36 +0300 |
---|---|---|
committer | greg <greg@blackbox> | 2009-06-20 15:35:29 +0200 |
commit | 0b9223d493e016ccdce91aae1a6f69aff6c03a0f (patch) | |
tree | c1746049bf4173693b1cab28693a21bd6abaf394 /libass | |
parent | 6a5c6a3748e3825d7a4281cfeac4ca25b32c8571 (diff) | |
download | libass-0b9223d493e016ccdce91aae1a6f69aff6c03a0f.tar.bz2 libass-0b9223d493e016ccdce91aae1a6f69aff6c03a0f.tar.xz |
Use safe hash functions for composite bitmaps
Previously the composite bitmap hash keys were compared and hashed
based on all the bytes in the struct, which could cause problems
because of padding bytes. Change the code to use field-by-field
operations as already done for other hash key types.
The composite hash key contains two bitmap hash keys. The hashing
function currently handles those by calling the function to calculate
the corresponding bitmap hash, and then updating the composite hash by
treating the result of the function call as a byte buffer. An
alternative would be to change the hash functions so that the initial
hash value could be passed as a parameter to the recursively called
function.
Diffstat (limited to 'libass')
-rw-r--r-- | libass/ass_cache.c | 3 | ||||
-rw-r--r-- | libass/ass_cache.h | 8 | ||||
-rw-r--r-- | libass/ass_cache_template.c | 24 |
3 files changed, 26 insertions, 9 deletions
diff --git a/libass/ass_cache.c b/libass/ass_cache.c index 534300d9..309d5801 100644 --- a/libass/ass_cache.c +++ b/libass/ass_cache.c @@ -374,7 +374,8 @@ hashmap_t *ass_composite_cache_init(void) composite_cache = hashmap_init(sizeof(composite_hash_key_t), sizeof(composite_hash_val_t), 0xFFFF + 13, - composite_hash_dtor, NULL, NULL); + composite_hash_dtor, composite_compare, + composite_hash); return composite_cache; } diff --git a/libass/ass_cache.h b/libass/ass_cache.h index f374b86f..c1d25b24 100644 --- a/libass/ass_cache.h +++ b/libass/ass_cache.h @@ -83,14 +83,6 @@ hashmap_t *ass_bitmap_cache_reset(hashmap_t *bitmap_cache); void ass_bitmap_cache_done(hashmap_t *bitmap_cache); -// Cache for composited bitmaps -typedef struct composite_hash_key_s { - int aw, ah, bw, bh; - int ax, ay, bx, by; - bitmap_hash_key_t a; - bitmap_hash_key_t b; -} composite_hash_key_t; - typedef struct composite_hash_val_s { unsigned char *a; unsigned char *b; diff --git a/libass/ass_cache_template.c b/libass/ass_cache_template.c index 7f9ec95f..11c7588e 100644 --- a/libass/ass_cache_template.c +++ b/libass/ass_cache_template.c @@ -6,6 +6,8 @@ type member; #define FTVECTOR(member) \ FT_Vector member; +#define BITMAPHASHKEY(member) \ + bitmap_hash_key_t member; #define END(typedefnamename) \ } typedefnamename; @@ -21,6 +23,8 @@ a->member == b->member && #define FTVECTOR(member) \ a->member.x == b->member.x && a->member.y == b->member.y && +#define BITMAPHASHKEY(member) \ + bitmap_compare(&a->member, &b->member, sizeof(a->member)) && #define END(typedefname) \ 1; \ } @@ -35,6 +39,10 @@ #define GENERIC(type, member) \ hval = fnv_32a_buf(&p->member, sizeof(p->member), hval); #define FTVECTOR(member) GENERIC(, member.x); GENERIC(, member.y); +#define BITMAPHASHKEY(member) { \ + unsigned temp = bitmap_hash(&p->member, sizeof(p->member)); \ + hval = fnv_32a_buf(&temp, sizeof(temp), hval); \ + } #define END(typedefname) \ return hval; \ } @@ -82,7 +90,23 @@ START(glyph, glyph_hash_key_s) GENERIC(unsigned, outline) // border width, 16.16 END(glyph_hash_key_t) +// Cache for composited bitmaps +START(composite, composite_hash_key_s) + GENERIC(int, aw) + GENERIC(int, ah) + GENERIC(int, bw) + GENERIC(int, bh) + GENERIC(int, ax) + GENERIC(int, ay) + GENERIC(int, bx) + GENERIC(int, by) + BITMAPHASHKEY(a) + BITMAPHASHKEY(b) +END(composite_hash_key_t) + + #undef START #undef GENERIC #undef FTVECTOR +#undef BITMAPHASHKEY #undef END |