Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove call to mem::uninitialized/zeroed inside vorbis structs #1

Closed
wants to merge 2 commits into from

Conversation

John2143
Copy link

As of the latest rustc 1.48.0, Decoder::<R>::new() panics at runtime with the error

attempted to zero-initialize type `librespot_tremor::tremor_sys::ov_callbacks`, which is invalid

This PR adds a close_func no-op to fill out ov_callbacks and changes DecoderData to use mem::transmute. This needs a review, but it does build and run locally.

fixes spotifyd issue Spotifyd/spotifyd/issues/719

Copy link

@hselasky hselasky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test OK using FreeBSD-12 and rust-1.48.0.

@thotypous
Copy link

Please merge. Very annoying bug. It makes life of people packaging stuff for distros really hard.

Comment on lines +161 to +164
//mem::zeroed not allowed here, so transmute from empty mem.
//UB, but this needs to be initialized from C.
//TODO: switch data to maybe uninit
std::mem::transmute::<[u8; SIZE_OF_VORBIS], OggVorbis_File>([0u8; SIZE_OF_VORBIS])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Make DecoderData #[repr(C)] and define a struct

#[repr(C)]
struct DecoderDataUninit<R> where R: Read + Seek {
    vorbis: MaybeUninit<tremor_sys::OggVorbis_File>,
    reader: R,
    current_logical_bitstream: libc::c_int,
    read_error: Option<io::Error>,
}

After the vorbis field is initialized, it can be transmuted to DecoderData.

@ericonr
Copy link

ericonr commented Jan 28, 2021

Is this PR being made for the correct branch? The tagged release (https://github.com/librespot-org/librespot-tremor/tree/v0.1.0) doesn't belong to any branch in this repository.

@Johannesd3
Copy link

I created another PR (#2) based on this one, which has probably a more sound use of unsafe and also some additional improvements.

@sashahilton00
Copy link
Member

Is this PR being made for the correct branch? The tagged release (https://github.com/librespot-org/librespot-tremor/tree/v0.1.0) doesn't belong to any branch in this repository.

This is the correct branch. I just pushed the commits. I must have somehow uploaded the tags without the commits. Thanks for spotting that.

I created another PR (#2) based on this one, which has probably a more sound use of unsafe and also some additional improvements.

Closing in favour of PR #2

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.

6 participants