Fix buffer overflow error in cel3ds, improve error handling #1145
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I noticed a potential buffer overflow error in the
readString
function in 3dsread.cpp: if the string is 1024 characters or longer, the terminating zero byte is not written and the string constructor fromconst char*
will therefore read beyond the end of the buffer.The rest of the loader functionality was in my opinion far too trusting that the input files are not malformed. I've therefore added various error checking that was missing, including verifying that the stream is in a good state after attempting to read data, and consistency checks that the expected amount of data has been read. I also replaced the void pointer usage with templates to ensure better type safety, and switched to using
std::make_unique
rather thannew
to simplify cleanup on the error path.So far I've checked that the Apollo 11 and Mir models still load.