From bdb64d0399a33132a94fea861ac7b5bacf906ce0 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 23 Nov 2005 15:21:00 +0000 Subject: Protect against possible division by zeros (#316468, Steve Grubb) 2005-11-23 Behdad Esfahbod Protect against possible division by zeros (#316468, Steve Grubb) * pango/pango-context.c (update_metrics_from_items), pango/pango-fontset.c (pango_fontset_real_get_metrics): If count is zero, do not alter approximate_{char,digit}_width. * pango/opentype/disasm.c: Err on invalid DeltaFormat. --- ChangeLog | 10 ++++++++++ pango/opentype/disasm.c | 28 ++++++++++++++++++---------- pango/pango-context.c | 7 +++++-- pango/pango-fontset.c | 7 +++++-- 4 files changed, 38 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 05afa81b..1e44c6dc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2005-11-23 Behdad Esfahbod + + Protect against possible division by zeros (#316468, Steve Grubb) + + * pango/pango-context.c (update_metrics_from_items), + pango/pango-fontset.c (pango_fontset_real_get_metrics): If count is + zero, do not alter approximate_{char,digit}_width. + + * pango/opentype/disasm.c: Err on invalid DeltaFormat. + 2005-11-23 Behdad Esfahbod * pango/fonts.c (pango_font_description_get_absolute_size): Remove diff --git a/pango/opentype/disasm.c b/pango/opentype/disasm.c index a49aa3f8..544baa27 100644 --- a/pango/opentype/disasm.c +++ b/pango/opentype/disasm.c @@ -447,18 +447,26 @@ Dump_Device (TTO_Device *Device, FILE *stream, int indent, FT_Bool is_gsub) break; } - n_per = 16 / bits; - mask = (1 << bits) - 1; - mask = mask << (16 - bits); - DUMP (""); - for (i = Device->StartSize; i <= Device->EndSize ; i++) + if (!bits) + { + + fprintf(stderr, "invalid DeltaFormat!!!!!\n"); + } + else { - FT_UShort val = Device->DeltaValue[i / n_per]; - FT_Short signed_val = ((val << ((i % n_per) * bits)) & mask); - dump (stream, indent, "%d", signed_val >> (16 - bits)); - if (i != Device->EndSize) - DUMP (", "); + n_per = 16 / bits; + mask = (1 << bits) - 1; + mask = mask << (16 - bits); + + for (i = Device->StartSize; i <= Device->EndSize ; i++) + { + FT_UShort val = Device->DeltaValue[i / n_per]; + FT_Short signed_val = ((val << ((i % n_per) * bits)) & mask); + dump (stream, indent, "%d", signed_val >> (16 - bits)); + if (i != Device->EndSize) + DUMP (", "); + } } DUMP ("\n"); } diff --git a/pango/pango-context.c b/pango/pango-context.c index cc2dee6a..58fd3eaf 100644 --- a/pango/pango-context.c +++ b/pango/pango-context.c @@ -1338,8 +1338,11 @@ update_metrics_from_items (PangoFontMetrics *metrics, g_hash_table_destroy (fonts_seen); - metrics->approximate_char_width /= count; - metrics->approximate_digit_width /= count; + if (count) + { + metrics->approximate_char_width /= count; + metrics->approximate_digit_width /= count; + } } /** diff --git a/pango/pango-fontset.c b/pango/pango-fontset.c index 261b6d70..d0feb62c 100644 --- a/pango/pango-fontset.c +++ b/pango/pango-fontset.c @@ -182,8 +182,11 @@ pango_fontset_real_get_metrics (PangoFontset *fontset) g_hash_table_destroy (fonts_seen); - metrics->approximate_char_width /= count; - metrics->approximate_digit_width /= count; + if (count) + { + metrics->approximate_char_width /= count; + metrics->approximate_digit_width /= count; + } return metrics; } -- cgit v1.2.1