OLD | NEW |
1 /* | 1 /* |
2 * Copyright © 2007,2008,2009,2010 Red Hat, Inc. | 2 * Copyright © 2007,2008,2009,2010 Red Hat, Inc. |
3 * Copyright © 2012 Google, Inc. | 3 * Copyright © 2012 Google, Inc. |
4 * | 4 * |
5 * This is part of HarfBuzz, a text shaping library. | 5 * This is part of HarfBuzz, a text shaping library. |
6 * | 6 * |
7 * Permission is hereby granted, without written agreement and without | 7 * Permission is hereby granted, without written agreement and without |
8 * license or royalty fees, to use, copy, modify, and distribute this | 8 * license or royalty fees, to use, copy, modify, and distribute this |
9 * software and its documentation for any purpose, provided that the | 9 * software and its documentation for any purpose, provided that the |
10 * above copyright notice and the following two paragraphs appear in | 10 * above copyright notice and the following two paragraphs appear in |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 #ifndef HB_DEBUG_SANITIZE | 164 #ifndef HB_DEBUG_SANITIZE |
165 #define HB_DEBUG_SANITIZE (HB_DEBUG+0) | 165 #define HB_DEBUG_SANITIZE (HB_DEBUG+0) |
166 #endif | 166 #endif |
167 | 167 |
168 | 168 |
169 #define TRACE_SANITIZE(this) \ | 169 #define TRACE_SANITIZE(this) \ |
170 hb_auto_trace_t<HB_DEBUG_SANITIZE, bool> trace \ | 170 hb_auto_trace_t<HB_DEBUG_SANITIZE, bool> trace \ |
171 (&c->debug_depth, c->get_name (), this, HB_FUNC, \ | 171 (&c->debug_depth, c->get_name (), this, HB_FUNC, \ |
172 ""); | 172 ""); |
173 | 173 |
| 174 /* This limits sanitizing time on really broken fonts. */ |
| 175 #ifndef HB_SANITIZE_MAX_EDITS |
| 176 #define HB_SANITIZE_MAX_EDITS 100 |
| 177 #endif |
174 | 178 |
175 struct hb_sanitize_context_t | 179 struct hb_sanitize_context_t |
176 { | 180 { |
177 inline const char *get_name (void) { return "SANITIZE"; } | 181 inline const char *get_name (void) { return "SANITIZE"; } |
178 static const unsigned int max_debug_depth = HB_DEBUG_SANITIZE; | 182 static const unsigned int max_debug_depth = HB_DEBUG_SANITIZE; |
179 typedef bool return_t; | 183 typedef bool return_t; |
180 template <typename T> | 184 template <typename T> |
181 inline return_t process (const T &obj) { return obj.sanitize (this); } | 185 inline return_t dispatch (const T &obj) { return obj.sanitize (this); } |
182 static return_t default_return_value (void) { return true; } | 186 static return_t default_return_value (void) { return true; } |
183 bool stop_sublookup_iteration (const return_t r HB_UNUSED) const { return fals
e; } | 187 bool stop_sublookup_iteration (const return_t r HB_UNUSED) const { return fals
e; } |
184 | 188 |
185 inline void init (hb_blob_t *b) | 189 inline void init (hb_blob_t *b) |
186 { | 190 { |
187 this->blob = hb_blob_reference (b); | 191 this->blob = hb_blob_reference (b); |
188 this->writable = false; | 192 this->writable = false; |
189 } | 193 } |
190 | 194 |
191 inline void start_processing (void) | 195 inline void start_processing (void) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 } | 244 } |
241 | 245 |
242 template <typename Type> | 246 template <typename Type> |
243 inline bool check_struct (const Type *obj) const | 247 inline bool check_struct (const Type *obj) const |
244 { | 248 { |
245 return likely (this->check_range (obj, obj->min_size)); | 249 return likely (this->check_range (obj, obj->min_size)); |
246 } | 250 } |
247 | 251 |
248 inline bool may_edit (const void *base HB_UNUSED, unsigned int len HB_UNUSED) | 252 inline bool may_edit (const void *base HB_UNUSED, unsigned int len HB_UNUSED) |
249 { | 253 { |
| 254 if (this->edit_count >= HB_SANITIZE_MAX_EDITS) |
| 255 return false; |
| 256 |
250 const char *p = (const char *) base; | 257 const char *p = (const char *) base; |
251 this->edit_count++; | 258 this->edit_count++; |
252 | 259 |
253 hb_auto_trace_t<HB_DEBUG_SANITIZE, bool> trace | 260 hb_auto_trace_t<HB_DEBUG_SANITIZE, bool> trace |
254 (&this->debug_depth, "SANITIZE", this->blob, NULL, | 261 (&this->debug_depth, "SANITIZE", this->blob, NULL, |
255 "may_edit(%u) [%p..%p] (%d bytes) in [%p..%p] -> %s", | 262 "may_edit(%u) [%p..%p] (%d bytes) in [%p..%p] -> %s", |
256 this->edit_count, | 263 this->edit_count, |
257 p, p + len, len, | 264 p, p + len, len, |
258 this->start, this->end, | 265 this->start, this->end, |
259 this->writable ? "GRANTED" : "DENIED"); | 266 this->writable ? "GRANTED" : "DENIED"); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 unsigned int len = this->head - this->start; | 404 unsigned int len = this->head - this->start; |
398 void *p = malloc (len); | 405 void *p = malloc (len); |
399 if (p) | 406 if (p) |
400 memcpy (p, this->start, len); | 407 memcpy (p, this->start, len); |
401 return reinterpret_cast<Type *> (p); | 408 return reinterpret_cast<Type *> (p); |
402 } | 409 } |
403 | 410 |
404 template <typename Type> | 411 template <typename Type> |
405 inline Type *allocate_size (unsigned int size) | 412 inline Type *allocate_size (unsigned int size) |
406 { | 413 { |
407 if (unlikely (this->ran_out_of_room || this->end - this->head < size)) { | 414 if (unlikely (this->ran_out_of_room || this->end - this->head < ptrdiff_t (s
ize))) { |
408 this->ran_out_of_room = true; | 415 this->ran_out_of_room = true; |
409 return NULL; | 416 return NULL; |
410 } | 417 } |
411 memset (this->head, 0, size); | 418 memset (this->head, 0, size); |
412 char *ret = this->head; | 419 char *ret = this->head; |
413 this->head += size; | 420 this->head += size; |
414 return reinterpret_cast<Type *> (ret); | 421 return reinterpret_cast<Type *> (ret); |
415 } | 422 } |
416 | 423 |
417 template <typename Type> | 424 template <typename Type> |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 /* Glyph index number, same as uint16 (length = 16 bits) */ | 616 /* Glyph index number, same as uint16 (length = 16 bits) */ |
610 typedef USHORT GlyphID; | 617 typedef USHORT GlyphID; |
611 | 618 |
612 /* Script/language-system/feature index */ | 619 /* Script/language-system/feature index */ |
613 struct Index : USHORT { | 620 struct Index : USHORT { |
614 static const unsigned int NOT_FOUND_INDEX = 0xFFFF; | 621 static const unsigned int NOT_FOUND_INDEX = 0xFFFF; |
615 }; | 622 }; |
616 DEFINE_NULL_DATA (Index, "\xff\xff"); | 623 DEFINE_NULL_DATA (Index, "\xff\xff"); |
617 | 624 |
618 /* Offset to a table, same as uint16 (length = 16 bits), Null offset = 0x0000 */ | 625 /* Offset to a table, same as uint16 (length = 16 bits), Null offset = 0x0000 */ |
619 typedef USHORT Offset; | 626 struct Offset : USHORT |
| 627 { |
| 628 inline bool is_null (void) const { return 0 == *this; } |
| 629 public: |
| 630 DEFINE_SIZE_STATIC (2); |
| 631 }; |
620 | 632 |
621 /* LongOffset to a table, same as uint32 (length = 32 bits), Null offset = 0x000
00000 */ | 633 /* LongOffset to a table, same as uint32 (length = 32 bits), Null offset = 0x000
00000 */ |
622 typedef ULONG LongOffset; | 634 struct LongOffset : ULONG |
| 635 { |
| 636 inline bool is_null (void) const { return 0 == *this; } |
| 637 public: |
| 638 DEFINE_SIZE_STATIC (4); |
| 639 }; |
623 | 640 |
624 | 641 |
625 /* CheckSum */ | 642 /* CheckSum */ |
626 struct CheckSum : ULONG | 643 struct CheckSum : ULONG |
627 { | 644 { |
628 static uint32_t CalcTableChecksum (ULONG *Table, uint32_t Length) | 645 static uint32_t CalcTableChecksum (ULONG *Table, uint32_t Length) |
629 { | 646 { |
630 uint32_t Sum = 0L; | 647 uint32_t Sum = 0L; |
631 ULONG *EndPtr = Table+((Length+3) & ~3) / ULONG::static_size; | 648 ULONG *EndPtr = Table+((Length+3) & ~3) / ULONG::static_size; |
632 | 649 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 | 684 |
668 template <typename OffsetType, typename Type> | 685 template <typename OffsetType, typename Type> |
669 struct GenericOffsetTo : OffsetType | 686 struct GenericOffsetTo : OffsetType |
670 { | 687 { |
671 inline const Type& operator () (const void *base) const | 688 inline const Type& operator () (const void *base) const |
672 { | 689 { |
673 unsigned int offset = *this; | 690 unsigned int offset = *this; |
674 if (unlikely (!offset)) return Null(Type); | 691 if (unlikely (!offset)) return Null(Type); |
675 return StructAtOffset<Type> (base, offset); | 692 return StructAtOffset<Type> (base, offset); |
676 } | 693 } |
677 inline Type& operator () (void *base) | |
678 { | |
679 unsigned int offset = *this; | |
680 return StructAtOffset<Type> (base, offset); | |
681 } | |
682 | 694 |
683 inline Type& serialize (hb_serialize_context_t *c, void *base) | 695 inline Type& serialize (hb_serialize_context_t *c, void *base) |
684 { | 696 { |
685 Type *t = c->start_embed<Type> (); | 697 Type *t = c->start_embed<Type> (); |
686 this->set ((char *) t - (char *) base); /* TODO(serialize) Overflow? */ | 698 this->set ((char *) t - (char *) base); /* TODO(serialize) Overflow? */ |
687 return *t; | 699 return *t; |
688 } | 700 } |
689 | 701 |
690 inline bool sanitize (hb_sanitize_context_t *c, void *base) { | 702 inline bool sanitize (hb_sanitize_context_t *c, void *base) { |
691 TRACE_SANITIZE (this); | 703 TRACE_SANITIZE (this); |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
953 return p ? p - this->array : -1; | 965 return p ? p - this->array : -1; |
954 } | 966 } |
955 } | 967 } |
956 }; | 968 }; |
957 | 969 |
958 | 970 |
959 } /* namespace OT */ | 971 } /* namespace OT */ |
960 | 972 |
961 | 973 |
962 #endif /* HB_OPEN_TYPE_PRIVATE_HH */ | 974 #endif /* HB_OPEN_TYPE_PRIVATE_HH */ |
OLD | NEW |