Skip to content

Commit

Permalink
Auto merge of #189 - CryZe:fix-freetype-panic, r=jdm
Browse files Browse the repository at this point in the history
Fix panic when parsing invalid `usWidthClass`

The code here just trusted the value to always to be valid, but since this may be an arbitrary font, the value may not always be valid. In my case the `usWidthClass` I'm seeing has the value 500, probably the `usWeightClass` accidentally being assigned to the `usWidthClass`.
  • Loading branch information
bors-servo authored Nov 23, 2021
2 parents 0edcf32 + bd6b39d commit 59213db
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/loaders/freetype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,14 +359,14 @@ impl Font {
_ => Style::Normal,
};
let stretch = match os2_table {
Some(os2_table) if (*os2_table).usWidthClass > 0 => {
Some(os2_table) if (1..=9).contains(&(*os2_table).usWidthClass) => {
Stretch(Stretch::MAPPING[((*os2_table).usWidthClass as usize) - 1])
}
_ => Stretch::NORMAL,
};
let weight = match os2_table {
None => Weight::NORMAL,
Some(os2_table) => Weight((*os2_table).usWeightClass as u32 as f32),
Some(os2_table) => Weight((*os2_table).usWeightClass as f32),
};
Properties {
style,
Expand Down

0 comments on commit 59213db

Please sign in to comment.