Skip to content

prevent slice::from_raw_parts from being passed a null pointer#1380

Open
z-erica wants to merge 1 commit into
tectonic-typesetting:masterfrom
z-erica:push-qsrumvxrszzm
Open

prevent slice::from_raw_parts from being passed a null pointer#1380
z-erica wants to merge 1 commit into
tectonic-typesetting:masterfrom
z-erica:push-qsrumvxrszzm

Conversation

@z-erica

@z-erica z-erica commented Jul 10, 2026

Copy link
Copy Markdown

when nfont is zero in a FcFontSet, the fonts field can be a null pointer. this can make the test suite panic:

thread 'trip_test' (7786) panicked at crates/bridge_fontconfig/src/font_set.rs:23:18:
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

This indicates a bug in the program. This Undefined Behavior check is optional, and cannot be relied on for safety.
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
thread caused non-unwinding panic. aborting.

this fix maintains the safety invariant by always returning an empty slice with a lifetime of 'static when the array is empty

when nfont is zero in a FcFontSet, the fonts field can be a null pointer.
this can make the test suite panic:

    thread 'trip_test' (7786) panicked at crates/bridge_fontconfig/src/font_set.rs:23:18:
    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`

    This indicates a bug in the program. This Undefined Behavior check is optional, and cannot be relied on for safety.
    note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
    thread caused non-unwinding panic. aborting.

this fix maintains the safety invariant by always returning an empty
slice with a lifetime of 'static when the array is empty
@z-erica z-erica marked this pull request as ready for review July 10, 2026 17:39
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

Successfully merging this pull request may close these issues.

1 participant