Repository: zng-ui/zng (language: rust)

Issue:
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`
In the latest [Apple CI run](https://github.com/zng-ui/zng/actions/runs/9272295205/job/25510582603)

Looks like a problem in harbuzz_rs (trying to allocate usize::MAX maybe?)

<details>
  <summary>stacktrace</summary>

```
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`
2024-05-28T16:02:52.0097850Z stack backtrace:
2024-05-28T16:02:52.0127030Z    0:        0x10ac42683 - std::backtrace_rs::backtrace::libunwind::trace::h5bfe4001d39ebff3
2024-05-28T16:02:52.0146080Z                                at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5
2024-05-28T16:02:52.0183770Z    1:        0x10ac42683 - std::backtrace_rs::backtrace::trace_unsynchronized::h86a1158ecfd606b7
2024-05-28T16:02:52.1108570Z                                at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
2024-05-28T16:02:52.1111840Z    2:        0x10ac42683 - std::sys_common::backtrace::_print_fmt::h0916a318c0fc97ff
2024-05-28T16:02:52.1123610Z                                at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/sys_common/backtrace.rs:68:5
2024-05-28T16:02:52.1125770Z    3:        0x10ac42683 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h9e09877065e04f77
2024-05-28T16:02:52.1127630Z                                at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/sys_common/backtrace.rs:44:22
2024-05-28T16:02:52.1129140Z    4:        0x10ac6adfb - core::fmt::rt::Argument::fmt::h9d2968fcafab28ba
2024-05-28T16:02:52.1130690Z                                at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/fmt/rt.rs:142:9
2024-05-28T16:02:52.1131970Z    5:        0x10ac6adfb - core::fmt::write::ha1eda037e545f7da
2024-05-28T16:02:52.1133140Z                                at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/fmt/mod.rs:1153:17
2024-05-28T16:02:52.1134480Z    6:        0x10ac3f01e - std::io::Write::write_fmt::h982a70ce7879c870
2024-05-28T16:02:52.1135700Z                                at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/io/mod.rs:1843:15
2024-05-28T16:02:52.1137810Z    7:        0x10ac42471 - std::sys_common::backtrace::_print::h0896aee7ef2a1b71
2024-05-28T16:02:52.1142330Z                                at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/sys_common/backtrace.rs:47:5
2024-05-28T16:02:52.1146700Z    8:        0x10ac42471 - std::sys_common::backtrace::print::h614a07b8de11add7
2024-05-28T16:02:52.1148450Z                                at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/sys_common/backtrace.rs:34:9
2024-05-28T16:02:52.1152540Z    9:        0x10ac44099 - std::panicking::default_hook::{{closure}}::h079cbc758586c627
2024-05-28T16:02:52.1154230Z   10:        0x10ac43e00 - std::panicking::default_hook::ha4241b247d28f540
2024-05-28T16:02:52.1157520Z                                at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/panicking.rs:292:9
2024-05-28T16:02:52.1160220Z   11:        0x10ac44ace - std::panicking::rust_panic_with_hook::h610a5d47d992d59c
2024-05-28T16:02:52.1164130Z                                at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/panicking.rs:779:13
2024-05-28T16:02:52.1169300Z   12:        0x10ac443fc - std::panicking::begin_panic_handler::{{closure}}::hb7bd4ff0d901d687
2024-05-28T16:02:52.1170800Z                                at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/panicking.rs:649:13
2024-05-28T16:02:52.1172470Z   13:        0x10ac42b59 - std::sys_common::backtrace::__rust_end_short_backtrace::h08de5c5c123a7cab
2024-05-28T16:02:52.1174400Z                                at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/sys_common/backtrace.rs:171:18
2024-05-28T16:02:52.1188090Z   14:        0x10ac44166 - rust_begin_unwind
2024-05-28T16:02:52.1191450Z                                at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/panicking.rs:645:5
2024-05-28T16:02:52.1197290Z   15:        0x10acd22ca - core::panicking::panic_nounwind_fmt::runtime::h1699604b67582fc1
2024-05-28T16:02:52.1201130Z                                at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/panicking.rs:110:18
2024-05-28T16:02:52.1204230Z   16:        0x10acd22ca - core::panicking::panic_nounwind_fmt::h618084f54c5bb676
2024-05-28T16:02:52.1206520Z                                at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/panicking.rs:123:9
2024-05-28T16:02:52.1209480Z   17:        0x10acd237d - core::panicking::panic_nounwind::hee987b57fea6968f
2024-05-28T16:02:52.1211870Z                                at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/panicking.rs:156:5
2024-05-28T16:02:52.1218230Z   18:        0x109d28b7c - core::slice::raw::from_raw_parts::precondition_check::hf3885a66ab2f9dce
2024-05-28T16:02:52.1220650Z   19:        0x109d28a25 - core::slice::raw::from_raw_parts::h03781f0b8dec303b
2024-05-28T16:02:52.1224260Z   20:        0x109d28c1e - harfbuzz_rs::blob::Blob::get_data::h106431f432abd579
2024-05-28T16:02:52.1226730Z   21:        0x109d28ca9 - <harfbuzz_rs::blob::Blob as core::ops::deref::Deref>::deref::h3f16c8b59c370d39
2024-05-28T16:02:52.1229200Z   22:        0x109d1b6d9 - harfbuzz_rs::face::Face::table_with_tag::h34254aeb4f15041c
2024-05-28T16:02:52.1231290Z   23:        0x109c400de - zng_ext_font::FontFace::load::h38a7d54fed917fa7
2024-05-28T16:02:52.1234750Z   24:        0x109c4fa55 - zng_ext_font::FontFaceLoader::load_resolved::{{closure}}::h7f62966d3867f7f3
2024-05-28T16:02:52.1238310Z   25:        0x109c953a2 - <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::h97ee928bcf329908
2024-05-28T16:02:52.1241110Z   26:        0x109cfa366 - std::panicking::try::do_call::ha675e754786906e3
2024-05-28T16:02:52.1243030Z   27:        0x109d06fbd - ___rust_try
2024-05-28T16:02:52.1244010Z   28:        0x109cf9dad - std::panicking::try::hf2f9c08333660de8
2024-05-28T16:02:52.1245090Z   29:        0x109c96c44 - std::panic::catch_unwind::h05c544093d1408c1
2024-05-28T16:02:52.1246430Z   30:        0x109c68a50 - zng_task::wait_catch::{{closure}}::{{closure}}::{{closure}}::h5bd31dafe43c9dc5
2024-05-28T16:02:52.1247950Z   31:        0x109c5b643 - zng_app_context::LocalContext::with_context::ha71ea7a61c0a01c4
2024-05-28T16:02:52.1249600Z   32:        0x109c68904 - zng_task::wait_catch::{{closure}}::{{closure}}::h3b2e230fc3373bfb
2024-05-28T16:02:52.1251260Z   33:        0x109d0cf15 - blocking::unblock::{{closure}}::hf99b5a66af1c0ae9
2024-05-28T16:02:52.1252760Z   34:        0x109ce5f39 - async_task::raw::RawTask<F,T,S,M>::run::{{closure}}::heabd4ae38a662323
2024-05-28T16:02:52.1254640Z   35:        0x109caaba0 - core::ops::function::FnOnce::call_once::h9c307674d8f3bff5
2024-05-28T16:02:52.1256500Z   36:        0x109c95284 - <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::h06fe33ba1926d36f
2024-05-28T16:02:52.1258200Z   37:        0x109cfa07c - std::panicking::try::do_call::h3f089c1a70b8734b
2024-05-28T16:02:52.1259630Z   38:        0x109d06fbd - ___rust_try
2024-05-28T16:02:52.1262640Z   39:        0x109cf983f - std::panicking::try::h4eb96546ab5cb94c
2024-05-28T16:02:52.1265570Z   40:        0x109c96d24 - std::panic::catch_unwind::he28ad9dd0c277a23
2024-05-28T16:02:52.1270480Z   41:        0x109ce4587 - async_task::raw::RawTask<F,T,S,M>::run::h54f453d7dcecd9d7
2024-05-28T16:02:52.1274810Z   42:        0x10a869390 - async_task::runnable::Runnable<M>::run::h2fca0dffdd7b1c0e
2024-05-28T16:02:52.1293220Z   43:        0x10a86d089 - blocking::Executor::main_loop::{{closure}}::he672358afa5ba5a6
2024-05-28T16:02:52.1295920Z   44:        0x10a86e034 - std::panicking::try::do_call::h95b06deba6bbba91
2024-05-28T16:02:52.1297420Z   45:        0x10a86fd8d - ___rust_try
2024-05-28T16:02:52.1299150Z   46:        0x10a86df73 - std::panicking::try::h1e68b4dff3e91e20
2024-05-28T16:02:52.1307100Z   47:        0x10a8695e4 - std::panic::catch_unwind::h9713b37dca7e78bd
2024-05-28T16:02:52.1309060Z   48:        0x10a86cc1e - blocking::Executor::main_loop::h45d664bcf35571c5
2024-05-28T16:02:52.1311920Z   49:        0x10a86d815 - blocking::Executor::grow_pool::{{closure}}::h12dba949a8a4906d
2024-05-28T16:02:52.1314660Z   50:        0x10a8693d9 - std::sys_common::backtrace::__rust_begin_short_backtrace::had08f22ea5dad5c8
2024-05-28T16:02:52.1317830Z   51:        0x10a86a2f9 - std::thread::Builder::spawn_unchecked_::{{closure}}::{{closure}}::h7ce0e9b4f0d05239
2024-05-28T16:02:52.1321460Z   52:        0x10a86dc2d - <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::h6db912796d757590
2024-05-28T16:02:52.1325660Z   53:        0x10a86e05c - std::panicking::try::do_call::hba6ab743f1d4ea13
2024-05-28T16:02:52.1327810Z   54:        0x10a86fd8d - ___rust_try
2024-05-28T16:02:52.1328810Z   55:        0x10a86dfdb - std::panicking::try::h574794b81b34f015
2024-05-28T16:02:52.1332180Z   56:        0x10a86a1ba - std::thread::Builder::spawn_unchecked_::{{closure}}::h7d3408ab6753b4b9
2024-05-28T16:02:52.1339520Z   57:        0x10a86a70d - core::ops::function::FnOnce::call_once{{vtable.shim}}::hac45c460eb163fa7
2024-05-28T16:02:52.1343540Z   58:        0x10ac4a889 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h9a7a81ddd19c0c7d
2024-05-28T16:02:52.1347410Z                                at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/alloc/src/boxed.rs:2020:9
2024-05-28T16:02:52.1353830Z   59:        0x10ac4a889 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h2e428d79542aac98
2024-05-28T16:02:52.1356000Z                                at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/alloc/src/boxed.rs:2020:9
2024-05-28T16:02:52.1357820Z   60:        0x10ac4a889 - std::sys::pal::unix::thread::Thread::new::thread_start::hfad3fe8a2c338ed5
2024-05-28T16:02:52.1359850Z                                at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/sys/pal/unix/thread.rs:108:17
2024-05-28T16:02:52.1361780Z   61:     0x7ff81b8911d3 - __pthread_start
2024-05-28T16:02:52.1362880Z thread caused non-unwinding panic. aborting.
```

