]> granicus.if.org Git - libass/commitdiff
Use safe hash functions for composite bitmaps
authorUoti Urpala <uau@glyph.nonexistent.invalid>
Fri, 19 Jun 2009 16:26:36 +0000 (19:26 +0300)
committergreg <greg@blackbox>
Sat, 20 Jun 2009 13:35:29 +0000 (15:35 +0200)
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.

libass/ass_cache.c
libass/ass_cache.h
libass/ass_cache_template.c

index 534300d9621ef39e72c2d9c9cd85d457c2550089..309d580147a501fc2d238b4485e1e5692416da7b 100644 (file)
@@ -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;
 }
 
index f374b86fcc70be57fd909667ba78072dc2bc4229..c1d25b240af15841a706d2e3cf11e27e52c5e6db 100644 (file)
@@ -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;
index 7f9ec95f570348f464c08b7b157efefb392a989f..11c7588ec9150c2687f9600a0f15d20a6f561bc1 100644 (file)
@@ -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; \
     }
 #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