Don't accept NaN geom sizes.

PiperOrigin-RevId: 542209911
Change-Id: I80f9728e8e624d19783370ba5072f39624c1bbe7
This commit is contained in:
Nimrod Gileadi
2023-06-21 04:01:50 -07:00
committed by Copybara-Service
parent 516c5a8bbe
commit 74747e2ae6
2 changed files with 26 additions and 0 deletions
+5
View File
@@ -1717,6 +1717,11 @@ void mjCGeom::Compile(void) {
size[2] = mjMAX(fabs(aabb[2]), fabs(aabb[5]));
}
for (double s : size) {
if (std::isnan(s)) {
throw mjCError(this, "nan size in geom '%s' (id = %d)", name.c_str(), id);
}
}
// compute aabb
ComputeAABB();
+21
View File
@@ -440,6 +440,27 @@ TEST_F(MjCGeomTest, IgnoreBadGeomOutsideInertiagrouprange) {
mj_deleteModel(m);
}
// ------------- test invalid size values --------------------------------------
TEST_F(MjCGeomTest, NanSize) {
// even if the caller ignores warnings, models shouldn't compile with NaN
// geom sizes
mju_user_warning = nullptr;
static constexpr char xml[] = R"(
<mujoco>
<worldbody>
<body>
<geom type="box" size="1 1 nan" mass="1" />
</body>
</worldbody>
</mujoco>
)";
std::array<char, 1000> error;
mjModel* model = LoadModelFromString(xml, error.data(), error.size());
ASSERT_THAT(model, testing::IsNull());
ASSERT_THAT(error.data(), HasSubstr("nan"));
}
// ------------- test height fields --------------------------------------------
using MjCHFieldTest = MujocoTest;