</details>


Discussion / hints:

Fix patch:
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index f1a2b16ec..24469d70e 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -49,7 +49,7 @@ jobs:
       - uses: Swatinem/rust-cache@v2
       - run: cargo check --workspace --examples --tests --release
       - run: cargo clean
-  test:
+  test-ubuntu:
     runs-on: ubuntu-latest
     needs: [check]
     env:
@@ -68,6 +68,48 @@ jobs:
     - uses: Swatinem/rust-cache@v2
     - run: cargo do test --nextest
     - run: cargo clean
+  test-windows:
+    runs-on: windows-latest
+    needs: [check]
+    env:
+      ZNG_TP_LICENSES: true
+      NEXTEST_RETRIES: 3
+      CC: 'clang-cl'
+      CXX: 'clang-cl'
+    steps:
+    - uses: dtolnay/rust-toolchain@stable
+    - name: install cargo-about
+      uses: baptiste0928/cargo-install@v3
+      with:
+        crate: cargo-about
+    - name: install cargo-nextest
+      uses: taiki-e/install-action@v2
+      with:
+        tool: cargo-nextest
+    - uses: actions/checkout@v4
+    - uses: Swatinem/rust-cache@v2
+    - run: cargo do test --nextest
+    - run: cargo clean
+  test-macos:
+    runs-on: macos-latest
+    needs: [check]
+    env:
+      ZNG_TP_LICENSES: true
+      NEXTEST_RETRIES: 3
+    steps:
+    - uses: dtolnay/rust-toolchain@stable
+    - name: install cargo-about
+      uses: baptiste0928/cargo-install@v3
+      with:
+        crate: cargo-about
+    - name: install cargo-nextest
+      uses: taiki-e/install-action@v2
+      with:
+        tool: cargo-nextest
+    - uses: actions/checkout@v4
+    - uses: Swatinem/rust-cache@v2
+    - run: cargo do test --nextest
+    - run: cargo clean
   test-doc:
     runs-on: ubuntu-latest
     needs: [check]
