Twinklebear / tobj

Tiny OBJ Loader in Rust
MIT License
233 stars 47 forks source link

Fix out of bound error if material name is missing #49

Closed Dyedbyte closed 2 years ago

Dyedbyte commented 2 years ago

When reading material names specified by the usemtl tag, the program may panic due to an out of bound bug if the material name is missing. This PR should fix this error by splitting the line at the first whitespace so that everything after the tag (including whitespace) belongs to the material name.

Minimal reproduction

use tobj::{LoadOptions, load_obj_buf, load_mtl_buf};

fn main() {
    let mut data = "usemtl".as_bytes();
    load_obj_buf(&mut data, &LoadOptions::default(), |_| load_mtl_buf(&mut "".as_bytes()));
}
Twinklebear commented 2 years ago

Thanks @Dyedbyte , this looks good! It looks like the last thing to do before merging this is to run cargo fmt to fix the job: https://github.com/Twinklebear/tobj/runs/5370142090?check_suite_focus=true . The nightly failure will take some other fixes since it looks like some functionality has changed there so that's ok to be failing.

Dyedbyte commented 2 years ago

@Twinklebear I have now run cargo fmt, I hope the formatting looks now as expected.

Twinklebear commented 2 years ago

Looks great, thanks @Dyedbyte !