jpaver / opengametools

A set of open c++ game development tools that are lightweight, easy-to-integrate and free to use. Currently hosting a magicavoxel .vox full scene loader.
MIT License
375 stars 36 forks source link

ogt_vox: segfault when accessing invalid group indices #55

Closed mgerhardy closed 1 year ago

mgerhardy commented 1 year ago
for (uint32_t i = 0; i < scene->num_instances; ++i) {
  ogt_assert(scene->instances[i].group_index == k_invalid_group_index || scene->instances[i].group_index < scene->num_groups, "Invalid group index");
}

I've added this to the end of ogt_vox_read_scene_with_flags for the attached vox file - and it triggers. There is an invalid group index loaded. Maybe we should add some sanity checks to the end of this function to ensure that the client code can be safe in accessing members via index.

vox2obj crashes on that input file, too, Magicavoxel is able to load it

magicavoxel.vox.zip

mgerhardy commented 1 year ago

oh, btw. the segfault happens in ogt_vox_sample_instance_transform for me, because the groups are null

but there are other places like scene->groups[instance.group_index].hidden were the group_index is 0 and the num_groups is 0, too

jpaver commented 1 year ago

Hey @mgerhardy -- I took a look and pushed this PR https://github.com/jpaver/opengametools/pull/56 that fixes this issue. I would appreciate if you could take it for a spin and confirm the issues are fixed for you too. Thanks for the report!