@@ -90,6 +132,6 @@ jobs:
       - run: cargo clean
   test-all:
     runs-on: ubuntu-latest
-    needs: [check-release, doc, test, test-doc, test-macro]
+    needs: [check-release, doc, test-ubuntu, test-windows, test-macos, test-doc, test-macro]
     steps:
       - run: exit 0
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 02d2f49db..d6a3e29a8 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -78,7 +78,7 @@ jobs:
       - run: cargo clean
         if: ${{ github.event.inputs.skip_checks != 'true' }}
   check-macos:
-    runs-on: macos-13
+    runs-on: macos-latest
     steps:
       - uses: actions/checkout@v4
         if: ${{ github.event.inputs.skip_checks != 'true' }}
@@ -225,7 +225,7 @@ jobs:
           name: prebuilt-windows
           path: crates/zng-view-prebuilt/lib/zng_view.dll
   prebuild-macos:
-    runs-on: macos-13
+    runs-on: macos-latest
     needs: [check-macos]
     env:
       ZNG_TP_LICENSES: true
@@ -392,7 +392,7 @@ jobs:
       - run: cargo clean
         if: ${{ github.event.inputs.skip_tests != 'true' }}
   test-macos:
-    runs-on: macos-13
+    runs-on: macos-latest
     needs: [prebuild-macos]
     env:
       NEXTEST_RETRIES: 3
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9fbf93c3b..067193309 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,7 @@
 * Fix `Img::copy_pixels`.
 * Fix `view_process::default::run_same_process` exit in headless runs.
 * Fix `AutoGrowMode::rows` actually enabling Columns auto grow.
