Skip to content

Commit

Permalink
sanitize debris and detail levels on parse (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
Baezon authored Aug 26, 2023
1 parent 25c01b0 commit a22f85b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pof/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ urlencoding = "2.1"
gltf-json = "1.0"
base64 = "0.13"
itertools = "0.10.3"
log = "0.4.14"
[[bin]]
name = "pof"
path = "src/main.rs"
Expand Down
25 changes: 21 additions & 4 deletions pof/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use byteorder::{ReadBytesExt, LE};
use core::panic;
use dae_parser as dae;
use glm::Mat4x4;
use log::warn;
use nalgebra_glm as glm;
use std::collections::HashMap;
use std::convert::TryInto;
Expand Down Expand Up @@ -456,16 +457,32 @@ impl<R: Read + Seek> Parser<R> {
}
}

for id in debris_objs {
sub_objects[id].is_debris_model = true;
}
debris_objs.retain(|id| {
if id.0 < sub_objects.len() as u32 {
sub_objects[*id].is_debris_model = true;
true
} else {
warn!("Invalid debris object {} discarded", id.0);
false
}
});

let mut header = header.expect("No header chunk found???");
header.detail_levels.retain(|id| {
if id.0 < sub_objects.len() as u32 {
true
} else {
warn!("Invalid detail level object {} discarded", id.0);
false
}
});

let mut textures = textures.unwrap_or_default();
let untextured_idx = post_parse_fill_untextured_slot(&mut sub_objects, &mut textures);

let mut model = Model {
version: self.version,
header: header.expect("No header chunk found???"),
header,
sub_objects,
textures,
paths: paths.unwrap_or_default(),
Expand Down

0 comments on commit a22f85b

Please sign in to comment.