Skip to content

Commit 0fe5aa1

Browse files
committed
Add check for nan in Nurbs. Add check for IfcTokenType::LINE_END in IfcLoader to prevent near infinite loop
1 parent 52901d2 commit 0fe5aa1

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/cpp/web-ifc/geometry/nurbs.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ namespace webifc::geometry{
178178
this->pth = tinynurbs::surfacePoint(*this->nurbs, 1.0, 0.0);
179179
this->ptv = tinynurbs::surfacePoint(*this->nurbs, 0.0, 1.0);
180180

181+
if (std::isnan(pth.x) || std::isnan(pth.y) ||std::isnan(pth.z) ) {
182+
spdlog::error("pth isnan: ({}/{}/{})", pth.x, pth.y, pth.z);
183+
return;
184+
}
185+
181186
// Compute distances for further use.
182187
this->dh = glm::distance(ptc, pth);
183188
this->dv = glm::distance(ptc, ptv);
@@ -313,6 +318,12 @@ namespace webifc::geometry{
313318
double rads = (i / rotations) * pi2;
314319
double incU = glm::sin(rads) / mul_divisor;
315320
double incV = glm::cos(rads) / mul_divisor;
321+
322+
if (std::isnan(pr)) {
323+
spdlog::error("Invalid pr {} ",pr);
324+
break;
325+
}
326+
316327
if (pr > 1) incV *= pr;
317328
else incU /= pr;
318329
while (true)

src/cpp/web-ifc/parsing/IfcLoader.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,11 @@ namespace webifc::parsing {
507507
{
508508
depth--;
509509
}
510+
else if (t == IfcTokenType::LINE_END)
511+
{
512+
spdlog::error("[GetSetArgument[{}]) unexpected LINE_END token", GetCurrentLineExpressID());
513+
break;
514+
}
510515
else
511516
{
512517
tapeOffsets.push_back(offset);
@@ -522,7 +527,7 @@ namespace webifc::parsing {
522527
}
523528
else
524529
{
525-
spdlog::error("[GetSetArgument[]) unexpected token", GetCurrentLineExpressID());
530+
spdlog::error("[GetSetArgument[{}]) unexpected token", GetCurrentLineExpressID());
526531
}
527532
}
528533

0 commit comments

Comments
 (0)