Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GeographicBoundingBox::intersects(): avoid infinite recursion and stack overflow on invalid bounding boxes #3918

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/iso19111/metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,13 @@ bool GeographicBoundingBox::Private::intersects(const Private &other) const {
return false;
}

// Bail out on longitudes not in [-180,180]. We could probably make
// some sense of them, but this check at least avoid potential infinite
// recursion.
if (oW > 180 || oE < -180) {
return false;
}

return intersects(Private(oW, oS, 180.0, oN)) ||
intersects(Private(-180.0, oS, oE, oN));

Expand Down
5 changes: 5 additions & 0 deletions test/unit/test_metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,15 +308,20 @@ TEST(metadata, extent_edge_cases) {
InvalidValueTypeException);

// Scenario of https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=57328
// and https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=60084
{
auto A = Extent::createFromBBOX(0, 1, 2, 3);
auto B = Extent::createFromBBOX(200, -80, -100, 80);
EXPECT_FALSE(A->intersects(B));
EXPECT_FALSE(B->intersects(A));
EXPECT_TRUE(A->intersection(B) == nullptr);
EXPECT_TRUE(B->intersection(A) == nullptr);
}
{
auto A = Extent::createFromBBOX(0, 1, 2, 3);
auto B = Extent::createFromBBOX(100, -80, -200, 80);
EXPECT_FALSE(A->intersects(B));
EXPECT_FALSE(B->intersects(A));
EXPECT_TRUE(A->intersection(B) == nullptr);
EXPECT_TRUE(B->intersection(A) == nullptr);
}
Expand Down