Unverified Commit eb4c6d09 authored by Jeremy Soller's avatar Jeremy Soller Committed by GitHub

Merge pull request #7 from brayniac/fuzz-fix-1

fix: out of bounds read for empty font data
parents ac82e0bd 7d0454fa
......@@ -246,8 +246,12 @@ fn platform_encoding_id(platform_id: PlatformId, encoding_id: Option<u16>, langu
// truetype fonts that aren't padded to alignment, define ALLOW_UNALIGNED_TRUETYPE
pub fn is_font(font: &[u8]) -> bool {
let tag = &font[0..4];
tag == [b'1', 0, 0, 0] || tag == b"typ1" || tag == b"OTTO" || tag == [0, 1, 0, 0]
if font.len() >= 4 {
let tag = &font[0..4];
tag == [b'1', 0, 0, 0] || tag == b"typ1" || tag == b"OTTO" || tag == [0, 1, 0, 0]
} else {
false
}
}
fn find_table(data: &[u8], fontstart: usize, tag: &[u8]) -> u32 {
......
extern crate stb_truetype;
mod tests {
use stb_truetype;
#[test]
fn is_font() {
assert!(stb_truetype::is_font(b"OTTO"));
assert!(!stb_truetype::is_font(b""));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment