servo / font-kit

A cross-platform font loading library written in Rust
Apache License 2.0
693 stars 104 forks source link

Panic when checking file #250

Open qarmin opened 3 months ago

qarmin commented 3 months ago

I know that this a duplicate of other issues, but this seems to be first issue with code that produces problem and test file I didn't want to link to another issue, as it could be overlooked

code

fn check_file(path: &str) {
    let handle = Handle::Path {
        path: PathBuf::from(path),
        font_index: 0
    };
    match MemSource::from_fonts([handle.clone()].into_iter()) {
        Ok(mut source) => {
            let _ = source.all_families();
            let _ = source.select_best_match(&[], &font_kit::properties::Properties::new());
            let _ = source.select_by_postscript_name("");
            let _ = source.as_any();
            let _ = source.add_font(handle);
            let _ = source.all_families();
            let _ = source.select_best_match(&[], &font_kit::properties::Properties::new());
            let _ = source.select_by_postscript_name("");
            let _ = source.as_any();
        },
        Err(e) => {
            eprintln!("Error: {:?}", e);
        }
    }
}

cause this

thread 'main' panicked at /home/runner/.cargo/git/checkouts/font-kit-635e0cfc33286473/f1c992f/src/loaders/freetype.rs:1161:9:
assertion `left == right` failed
  left: 23
 right: 0
stack backtrace:
   0: rust_begin_unwind
             at /rustc/8bfcae730a5db2438bbda72796175bba21427be1/library/std/src/panicking.rs:665:5
   1: core::panicking::panic_fmt
             at /rustc/8bfcae730a5db2438bbda72796175bba21427be1/library/core/src/panicking.rs:74:14
   2: core::panicking::assert_failed_inner
             at /rustc/8bfcae730a5db2438bbda72796175bba21427be1/library/core/src/panicking.rs:410:17
   3: core::panicking::assert_failed
             at /rustc/8bfcae730a5db2438bbda72796175bba21427be1/library/core/src/panicking.rs:365:5
   4: font_kit::loaders::freetype::reset_freetype_face_char_size
             at /home/runner/.cargo/git/checkouts/font-kit-635e0cfc33286473/f1c992f/src/loaders/freetype.rs:1161:9
   5: font_kit::loaders::freetype::setup_freetype_face
             at /home/runner/.cargo/git/checkouts/font-kit-635e0cfc33286473/f1c992f/src/loaders/freetype.rs:1154:5
   6: font_kit::loaders::freetype::Font::from_bytes::{{closure}}
             at /home/runner/.cargo/git/checkouts/font-kit-635e0cfc33286473/f1c992f/src/loaders/freetype.rs:148:13
   7: std::thread::local::LocalKey<T>::try_with
             at /rustc/8bfcae730a5db2438bbda72796175bba21427be1/library/std/src/thread/local.rs:283:12
   8: std::thread::local::LocalKey<T>::with
             at /rustc/8bfcae730a5db2438bbda72796175bba21427be1/library/std/src/thread/local.rs:260:9
   9: font_kit::loaders::freetype::Font::from_bytes
             at /home/runner/.cargo/git/checkouts/font-kit-635e0cfc33286473/f1c992f/src/loaders/freetype.rs:135:26
  10: font_kit::loaders::freetype::Font::from_file
             at /home/runner/.cargo/git/checkouts/font-kit-635e0cfc33286473/f1c992f/src/loaders/freetype.rs:165:9
  11: <font_kit::loaders::freetype::Font as font_kit::loader::Loader>::from_file
             at /home/runner/.cargo/git/checkouts/font-kit-635e0cfc33286473/f1c992f/src/loaders/freetype.rs:1012:9
  12: font_kit::loader::Loader::from_path
             at /home/runner/.cargo/git/checkouts/font-kit-635e0cfc33286473/f1c992f/src/loader.rs:62:9
  13: font_kit::loader::Loader::from_handle
             at /home/runner/.cargo/git/checkouts/font-kit-635e0cfc33286473/f1c992f/src/loader.rs:79:18
  14: font_kit::loaders::freetype::Font::from_handle
             at /home/runner/.cargo/git/checkouts/font-kit-635e0cfc33286473/f1c992f/src/loaders/freetype.rs:208:9
  15: font_kit::sources::mem::add_font
             at /home/runner/.cargo/git/checkouts/font-kit-635e0cfc33286473/f1c992f/src/sources/mem.rs:190:16
  16: font_kit::sources::mem::MemSource::from_fonts
             at /home/runner/.cargo/git/checkouts/font-kit-635e0cfc33286473/f1c992f/src/sources/mem.rs:43:13
  17: font_kit::check_file
             at ./src/crates/font_kit/src/main.rs:32:11
  18: font_kit::main
             at ./src/crates/font_kit/src/main.rs:23:9
  19: core::ops::function::FnOnce::call_once
             at /rustc/8bfcae730a5db2438bbda72796175bba21427be1/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
timeout: the monitored command dumped core

##### Automatic Fuzzer note, output status "None", output signal "Some(6)"

compressed.zip