Created
March 13, 2019 23:36
-
-
Save raphlinus/2cddf813aa7bdca226a3ec893d5b797e to your computer and use it in GitHub Desktop.
Example of unsoundness in harfbuzz crate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use harfbuzz::Blob; | |
fn create_blob() -> Blob { | |
let vec = vec![1; 256]; | |
Blob::new_read_only(&vec) | |
// BAD: vec is dropped here, the blob still holds a reference | |
} | |
fn blob_sum(blob: &Blob) -> u32 { | |
blob.iter().map(|byte| *byte as u32).sum() | |
} | |
fn main() { | |
let vec = vec![1; 256]; | |
let blob_ok = Blob::new_read_only(&vec); | |
let blob_bad = create_blob(); | |
println!("sum of bytes should be {}", blob_sum(&blob_ok)); | |
println!("sum of bytes (bad) is {}", blob_sum(&blob_bad)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment