This is an automated email from the ASF dual-hosted git repository. leerho pushed a commit to branch 5.3.x in repository https://gitbox.apache.org/repos/asf/datasketches-cpp.git
commit b31531b7ddbcb6e97df049e6efe971c186d4673b Author: Lee Rhodes <[email protected]> AuthorDate: Fri Oct 30 13:51:04 2026 -0700 Quantiles: check the input size before the serial version 1 field The bytes overload of deserialize() read the unused 8-byte field of serial version 1 images without checking that the input holds it. Co-Authored-By: Claude Opus 5.5 <[email protected]> --- quantiles/include/quantiles_sketch_impl.hpp | 1 + quantiles/test/quantiles_sketch_test.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/quantiles/include/quantiles_sketch_impl.hpp b/quantiles/include/quantiles_sketch_impl.hpp index 2dacf21e..a3466f3a 100644 --- a/quantiles/include/quantiles_sketch_impl.hpp +++ b/quantiles/include/quantiles_sketch_impl.hpp @@ -531,6 +531,7 @@ auto quantiles_sketch<T, C, A>::deserialize(const void* bytes, size_t size, cons if (serial_version == 1) { uint64_t unused_long; + ensure_minimum_memory(end_ptr - ptr, sizeof(unused_long)); ptr += copy_from_mem(ptr, unused_long); // no longer used } diff --git a/quantiles/test/quantiles_sketch_test.cpp b/quantiles/test/quantiles_sketch_test.cpp index 8230f6a1..0a23a7c7 100644 --- a/quantiles/test/quantiles_sketch_test.cpp +++ b/quantiles/test/quantiles_sketch_test.cpp @@ -956,4 +956,17 @@ TEST_CASE("quantiles sketch", "[quantiles_sketch]") { } } + +TEST_CASE("quantiles sketch: deserialize serial version 1 truncated after min and max", "[quantiles_sketch]") { + quantiles_sketch<int> sketch(16); + for (int i = 0; i < 1000; ++i) sketch.update(i); + auto bytes = sketch.serialize(); + // serial version 1 has an unused 8-byte field after min and max + bytes[0] = 5; // preamble longs + bytes[1] = 1; // serial version + bytes[3] &= ~(1 << 3); // not compact + bytes.resize(8 + sizeof(uint64_t) + 2 * sizeof(int)); // preamble, n, min and max + REQUIRE_THROWS_AS(quantiles_sketch<int>::deserialize(bytes.data(), bytes.size()), std::out_of_range); +} + } /* namespace datasketches */ --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
