ddiakopoulos / tinyply

:earth_africa: C++11 ply 3d mesh format importer & exporter
598 stars 118 forks source link

Reading file causes heap corruption #47

Open HiImJulien opened 3 years ago

HiImJulien commented 3 years ago

Hey there! Lately I am fighting with heap corruptions, that are caused by the custom deleter used by the class Buffer. This bug probably related to #3 and #46.

The file I tried to parse, uses tri- and quadfaces; while latter were unwanted it causes your parser to exhibit following behavior:

Reading the lists with a size hint

const auto index_buffer = ply.request_properties_from_element("face", {"vertex_indices"}, 3);

causes a Heap corruption, when cleaning up the buffer.

Omitting the list_size_hint yields the exception, that "Variable length lists are not supported." as probably expected.

ddiakopoulos commented 3 years ago

3 is accurate. #46 I resolved with the issue's author on email somewhat (NaN's in ascii are not supported but I don't document that anywhere). I'm not sure I'll address this particular issue as a hotfix to version 2.3. Version 2.4 is on a branch and supports variable length lists correctly.

The specific bug you're running into with the heap corruption is that I never verify that the list size matches the hint in the inner loop and then throw a similar exception. I might have had it at one point and removed for better performance.