Skip to content

Commit

Permalink
Merge pull request #281 from jfkthame/glat-serialize
Browse files Browse the repository at this point in the history
Avoid calling Serialize() for an invalid Glat table
  • Loading branch information
khaledhosny authored Jul 22, 2024
2 parents 3324425 + 6787a2c commit 27d63ae
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/glat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ bool OpenTypeGLAT_v1::Parse(const uint8_t* data, size_t length) {
}

bool OpenTypeGLAT_v1::Serialize(OTSStream* out) {
assert(ShouldSerialize());
if (!out->WriteU32(this->version) ||
!SerializeParts(this->entries, out)) {
return Error("Failed to write table");
Expand Down Expand Up @@ -141,6 +142,7 @@ bool OpenTypeGLAT_v2::Parse(const uint8_t* data, size_t length) {
}

bool OpenTypeGLAT_v2::Serialize(OTSStream* out) {
assert(ShouldSerialize());
if (!out->WriteU32(this->version) ||
!SerializeParts(this->entries, out)) {
return Error("Failed to write table");
Expand Down Expand Up @@ -263,6 +265,7 @@ bool OpenTypeGLAT_v3::Parse(const uint8_t* data, size_t length,
}

bool OpenTypeGLAT_v3::Serialize(OTSStream* out) {
assert(ShouldSerialize());
if (!out->WriteU32(this->version) ||
!out->WriteU32(this->compHead) ||
!SerializeParts(this->entries, out)) {
Expand Down
4 changes: 4 additions & 0 deletions src/glat.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ class OpenTypeGLAT : public Table {
bool Parse(const uint8_t* data, size_t length);
bool Serialize(OTSStream* out);

virtual bool ShouldSerialize() {
return handler && handler->ShouldSerialize();
}

private:
Font* font;
uint32_t tag;
Expand Down
Binary file not shown.
1 change: 1 addition & 0 deletions tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ bad_fonts = [
'fonts/bad/ed550c912a8c5febfdad9ca2500b3284ecfac0d7.ttf',
'fonts/bad/edaf09c932e0582b1473384f66d5571da752a4d2.otf',
'fonts/bad/f1dba4340ce94f5359fa4434debc7efcfd1b521f.ttf',
'fonts/bad/f457d1f9504dbf206f50ea8ae7ab1bc4c51b95c0.ttc',
]

fuzzing_fonts = good_fonts + bad_fonts + [
Expand Down

0 comments on commit 27d63ae

Please sign in to comment.