Skip to content

DxcBlob::as_slice violates slice::from_raw_parts precondition when IDxcBlob::get_buffer_pointer returns null #85

@zopsicle

Description

@zopsicle

It is not allowed to pass a null pointer to slice::from_raw_parts. An empty blob can be obtained by compiling successfully without warnings, then calling get_error_buffer (useful for obtaining compiler warnings) on the Ok result of DxcCompiler::compile:

let result = dxc_compiler.compile(
    &source_blob,
    source_path.as_ref(),
    entry_point,
    target_profile,
    &args,
    Some(&mut IncludeHandler),
    /* defines */ &[],
);

match result {
    Ok(ok) => {
        let err = ok.get_error_buffer()?;
        //  thread 'main' panicked at library/core/src/panicking.rs:218:5:
        //  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.
        let err = dxc_library.get_blob_as_string(&err.into())?;
        println!("cargo::warning={err}");
        Ok(())
    },
    Err(err) => {
        let err = err.0.get_error_buffer()?;
        let err = dxc_library.get_blob_as_string(&err.into())?;
        Err(HassleError::CompileError(err).into())
    },
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions