@@ -359,7 +359,7 @@ auto count_min_sketch<W,A>::deserialize(std::istream& is, uint64_t seed, const A
359359
360360template <typename W, typename A>
361361size_t count_min_sketch<W,A>::get_serialized_size_bytes() const {
362- // The header is always 2 bytes , whether empty or full
362+ // The header is always 2 longs , whether empty or full
363363 size_t preamble_longs = PREAMBLE_LONGS_SHORT ;
364364
365365 // If the sketch is empty, we're done. Otherwise, we need the total weight
@@ -411,6 +411,8 @@ auto count_min_sketch<W,A>::serialize(unsigned header_size_bytes) const -> vecto
411411
412412template <typename W, typename A>
413413auto count_min_sketch<W,A>::deserialize(const void * bytes, size_t size, uint64_t seed, const A& allocator) -> count_min_sketch {
414+ ensure_minimum_memory (size, PREAMBLE_LONGS_SHORT * sizeof (uint64_t ));
415+
414416 const char * ptr = static_cast <const char *>(bytes);
415417
416418 // First 8 bytes are 4 bytes of preamble and 4 unused bytes.
@@ -443,6 +445,8 @@ auto count_min_sketch<W,A>::deserialize(const void* bytes, size_t size, uint64_t
443445 const bool is_empty = (flags_byte & (1 << flags::IS_EMPTY )) > 0 ;
444446 if (is_empty) return c ; // sketch is empty, no need to read further.
445447
448+ ensure_minimum_memory (size, sizeof (W) * (1 + nbuckets * nhashes));
449+
446450 // Long 2 is the weight.
447451 W weight;
448452 ptr += copy_from_mem (ptr, weight) ;
0 commit comments