Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"unsafe precondition(s) violated" querying tables from "Apple Color Emoji" #40

Open
SamRodri opened this issue May 29, 2024 · 1 comment

Comments

@SamRodri
Copy link

This code panics on macOS:

use std::sync::Arc;

fn main() {
    let (font, i) = find_system_font("Apple Color Emoji");
    let face = harfbuzz_rs::Face::from_bytes(&font, i);
    let _ = face.table_with_tag(b"GSUB").is_some();
}

fn find_system_font(name: &str) -> (Arc<Vec<u8>>, u32) {
    let font = font_kit::source::SystemSource::new()
        .select_best_match(
            &[font_kit::family_name::FamilyName::Title(name.to_owned())],
            &font_kit::properties::Properties::new(),
        )
        .unwrap();
    match font {
        font_kit::handle::Handle::Path { .. } => panic!("did not expect path"),
        font_kit::handle::Handle::Memory { bytes, font_index } => (bytes, font_index),
    }
}

Panic:

unsafe precondition(s) violated: slice::from_raw_parts requires the pointer to be aligned and non-null, and the total size of the slice not to exceed `isize::MAX`
stack backtrace:
   0: rust_begin_unwind
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/panicking.rs:645:5
   1: core::panicking::panic_nounwind_fmt::runtime
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/panicking.rs:110:18
   2: core::panicking::panic_nounwind_fmt
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/panicking.rs:123:9
   3: core::panicking::panic_nounwind
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/panicking.rs:156:5
   4: core::slice::raw::from_raw_parts::precondition_check
   5: core::slice::raw::from_raw_parts
   6: harfbuzz_rs::blob::Blob::get_data
   7: <harfbuzz_rs::blob::Blob as core::ops::deref::Deref>::deref
   8: harfbuzz_rs::face::Face::table_with_tag
   9: harfbuzz_issue::main
  10: core::ops::function::FnOnce::call_once

I think "Apple Color Emoji" does not have GSUB, so I expected false there.


I first encountered the issue here: zng-ui/zng#242

Minimized issue crate here: https://github.com/SamRodri/harfbuzz-issue

@SamRodri
Copy link
Author

I worked around the issue by not using harfbuzz_rs to query

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant