Merge pull request #58771 from yariks5s/polygon_bug_fix

Fix Segfault in `SlabsPolygonIndex::find`
This commit is contained in:
Yarik Briukhovetskyi 2024-01-16 12:35:04 +01:00 committed by GitHub
commit c9cee8c6cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 1 deletions

View File

@ -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;

View File

@ -157,6 +157,12 @@ public:
auto y_ratio = y * kSplit;
auto x_bin = static_cast<int>(x_ratio);
auto y_bin = static_cast<int>(y_ratio);
/// 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.
if (x_bin == kSplit)
--x_bin;
/// => x_bin (y_bin) will be 4, which can lead to wrong vector access.
if (y_bin == kSplit)
--y_bin;
return children[y_bin + x_bin * kSplit]->find(x_ratio - x_bin, y_ratio - y_bin);
}

View File

@ -0,0 +1 @@
0

View File

@ -0,0 +1,11 @@
#!/usr/bin/env bash
# Tags: no-fasttest
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', 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));"