Skip to content

Commit

Permalink
Add lookup flag validation check.
Browse files Browse the repository at this point in the history
Checks existence of Glyph class definition table in GDEF table if bits of lookup flags which require the table are set.

BUG=76943
TEST=test/layout_common_table_test.cc
  • Loading branch information
[email protected] committed Mar 22, 2011
1 parent d52d77a commit 9fef4be
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/gdef.cc
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ bool ots_gdef_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
DROP_THIS_TABLE;
return true;
}
gdef->has_glyph_class_def = true;
}

if (offset_attach_list) {
Expand Down
2 changes: 2 additions & 0 deletions src/gdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace ots {
struct OpenTypeGDEF {
OpenTypeGDEF()
: version_2(false),
has_glyph_class_def(false),
has_mark_attachment_class_def(false),
has_mark_glyph_sets_def(false),
num_mark_glyph_sets(0),
Expand All @@ -20,6 +21,7 @@ struct OpenTypeGDEF {
}

bool version_2;
bool has_glyph_class_def;
bool has_mark_attachment_class_def;
bool has_mark_glyph_sets_def;
uint16_t num_mark_glyph_sets;
Expand Down
6 changes: 6 additions & 0 deletions src/layout.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const uint32_t kScriptTableTagDflt = 0x44464c54;
const uint16_t kNoRequiredFeatureIndexDefined = 0xFFFF;
// The lookup flag bit which indicates existence of MarkFilteringSet.
const uint16_t kUseMarkFilteringSetBit = 0x0010;
// The lookup flags which require GDEF table.
const uint16_t kGdefRequiredFlags = 0x0002 | 0x0004 | 0x0008;
// The mask for MarkAttachmentType.
const uint16_t kMarkAttachmentTypeMask = 0xFF00;
// The maximum type number of format for device tables.
Expand Down Expand Up @@ -188,6 +190,10 @@ bool ParseLookupTable(ots::OpenTypeFile *file, const uint8_t *data,
}

// Check lookup flags.
if ((lookup_flag & kGdefRequiredFlags) &&
(!file->gdef || !file->gdef->has_glyph_class_def)) {
return OTS_FAILURE();
}
if ((lookup_flag & kMarkAttachmentTypeMask) &&
(!file->gdef || !file->gdef->has_mark_attachment_class_def)) {
return OTS_FAILURE();
Expand Down
8 changes: 8 additions & 0 deletions test/layout_common_table_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,14 @@ TEST_F(LookupListTableTest, TesBadLookupType) {
EXPECT_FALSE(Parse());
}

TEST_F(LookupListTableTest, TesBadLookupFlag) {
BuildFakeLookupListTable(&out, 1, 1);
// Set IgnoreBaseGlyphs(0x0002) to the lookup flag of LookupTable[0].
out.Seek(6);
out.WriteU16(0x0002);
EXPECT_FALSE(Parse());
}

TEST_F(LookupListTableTest, TesBadSubtableCount) {
BuildFakeLookupListTable(&out, 1, 1);
// Set too large sutable count of LookupTable[0].
Expand Down

0 comments on commit 9fef4be

Please sign in to comment.