Skip to content

Commit

Permalink
Sanitise web fonts
Browse files Browse the repository at this point in the history
Fixes #3030.
  • Loading branch information
kmcallister authored and nox committed Aug 22, 2016
1 parent 32a0493 commit 6cbf9e7
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
1 change: 1 addition & 0 deletions components/gfx/Cargo.toml
Expand Up @@ -16,6 +16,7 @@ azure = {git = "https://github.com/servo/rust-azure", features = ["plugins"]}
bitflags = "0.7"
euclid = "0.10.1"
fnv = "1.0"
fontsan = {git = "https://github.com/servo/fontsan"}
gfx_traits = {path = "../gfx_traits"}
harfbuzz-sys = "0.1"
heapsize = "0.3.0"
Expand Down
15 changes: 13 additions & 2 deletions components/gfx/font_cache_thread.rs
Expand Up @@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use font_template::{FontTemplate, FontTemplateDescriptor};
use fontsan;
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
use ipc_channel::router::ROUTER;
use mime::{TopLevel, SubLevel};
Expand Down Expand Up @@ -252,8 +253,18 @@ impl FontCache {
channel_to_self.send(msg).unwrap();
return;
}
let mut bytes = bytes.lock().unwrap();
let bytes = mem::replace(&mut *bytes, Vec::new());
let bytes = mem::replace(&mut *bytes.lock().unwrap(), vec![]);
let bytes = match fontsan::process(&bytes) {
Ok(san) => san,
Err(_) => {
// FIXME(servo/fontsan#1): get an error message
debug!("Sanitiser rejected web font: \
family={:?} url={}", family_name, url);
let msg = Command::AddWebFont(family_name.clone(), sources.clone(), sender.clone());
channel_to_self.send(msg).unwrap();
return;
},
};
let command =
Command::AddDownloadedWebFont(family_name.clone(),
url.clone(),
Expand Down
1 change: 1 addition & 0 deletions components/gfx/lib.rs
Expand Up @@ -39,6 +39,7 @@ extern crate fnv;
// Platforms that use Freetype/Fontconfig library dependencies
#[cfg(any(target_os = "linux", target_os = "android", all(target_os = "windows", target_env = "gnu")))]
extern crate fontconfig;
extern crate fontsan;
#[cfg(any(target_os = "linux", target_os = "android", all(target_os = "windows", target_env = "gnu")))]
extern crate freetype;

Expand Down
11 changes: 11 additions & 0 deletions components/servo/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions ports/cef/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6cbf9e7

Please sign in to comment.