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

Empty structs cause an infinite loop when reading a Vec #513

Open
AaronAsAChimp opened this issue Dec 8, 2024 · 0 comments
Open

Empty structs cause an infinite loop when reading a Vec #513

AaronAsAChimp opened this issue Dec 8, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@AaronAsAChimp
Copy link

When using read_all or bytes_read with a Vec of empty structs and at least one byte to read, Deku will enter into an infinite loop.

Actual Behavior
The code compiles without issue and the program enters an infinite loop that can only be exited with an force quit.

Example:

use deku::prelude::*;

#[derive(Debug, PartialEq, DekuRead)]
struct EmptyThing {}

#[derive(Debug, PartialEq, DekuRead)]
struct ListOfThings {
    // Either of the following lines cause an infinite loop.

    // #[deku(bytes_read="1")]
    #[deku(read_all)]
    things: Vec<EmptyThing>
}

fn main() {
    let bytes: Vec<u8> = vec![0x00];
    let list_of_things_maybe = ListOfThings::from_bytes((bytes.as_ref(), 0)); 

    if list_of_things_maybe.is_ok() {
        println!("Ok! {:?}", list_of_things_maybe.unwrap());
    } else {
        println!("Not Ok!");
    }
}

Expected Behavior

The ideal solution would be to fail compilation because this is not a valid situation (i.e. you can't read a Vec nothings). It might also make sense to allow compilation and just read an empty Vec.

@sharksforarms sharksforarms added the bug Something isn't working label Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants