From: handa Date: Sun, 29 Jun 2008 13:13:07 +0000 (+0000) Subject: (read_device_table): Accept an invalid table. X-Git-Tag: REL-0-9-8~6 X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6f561ba035a72fb4a0553ca51d2f7576d36a9ee2;p=m17n%2Flibotf.git (read_device_table): Accept an invalid table. --- diff --git a/src/otfopen.c b/src/otfopen.c index ea0445b..ba74e24 100644 --- a/src/otfopen.c +++ b/src/otfopen.c @@ -951,41 +951,48 @@ read_device_table (OTF *otf, OTF_Stream *stream, long offset, READ_UINT16 (stream, table->EndSize); READ_UINT16 (stream, table->DeltaFormat); num = table->EndSize - table->StartSize + 1; - OTF_MALLOC (table->DeltaValue, num, ""); + if (num > 0 && table->DeltaFormat >= 1 && table->DeltaFormat <= 3) + { + OTF_MALLOC (table->DeltaValue, num, ""); - if (table->DeltaFormat == 1) - for (i = 0; i < num; i++) - { - if ((i % 8) == 0) - READ_UINT16 (stream, val); - intval.int2 = (val >> (14 - (i % 8) * 2)) & 0x03; - table->DeltaValue[i] = intval.int2; - } - else if (table->DeltaFormat == 2) - for (i = 0; i < num; i++) - { - if ((i % 4) == 0) - READ_UINT16 (stream, val); - intval.int4 = (val >> (12 - (i % 4) * 4)) & 0x0F; - table->DeltaValue[i] = intval.int4; - } - else if (table->DeltaFormat == 3) - for (i = 0; i < num; i++) - { - if ((i % 2) == 0) + if (table->DeltaFormat == 1) + for (i = 0; i < num; i++) { - READ_UINT16 (stream, val); - intval.int8 = val >> 8; - table->DeltaValue[i] = intval.int8; + if ((i % 8) == 0) + READ_UINT16 (stream, val); + intval.int2 = (val >> (14 - (i % 8) * 2)) & 0x03; + table->DeltaValue[i] = intval.int2; } - else + else if (table->DeltaFormat == 2) + for (i = 0; i < num; i++) { - intval.int8 = val >> 8; - table->DeltaValue[i] = intval.int8; + if ((i % 4) == 0) + READ_UINT16 (stream, val); + intval.int4 = (val >> (12 - (i % 4) * 4)) & 0x0F; + table->DeltaValue[i] = intval.int4; } - } + else /* (table->DeltaFormat == 3) */ + for (i = 0; i < num; i++) + { + if ((i % 2) == 0) + { + READ_UINT16 (stream, val); + intval.int8 = val >> 8; + table->DeltaValue[i] = intval.int8; + } + else + { + intval.int8 = val >> 8; + table->DeltaValue[i] = intval.int8; + } + } + } else - OTF_ERROR (OTF_ERROR_TABLE, " (Invalid format)"); + { + /* Invalid DeltaFormat but several fonts has such values (bug of + fontforge?). So accept it with NULL delta values. */ + table->DeltaValue = NULL; + } return 0; }