Skip to content

Commit

Permalink
More careful range checks in STAT parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
jfkthame committed Mar 25, 2024
1 parent f05dbe6 commit 91ae931
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/stat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ bool OpenTypeSTAT::Parse(const uint8_t* data, size_t length) {
return Drop("Invalid designAxisSize");
}
if (this->designAxesOffset < headerEnd ||
size_t(this->designAxesOffset) +
size_t(this->designAxisCount) * size_t(this->designAxisSize) > length) {
size_t(this->designAxesOffset) > length ||
size_t(this->designAxisCount) * size_t(this->designAxisSize) >
length - size_t(this->designAxesOffset)) {
return Drop("Invalid designAxesOffset");
}
}
Expand Down Expand Up @@ -94,8 +95,9 @@ bool OpenTypeSTAT::Parse(const uint8_t* data, size_t length) {
}
} else {
if (this->offsetToAxisValueOffsets < headerEnd ||
size_t(this->offsetToAxisValueOffsets) +
size_t(this->axisValueCount) * sizeof(uint16_t) > length) {
size_t(this->offsetToAxisValueOffsets) > length ||
size_t(this->axisValueCount) * sizeof(uint16_t) >
length - size_t(this->offsetToAxisValueOffsets)) {
return Drop("Invalid offsetToAxisValueOffsets");
}
}
Expand All @@ -106,7 +108,9 @@ bool OpenTypeSTAT::Parse(const uint8_t* data, size_t length) {
if (!table.ReadU16(&axisValueOffset)) {
return Drop("Failed to read axis value offset");
}
if (this->offsetToAxisValueOffsets + axisValueOffset > length) {
// We already checked that offsetToAxisValueOffsets doesn't exceed length,
// so this subtraction will not underflow.
if (axisValueOffset > length - this->offsetToAxisValueOffsets) {
return Drop("Invalid axis value offset");
}
table.set_offset(this->offsetToAxisValueOffsets + axisValueOffset);
Expand Down

0 comments on commit 91ae931

Please sign in to comment.