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

Fix Segfault in SlabsPolygonIndex::find #58771

Merged
merged 7 commits into from Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Dictionaries/PolygonDictionaryUtils.cpp
Expand Up @@ -267,7 +267,7 @@ bool SlabsPolygonIndex::find(const Point & point, size_t & id) const
Coord y = point.y();

/** Not in bounding box */
if (x < sorted_x[0] || x > sorted_x.back())
if (x < sorted_x.front() || x > sorted_x.back())
return false;

bool found = false;
Expand Down
2 changes: 2 additions & 0 deletions src/Dictionaries/PolygonDictionaryUtils.h
Expand Up @@ -157,6 +157,8 @@ class DividedCell : public ICell<ReturnCell>
auto y_ratio = y * kSplit;
auto x_bin = static_cast<int>(x_ratio);
auto y_bin = static_cast<int>(y_ratio);
x_bin = x_bin == kSplit ? x_bin - 1 : x_bin; // In case if we have a lot of values and argument is very close to max_x (max_y) so x_ratio (y_ratio) = 1
y_bin = y_bin == kSplit ? y_bin - 1 : y_bin; // => x_bin (y_bin) will be 4, which can lead to wrong vector access
return children[y_bin + x_bin * kSplit]->find(x_ratio - x_bin, y_ratio - y_bin);
}

Expand Down
@@ -0,0 +1 @@
0
10 changes: 10 additions & 0 deletions tests/queries/0_stateless/02960_polygon_bound_bug.sh
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../shell_config.sh
. "$CURDIR"/../shell_config.sh

$CLICKHOUSE_LOCAL -nm -q "CREATE TABLE test_table (geom MultiPolygon) engine=MergeTree ORDER BY geom;
INSERT INTO test_table SELECT * FROM file('$CURDIR/data_parquet/02960_polygon_bound_bug.parquet');
CREATE DICTIONARY test_dict (geom MultiPolygon) PRIMARY KEY geom SOURCE (CLICKHOUSE(TABLE 'test_table')) LIFETIME(MIN 0 MAX 0) LAYOUT(POLYGON(STORE_POLYGON_KEY_COLUMN 1));
SELECT dictHas(test_dict,(174.84729269276494,-36.99524960275426));"
Binary file not shown.