Skip to content

Commit 3d78742

Browse files
leerhoclaude
andcommitted
Build against datasketches-cpp 5.3.0
C++ 5.3.0 fixes five deserialization vulnerabilities (CVE-2026-103501, -103513, -103634, -103635, -103636), which this package inherits. Two C++ member functions gained a defaulted parameter, which breaks the bindings that take their address: - update_theta_sketch::compact(ordered, trim): expose trim=False. Without a second nb::arg the build fails. - hll_sketch::reset(full_size): expose full_size=False. Without an nb::arg, reset() required an argument and test_hll_* failed. Also bind the new frequent_items_sketch::reset(). Adds tests for all three. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent f4924f3 commit 3d78742

7 files changed

Lines changed: 25 additions & 5 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ cmake_policy(SET CMP0097 NEW)
117117
include(ExternalProject)
118118
ExternalProject_Add(datasketches
119119
GIT_REPOSITORY https://github.com/apache/datasketches-cpp.git
120-
GIT_TAG 5.2.0
120+
GIT_TAG 5.3.0
121121
GIT_SHALLOW true
122122
GIT_SUBMODULES ""
123123
INSTALL_DIR /tmp/datasketches

‎src/fi_wrapper.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ void bind_fi_sketch(nb::module_ &m, const char* name) {
6262
"Merges the given sketch into this one")
6363
.def("is_empty", &frequent_items_sketch<T, W, H, E>::is_empty,
6464
"Returns True if the sketch is empty, otherwise False")
65+
.def("reset", &frequent_items_sketch<T, W, H, E>::reset,
66+
"Resets the sketch to the initial empty state")
6567
.def_prop_ro("num_active_items", &frequent_items_sketch<T, W, H, E>::get_num_active_items,
6668
"The number of active items in the sketch")
6769
.def_prop_ro("total_weight", &frequent_items_sketch<T, W, H, E>::get_total_weight,

‎src/hll_wrapper.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ void init_hll(nb::module_ &m) {
6565
"Returns the size of the serialized sketch")
6666
.def("get_compact_serialization_bytes", &hll_sketch::get_compact_serialization_bytes,
6767
"Returns the size of the serialized sketch when compressing the exception table if HLL_4")
68-
.def("reset", &hll_sketch::reset,
69-
"Resets the sketch to the empty state in coupon collection mode")
68+
.def("reset", &hll_sketch::reset, nb::arg("full_size")=false,
69+
"Resets the sketch to the empty state, in coupon collection mode or, if full_size is True, as a full-size HLL array")
7070
.def("update", (void (hll_sketch::*)(int64_t)) &hll_sketch::update, nb::arg("datum"),
7171
"Updates the sketch with the given integral value")
7272
.def("update", (void (hll_sketch::*)(double)) &hll_sketch::update, nb::arg("datum"),

‎src/theta_wrapper.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ void init_theta(nb::module_ &m) {
8888
"Updates the sketch with the given floating point value")
8989
.def("update", (void (update_theta_sketch::*)(const std::string&)) &update_theta_sketch::update, nb::arg("datum"),
9090
"Updates the sketch with the given string")
91-
.def("compact", &update_theta_sketch::compact, nb::arg("ordered")=true,
92-
"Returns a compacted form of the sketch, optionally sorting it")
91+
.def("compact", &update_theta_sketch::compact, nb::arg("ordered")=true, nb::arg("trim")=false,
92+
"Returns a compacted form of the sketch, optionally sorting it and trimming it to at most the nominal size k")
9393
.def("trim", &update_theta_sketch::trim, "Removes retained entries in excess of the nominal size k (if any)")
9494
.def("reset", &update_theta_sketch::reset, "Resets the sketch to the initial empty state")
9595
;

‎tests/fi_test.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,5 +148,12 @@ def test_fi_sketch(self):
148148
reference_apriori_error = frequent_strings_sketch.get_apriori_error(k, wt)
149149
self.assertAlmostEqual(sk_apriori_error, reference_apriori_error, delta=1e-6)
150150

151+
fi.update("a", 5)
152+
self.assertFalse(fi.is_empty())
153+
fi.reset()
154+
self.assertTrue(fi.is_empty())
155+
self.assertEqual(fi.total_weight, 0)
156+
self.assertEqual(fi.num_active_items, 0)
157+
151158
if __name__ == '__main__':
152159
unittest.main()

‎tests/hll_test.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ def test_hll_sketch(self):
101101
hll.reset()
102102
self.assertTrue(hll.is_empty())
103103

104+
# reset can also return to an empty full-size HLL array
105+
hll.reset(full_size=True)
106+
self.assertTrue(hll.is_empty())
107+
full = hll_sketch(lgk, tgt_hll_type.HLL_6, True)
108+
self.assertEqual(hll.get_updatable_serialization_bytes(), full.get_updatable_serialization_bytes())
109+
104110
def test_hll_union(self):
105111
lgk = 7
106112
n = 53

‎tests/theta_test.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ def test_theta_basic_example(self):
6868
count = count + 1
6969
self.assertEqual(count, new_sk.num_retained)
7070

71+
# compact can also trim the result to at most k entries
72+
trimmed = sk.compact(trim=True)
73+
self.assertLessEqual(trimmed.num_retained, 1 << lgk)
74+
self.assertLessEqual(trimmed.num_retained, sk.num_retained)
75+
7176
num = sk.num_retained
7277
sk.trim()
7378
self.assertLessEqual(sk.num_retained, num)

0 commit comments

Comments
 (0)