Skip to content

Commit 7d464b8

Browse files
authored
[read-fonts] aat: use wrapping to avoid panics on 32-bit (#2017)
Security analysis pointed at that these ops could overflow only on 32-bit builds. So use wrapping to avoid the cost on target platforms. Any values that overflow will be caught by subsequent checked memory reads and return an error anyway. internal bug ref: b/537783431
1 parent d0f5d07 commit 7d464b8

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

read-fonts/src/tables/aat.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ impl Lookup10<'_> {
166166
.checked_sub(self.first_glyph())
167167
.ok_or(ReadError::OutOfBounds)? as usize;
168168
let unit_size = self.unit_size() as usize;
169-
let offset = ix * unit_size;
169+
let offset = ix.wrapping_mul(unit_size);
170170
let mut cursor = FontData::new(self.values_data()).cursor();
171171
cursor.advance_by(offset);
172172
let val = match unit_size {
@@ -477,14 +477,16 @@ where
477477
if class >= self.n_classes {
478478
class = class::OUT_OF_BOUNDS as usize;
479479
}
480-
let state_ix = state as usize * self.n_classes + class;
480+
let state_ix = (state as usize)
481+
.wrapping_mul(self.n_classes)
482+
.wrapping_add(class);
481483
let entry_ix = self
482484
.state_array
483485
.get(state_ix)
484486
.copied()
485487
.ok_or(ReadError::OutOfBounds)?
486488
.get() as usize;
487-
let entry_offset = entry_ix * StateEntry::<T>::RAW_BYTE_LEN;
489+
let entry_offset = entry_ix.wrapping_mul(StateEntry::<T>::RAW_BYTE_LEN);
488490
let entry_data = self
489491
.entry_table
490492
.get(entry_offset..)

0 commit comments

Comments
 (0)