leerho commented on code in PR #565:
URL: https://github.com/apache/datasketches-cpp/pull/565#discussion_r4541879322


##########
hll/include/CouponHashSet-internal.hpp:
##########
@@ -83,12 +83,20 @@ CouponHashSet<A>* CouponHashSet<A>::newSet(const void* 
bytes, size_t len, const
   if (lgK <= 7) {
     throw std::invalid_argument("Attempt to deserialize invalid CouponHashSet 
with lgConfigK <= 7. Found: "
                                 + std::to_string(lgK));
-  }   
+  }
+  HllUtil<A>::checkLgK(lgK);
   uint8_t lgArrInts = data[hll_constants::LG_ARR_BYTE];
   const bool compactFlag = ((data[hll_constants::FLAGS_BYTE] & 
hll_constants::COMPACT_FLAG_MASK) ? true : false);
 
   uint32_t couponCount;
   std::memcpy(&couponCount, data + hll_constants::HASH_SET_COUNT_INT, 
sizeof(couponCount));
+  const uint32_t maxCouponCount = hll_constants::RESIZE_NUMER * (uint32_t(1) 
<< (lgK - 3))
+      / hll_constants::RESIZE_DENOM;
+  if (compactFlag && couponCount > maxCouponCount) {

Review Comment:
   In a compact image the reader re-inserts each coupon with `couponUpdate()`. 
A count above 3/4·2^(lgK−3) would make the set promote to HLL partway through 
deserialization, and `newSet()` would discard the promoted object. No valid 
writer produces such a count, because a set promotes as soon as it passes that 
limit, so the check only rejects corrupt images. An updatable image is copied 
into the table as a block, so its count can't trigger a promotion during 
deserialization. My review comment asks for hardening on that path.
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to