mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-02 06:12:41 +01:00
Merge #535's review fixes into feat/e4d-load
Resolved: start_tools() parses the convertmodels flags with from_chars and both commands stop on bad flags; a vehicle's .t3d is refused before it. The reader keeps the streams of this branch and the known sections of #535: an unknown section the model needs is refused as unknown before its codec is looked at, and an unknown optional one in the codec of the streams is passed over even by the tools, which can't keep it unpacked (forward compatibility of the codec flag). An exception in a stream worker (no memory for a declared size) becomes the error of the file instead of std::terminate; NOSONAR on the S2259 false positive there and on the seeded engines of the tests.
This commit is contained in:
+49
-2
@@ -300,6 +300,17 @@ TEST_CASE("e4d: broken files are refused with a reason, and leave the model empt
|
||||
rehash(File);
|
||||
},
|
||||
"don't hold together"},
|
||||
{"a header that claims fewer bytes than itself",
|
||||
[](std::vector<std::byte> &File) { put_at(File, offsetof(e4d::file_header, file_size), std::uint64_t{32}); },
|
||||
"less than its header"},
|
||||
{"a node in the subtree of another node than its parent",
|
||||
[§ion](std::vector<std::byte> &File) {
|
||||
// the body (node 1) reaches over the hose (node 2), whose parent is the root
|
||||
put_at(File, section(e4d::section::nodes).offset + sizeof(e4d::table_header) + sizeof(e4d::node_record) + offsetof(e4d::node_record, subtree_end),
|
||||
std::uint32_t{5});
|
||||
rehash(File);
|
||||
},
|
||||
"lies in the subtree of node 1"},
|
||||
{"a record too short for its table",
|
||||
[§ion](std::vector<std::byte> &File) {
|
||||
put_at(File, section(e4d::section::primitives).offset + 4, std::uint32_t{20});
|
||||
@@ -506,13 +517,49 @@ TEST_CASE("e4d: the streams in the codecs of meshoptimizer, with and without zst
|
||||
CHECK(loaded.nodes.empty());
|
||||
}
|
||||
|
||||
TEST_CASE("e4d: a section the reader doesn't know is passed over unless the tools keep it")
|
||||
{
|
||||
auto const file{sample_file()};
|
||||
e4d::model kept;
|
||||
REQUIRE(e4d::read(file, kept, {true, true}).ok);
|
||||
CHECK(kept.unknown.size() == 1);
|
||||
e4d::model skipped;
|
||||
auto const result{e4d::read(file, skipped, {true, false})};
|
||||
REQUIRE_MESSAGE(result.ok, result.error);
|
||||
CHECK(skipped.unknown.empty());
|
||||
kept.unknown.clear();
|
||||
CHECK(e4d::dump(skipped) == e4d::dump(kept));
|
||||
}
|
||||
|
||||
TEST_CASE("e4d: an unknown section in the codec of the streams doesn't stop the reading, unless the model needs it")
|
||||
{
|
||||
// a later version may put a new optional stream in the codec; this one passes it over, the tools too
|
||||
auto file{sample_file(false)};
|
||||
auto const offset{entry_offset(file, e4d::fourcc("ZZZZ"))};
|
||||
auto entry{get_at<e4d::section_entry>(file, offset)};
|
||||
entry.flags |= e4d::section_flags::meshopt;
|
||||
put_at(file, offset, entry);
|
||||
rehash(file);
|
||||
e4d::model loaded;
|
||||
auto const result{e4d::read(file, loaded, {true, true})};
|
||||
REQUIRE_MESSAGE(result.ok, result.error);
|
||||
CHECK(loaded.unknown.empty());
|
||||
// one the model needs is refused as unknown, not for its codec
|
||||
entry.flags |= e4d::section_flags::required;
|
||||
put_at(file, offset, entry);
|
||||
rehash(file);
|
||||
auto const required{e4d::read(file, loaded, {true, true})};
|
||||
CHECK_FALSE(required.ok);
|
||||
CHECK(required.error.find("doesn't know") != std::string::npos);
|
||||
}
|
||||
|
||||
TEST_CASE("e4d: a file with random bytes changed is read or refused, never more")
|
||||
{
|
||||
// the sample, too small for the codecs, and the grid, in them
|
||||
for (auto const variant : {0, 1, 2}) {
|
||||
auto const compress{variant == 1};
|
||||
auto const good{variant < 2 ? sample_file(compress) : e4d::write(grid_model(), {true, 9, true})};
|
||||
std::mt19937 random{static_cast<unsigned>(7 + variant * 4)};
|
||||
std::mt19937 random{static_cast<unsigned>(7 + variant * 4)}; // NOSONAR: seeded on purpose, the test changes the same bytes every run; nothing secret
|
||||
std::uniform_int_distribution<std::size_t> position{0, good.size() - 1};
|
||||
std::uniform_int_distribution<int> value{0, 255};
|
||||
for (int attempt = 0; attempt < 3000; ++attempt) {
|
||||
@@ -533,7 +580,7 @@ TEST_CASE("e4d: a file with random bytes changed is read or refused, never more"
|
||||
|
||||
TEST_CASE("e4d: the tangent frame survives its packing")
|
||||
{
|
||||
std::mt19937 random{3};
|
||||
std::mt19937 random{3}; // NOSONAR: seeded on purpose, the test packs the same frames every run; nothing secret
|
||||
std::uniform_real_distribution<float> coordinate{-1.f, 1.f};
|
||||
for (int attempt = 0; attempt < 2000; ++attempt) {
|
||||
glm::vec3 normal{coordinate(random), coordinate(random), coordinate(random)};
|
||||
|
||||
Reference in New Issue
Block a user