Try to better handle OOM situations

Fixes assert fail in https://github.com/behdad/harfbuzz/issues/161
with libharfbuzz-fuzzing.
This commit is contained in:
Behdad Esfahbod 2015-11-18 17:52:08 -08:00
parent ec625f7dfb
commit abadc1717d
8 changed files with 12 additions and 18 deletions

View File

@ -842,7 +842,7 @@ static inline bool ligate_input (hb_apply_context_t *c,
for (unsigned int i = 1; i < count; i++) for (unsigned int i = 1; i < count; i++)
{ {
while (buffer->idx < match_positions[i]) while (buffer->idx < match_positions[i] && !buffer->in_error)
{ {
if (!is_mark_ligature) { if (!is_mark_ligature) {
unsigned int new_lig_comp = components_so_far - last_num_components + unsigned int new_lig_comp = components_so_far - last_num_components +

View File

@ -890,7 +890,7 @@ apply_forward (OT::hb_apply_context_t *c,
{ {
bool ret = false; bool ret = false;
hb_buffer_t *buffer = c->buffer; hb_buffer_t *buffer = c->buffer;
while (buffer->idx < buffer->len) while (buffer->idx < buffer->len && !buffer->in_error)
{ {
if (accel.may_have (buffer->cur().codepoint) && if (accel.may_have (buffer->cur().codepoint) &&
(buffer->cur().mask & c->lookup_mask) && (buffer->cur().mask & c->lookup_mask) &&

View File

@ -188,7 +188,7 @@ preprocess_text_hangul (const hb_ot_shape_plan_t *plan,
*/ */
unsigned int count = buffer->len; unsigned int count = buffer->len;
for (buffer->idx = 0; buffer->idx < count;) for (buffer->idx = 0; buffer->idx < count && !buffer->in_error;)
{ {
hb_codepoint_t u = buffer->cur().codepoint; hb_codepoint_t u = buffer->cur().codepoint;

View File

@ -1243,7 +1243,7 @@ insert_dotted_circles (const hb_ot_shape_plan_t *plan HB_UNUSED,
buffer->idx = 0; buffer->idx = 0;
unsigned int last_syllable = 0; unsigned int last_syllable = 0;
while (buffer->idx < buffer->len) while (buffer->idx < buffer->len && !buffer->in_error)
{ {
unsigned int syllable = buffer->cur().syllable(); unsigned int syllable = buffer->cur().syllable();
syllable_type_t syllable_type = (syllable_type_t) (syllable & 0x0F); syllable_type_t syllable_type = (syllable_type_t) (syllable & 0x0F);

View File

@ -315,7 +315,7 @@ preprocess_text_thai (const hb_ot_shape_plan_t *plan,
buffer->clear_output (); buffer->clear_output ();
unsigned int count = buffer->len; unsigned int count = buffer->len;
for (buffer->idx = 0; buffer->idx < count;) for (buffer->idx = 0; buffer->idx < count && !buffer->in_error;)
{ {
hb_codepoint_t u = buffer->cur().codepoint; hb_codepoint_t u = buffer->cur().codepoint;
if (likely (!IS_SARA_AM (u))) { if (likely (!IS_SARA_AM (u))) {

View File

@ -490,11 +490,6 @@ insert_dotted_circles (const hb_ot_shape_plan_t *plan HB_UNUSED,
if (likely (!has_broken_syllables)) if (likely (!has_broken_syllables))
return; return;
hb_codepoint_t dottedcircle_glyph;
if (!font->get_glyph (0x25CCu, 0, &dottedcircle_glyph))
return;
hb_glyph_info_t dottedcircle = {0}; hb_glyph_info_t dottedcircle = {0};
if (!font->get_glyph (0x25CCu, 0, &dottedcircle.codepoint)) if (!font->get_glyph (0x25CCu, 0, &dottedcircle.codepoint))
return; return;
@ -503,9 +498,8 @@ insert_dotted_circles (const hb_ot_shape_plan_t *plan HB_UNUSED,
buffer->clear_output (); buffer->clear_output ();
buffer->idx = 0; buffer->idx = 0;
unsigned int last_syllable = 0; unsigned int last_syllable = 0;
while (buffer->idx < buffer->len) while (buffer->idx < buffer->len && !buffer->in_error)
{ {
unsigned int syllable = buffer->cur().syllable(); unsigned int syllable = buffer->cur().syllable();
syllable_type_t syllable_type = (syllable_type_t) (syllable & 0x0F); syllable_type_t syllable_type = (syllable_type_t) (syllable & 0x0F);

View File

@ -218,7 +218,7 @@ handle_variation_selector_cluster (const hb_ot_shape_normalize_context_t *c, uns
/* TODO Currently if there's a variation-selector we give-up, it's just too hard. */ /* TODO Currently if there's a variation-selector we give-up, it's just too hard. */
hb_buffer_t * const buffer = c->buffer; hb_buffer_t * const buffer = c->buffer;
hb_font_t * const font = c->font; hb_font_t * const font = c->font;
for (; buffer->idx < end - 1;) { for (; buffer->idx < end - 1 && !buffer->in_error;) {
if (unlikely (buffer->unicode->is_variation_selector (buffer->cur(+1).codepoint))) { if (unlikely (buffer->unicode->is_variation_selector (buffer->cur(+1).codepoint))) {
/* The next two lines are some ugly lines... But work. */ /* The next two lines are some ugly lines... But work. */
if (font->get_glyph (buffer->cur().codepoint, buffer->cur(+1).codepoint, &buffer->cur().glyph_index())) if (font->get_glyph (buffer->cur().codepoint, buffer->cur(+1).codepoint, &buffer->cur().glyph_index()))
@ -254,13 +254,13 @@ static inline void
decompose_multi_char_cluster (const hb_ot_shape_normalize_context_t *c, unsigned int end, bool short_circuit) decompose_multi_char_cluster (const hb_ot_shape_normalize_context_t *c, unsigned int end, bool short_circuit)
{ {
hb_buffer_t * const buffer = c->buffer; hb_buffer_t * const buffer = c->buffer;
for (unsigned int i = buffer->idx; i < end; i++) for (unsigned int i = buffer->idx; i < end && !buffer->in_error; i++)
if (unlikely (buffer->unicode->is_variation_selector (buffer->info[i].codepoint))) { if (unlikely (buffer->unicode->is_variation_selector (buffer->info[i].codepoint))) {
handle_variation_selector_cluster (c, end, short_circuit); handle_variation_selector_cluster (c, end, short_circuit);
return; return;
} }
while (buffer->idx < end) while (buffer->idx < end && !buffer->in_error)
decompose_current_character (c, short_circuit); decompose_current_character (c, short_circuit);
} }
@ -320,7 +320,7 @@ _hb_ot_shape_normalize (const hb_ot_shape_plan_t *plan,
buffer->clear_output (); buffer->clear_output ();
count = buffer->len; count = buffer->len;
for (buffer->idx = 0; buffer->idx < count;) for (buffer->idx = 0; buffer->idx < count && !buffer->in_error;)
{ {
unsigned int end; unsigned int end;
for (end = buffer->idx + 1; end < count; end++) for (end = buffer->idx + 1; end < count; end++)
@ -370,7 +370,7 @@ _hb_ot_shape_normalize (const hb_ot_shape_plan_t *plan,
count = buffer->len; count = buffer->len;
unsigned int starter = 0; unsigned int starter = 0;
buffer->next_glyph (); buffer->next_glyph ();
while (buffer->idx < count) while (buffer->idx < count && !buffer->in_error)
{ {
hb_codepoint_t composed, glyph; hb_codepoint_t composed, glyph;
if (/* We don't try to compose a non-mark character with it's preceding starter. if (/* We don't try to compose a non-mark character with it's preceding starter.

View File

@ -254,7 +254,7 @@ hb_insert_dotted_circle (hb_buffer_t *buffer, hb_font_t *font)
info.cluster = buffer->cur().cluster; info.cluster = buffer->cur().cluster;
info.mask = buffer->cur().mask; info.mask = buffer->cur().mask;
buffer->output_info (info); buffer->output_info (info);
while (buffer->idx < buffer->len) while (buffer->idx < buffer->len && !buffer->in_error)
buffer->next_glyph (); buffer->next_glyph ();
buffer->swap_buffers (); buffer->swap_buffers ();