+* Fix "unsafe precondition(s) violated" issue ([#242](https://github.com/zng-ui/zng/issues/242)).
 
 # 0.6.1
 
diff --git a/crates/zng-ext-font/src/lib.rs b/crates/zng-ext-font/src/lib.rs
index 03f7d6d22..6be454a5d 100644
--- a/crates/zng-ext-font/src/lib.rs
+++ b/crates/zng-ext-font/src/lib.rs
@@ -1019,7 +1019,7 @@ impl FontFace {
         } else {
             ColorGlyphs::load(&font)?
         };
-        let has_ligatures = face.table_with_tag(b"GSUB").is_some();
+        let has_ligatures = font.load_font_table(GSUB).is_some();
         let lig_carets = if has_ligatures {
             LigatureCaretList::empty()
         } else {
@@ -1094,7 +1094,8 @@ impl FontFace {
         } else {
             ColorGlyphs::load(&font)?
         };
-        let has_ligatures = face.table_with_tag(b"GSUB").is_some();
+
+        let has_ligatures = font.load_font_table(GSUB).is_some();
         let lig_carets = if has_ligatures {
             LigatureCaretList::empty()
         } else {
diff --git a/crates/zng-ext-font/src/ligature_util.rs b/crates/zng-ext-font/src/ligature_util.rs
index 276e3a7a9..dae2df498 100644
--- a/crates/zng-ext-font/src/ligature_util.rs
+++ b/crates/zng-ext-font/src/ligature_util.rs
@@ -12,6 +12,7 @@ use core::cmp;
 use byteorder::{BigEndian, ReadBytesExt};
 use zng_view_api::font::GlyphIndex;
 
+pub const GSUB: u32 = u32::from_be_bytes(*b"GSUB");
 const GDEF: u32 = u32::from_be_bytes(*b"GDEF");
 
 #[derive(Clone)]


Test patch: