servo / font-kit

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

Bail out from rendering when bitmap_buffer is null #197

Closed saethlin closed 1 year ago

saethlin commented 2 years ago

I don't really understand what's going on here. All I really know is that I ran into one of the standard library's debug assertions when running some of the examples in plotters. I trimmed one down, but not a whole lot.

use plotters::prelude::*;
fn main() {
    let mut buffer = vec![0u8; 1024 * 768 * 3];
    let area = BitMapBackend::with_buffer(&mut buffer[..], (1024, 768))
        .into_drawing_area()
        .split_evenly((1, 2));
    let _chart = ChartBuilder::on(&area[0])
        .caption("Incremental Example", ("sans-serif", 20))
        .build_cartesian_2d(0..10, 0..10)
        .expect("Unable to build ChartContext");
}

Running this example without this patch using cargo +nightly run -Zbuild-std --target=x86_64-unknown-linux-gnu will panic:

thread 'main' panicked at '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`', /home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/panicking.rs:126:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread caused non-unwinding panic. aborting.
Aborted (core dumped)

The problem is that the pointer is null.

Manishearth commented 1 year ago

@bors r+

Seems like an okay fix, though I'm not that clear on this codebase

jdm commented 1 year ago

@bors-servo r+

bors-servo commented 1 year ago

:pushpin: Commit 3bb66f3 has been approved by jdm

bors-servo commented 1 year ago

:hourglass: Testing commit 3bb66f3732d662e073062bff7cdcb87863592afb with merge 4811bef626fb80759e2aafe0a021a6cad19bb6fe...

Manishearth commented 1 year ago

Needs a rustfmt run

bors-servo commented 1 year ago

:boom: Test timed out

Manishearth commented 1 year ago

@bors-servo r+

bors-servo commented 1 year ago

:pushpin: Commit 787b68f has been approved by Manishearth

bors-servo commented 1 year ago

:hourglass: Testing commit 787b68f69662e5acca6913db072bcc294c0a1e09 with merge 8a714dd1e29957751595e79d8ae7c61b0171c391...

bors-servo commented 1 year ago

:boom: Test timed out

Manishearth commented 1 year ago

Something wrong with macos builders