From 849bdb0d24902cbbafada9177713d83791b00e9d Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Wed, 19 Jul 2017 17:35:13 -0700 Subject: [PATCH] Fix a crash in the woff2 encoder when it encounters a loca table with a length of zero. --- src/font.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/font.cc b/src/font.cc index fc496e0..8dc1043 100644 --- a/src/font.cc +++ b/src/font.cc @@ -331,8 +331,11 @@ int NumGlyphs(const Font& font) { return 0; } int index_fmt = IndexFormat(font); - int num_glyphs = (loca_table->length / (index_fmt == 0 ? 2 : 4)) - 1; - return num_glyphs; + int loca_record_size = (index_fmt == 0 ? 2 : 4); + if (loca_table->length < loca_record_size) { + return 0; + } + return (loca_table->length / loca_record_size) - 1; } int IndexFormat(const Font& font) {