This is an automated email from the ASF dual-hosted git repository.
twice pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks.git
The following commit(s) were added to refs/heads/unstable by this push:
new 94e4c8ef7 fix(geo): use strict weak ordering in sortGeoPointDESC
comparator (#3439)
94e4c8ef7 is described below
commit 94e4c8ef7e6bb5a98d892a05c4cbc6280c15f280
Author: Songqing Zhang <[email protected]>
AuthorDate: Fri Apr 10 22:35:19 2026 +0800
fix(geo): use strict weak ordering in sortGeoPointDESC comparator (#3439)
The GEO sort DESC comparator used >= instead of >, violating the strict
weak
ordering requirement of std::sort and causing undefined behavior when
elements have equal distances.
---
src/types/redis_geo.cc | 2 +-
tests/gocase/unit/geo/geo_test.go | 13 +++++++++++++
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/src/types/redis_geo.cc b/src/types/redis_geo.cc
index c38824724..e9294081c 100644
--- a/src/types/redis_geo.cc
+++ b/src/types/redis_geo.cc
@@ -421,6 +421,6 @@ bool Geo::appendIfWithinShape(std::vector<GeoPoint>
*geo_points, const GeoShape
bool Geo::sortGeoPointASC(const GeoPoint &gp1, const GeoPoint &gp2) { return
gp1.dist < gp2.dist; }
-bool Geo::sortGeoPointDESC(const GeoPoint &gp1, const GeoPoint &gp2) { return
gp1.dist >= gp2.dist; }
+bool Geo::sortGeoPointDESC(const GeoPoint &gp1, const GeoPoint &gp2) { return
gp1.dist > gp2.dist; }
} // namespace redis
diff --git a/tests/gocase/unit/geo/geo_test.go
b/tests/gocase/unit/geo/geo_test.go
index bca5a7cde..d3d8f0b1b 100644
--- a/tests/gocase/unit/geo/geo_test.go
+++ b/tests/gocase/unit/geo/geo_test.go
@@ -562,4 +562,17 @@ var testGeo = func(t *testing.T, configs
util.KvrocksServerConfigs) {
rdb.GeoRadiusStore(ctx, "points", 13.361389, 38.115556,
&redis.GeoRadiusQuery{Radius: 500, Unit: "km", Store: "points2"})
require.EqualValues(t, rdb.ZRange(ctx, "points", 0, -1).Val(),
rdb.ZRange(ctx, "points2", 0, -1).Val())
})
+
+ t.Run("GEORADIUS DESC with equal distances should not crash", func(t
*testing.T) {
+ require.NoError(t, rdb.Del(ctx, "geokey").Err())
+ require.NoError(t, rdb.GeoAdd(ctx, "geokey",
+ &redis.GeoLocation{Name: "A", Longitude: 13.361389,
Latitude: 38.115556},
+ &redis.GeoLocation{Name: "B", Longitude: 13.361389,
Latitude: 38.115556},
+ &redis.GeoLocation{Name: "C", Longitude: 13.361389,
Latitude: 38.115556},
+ &redis.GeoLocation{Name: "D", Longitude: 15.087269,
Latitude: 37.502669},
+ ).Err())
+ results := rdb.GeoRadius(ctx, "geokey", 13.361389, 38.115556,
+ &redis.GeoRadiusQuery{Radius: 500, Unit: "km", Sort:
"DESC"}).Val()
+ require.Len(t, results, 4)
+ })
}