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

Crash on mem::zeroed #77

Open
bshubenok-sigma opened this issue Nov 2, 2023 · 3 comments
Open

Crash on mem::zeroed #77

bshubenok-sigma opened this issue Nov 2, 2023 · 3 comments

Comments

@bshubenok-sigma
Copy link

I'm trying to run a stream capture example on arm64 device and getting this type of error:

The application panicked (crashed).
Message:  attempted to zero-initialize type `buffer::Metadata`, which is invalid
Location: library/core/src/panicking.rs:126

  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
                                ⋮ 7 frames hidden ⋮
   8: core::panicking::panic_nounwind_fmt::hef625da4d1887edc
      at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/panicking.rs:96
   9: core::panicking::panic_nounwind::h39541cbd5a72f09a
      at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/panicking.rs:126
  10: core::mem::zeroed::hffae7c8a55c7cecb
      at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/mem/mod.rs:653
  11: v4l::io::mmap::stream::Stream::with_buffers::h57158218617a1fba
      at /home/noah/.cargo/git/checkouts/libv4l-rs-917e1f4ffd90b94a/9844291/src/io/mmap/stream.rs:55
  12: lib::mediaengine::MediaEngine::process_video::{{closure}}::h36fd47a510f39921

As if it is enclosed in unsafe this may be somehow expected, I guess, but how could I overcome this?
Or is this me lacking some compiler settings?

@MarijnS95
Copy link
Collaborator

Hmm that looks to have been a bad change in 384e7fb, this struct isn't marked as repr(C) either.

If you look at enum Memory for example 0 isn't a valid bit-pattern, only values 1-4 are valid (anything else is UB):

libv4l-rs/src/memory.rs

Lines 12 to 19 in 9844291

#[repr(u32)]
#[derive(Debug, Clone, Copy)]
pub enum Memory {
Mmap = 1,
UserPtr = 2,
Overlay = 3,
DmaBuf = 4,
}

@raymanfx is it okay if I replace these with default() once again?

@MarijnS95
Copy link
Collaborator

Hmm it looks like the conversion from v4l2_buffer -> Metadata -> v4l2_buffer is also lossy.

@MarijnS95
Copy link
Collaborator

MarijnS95 commented Nov 2, 2023

For this specific case in mmap/stream.rs, I'm thinking of either wrapping it in MaybeUninit with // SAFETY docs about self.arena_index being valid, or wrapping it in an Option with an unwrap().

EDIT: Since there are user APIs passing arbitrary indices around, I'm leaning towards Option for additional validation.

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

No branches or pull requests

2 participants