Skip to content

Commit

Permalink
[Skrifa] Avoid initialization of HashSet with system random numbers
Browse files Browse the repository at this point in the history
Workaround for [1] and [2] - issues in the Chrome sandbox requiring
access to random number generators.

[1] https://bugs.chromium.org/p/chromium/issues/detail?id=1516634
[2] https://bugs.chromium.org/p/chromium/issues/detail?id=1516641
  • Loading branch information
drott committed Jan 8, 2024
1 parent 2cd4ac5 commit 0859ee1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
6 changes: 4 additions & 2 deletions skrifa/src/color/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ use read_fonts::{

use std::{collections::HashSet, fmt::Debug, ops::Range};

use traversal::{get_clipbox_font_units, traverse_v0_range, traverse_with_callbacks};
use traversal::{
get_clipbox_font_units, traverse_v0_range, traverse_with_callbacks, NonRandomHasherState,
};

pub use transform::Transform;

Expand Down Expand Up @@ -322,7 +324,7 @@ impl<'a> ColorGlyph<'a> {
painter.push_clip_box(rect);
}

let mut visited_set: HashSet<usize> = HashSet::new();
let mut visited_set = HashSet::with_hasher(NonRandomHasherState {});
visited_set.insert(*paint_id);
traverse_with_callbacks(
&resolve_paint(&instance, paint)?,
Expand Down
17 changes: 15 additions & 2 deletions skrifa/src/color/traversal.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::{cmp::Ordering, collections::HashSet, ops::Range};
use std::{
cmp::Ordering, collections::hash_map::DefaultHasher, collections::HashSet, hash::BuildHasher,
ops::Range,
};

use read_fonts::{
tables::colr::{CompositeMode, Extend},
Expand All @@ -13,6 +16,16 @@ use super::{
Brush, ColorPainter, ColorStop, PaintCachedColorGlyph, PaintError,
};

// Workaround for https://bugs.chromium.org/p/chromium/issues/detail?id=1516634.
pub(crate) struct NonRandomHasherState;

impl BuildHasher for NonRandomHasherState {
type Hasher = DefaultHasher;
fn build_hasher(&self) -> DefaultHasher {
DefaultHasher::new()
}
}

pub(crate) fn get_clipbox_font_units(
colr_instance: &ColrInstance,
glyph_id: GlyphId,
Expand Down Expand Up @@ -43,7 +56,7 @@ pub(crate) fn traverse_with_callbacks(
paint: &ResolvedPaint,
instance: &ColrInstance,
painter: &mut impl ColorPainter,
visited_set: &mut HashSet<usize>,
visited_set: &mut HashSet<usize, NonRandomHasherState>,
) -> Result<(), PaintError> {
match paint {
ResolvedPaint::ColrLayers { range } => {
Expand Down

0 comments on commit 0859ee1

Please sign in to comment.