tcbrindle / flux

A C++20 library for sequence-orientated programming
https://tristanbrindle.com/flux/
Boost Software License 1.0
484 stars 29 forks source link

cartesian_product size() can overflow #167

Closed tcbrindle closed 8 months ago

tcbrindle commented 8 months ago

As noted when @isaacy2012 was adding cartesian_power, the current implementation of size() for cartesian_product[_map] uses built-in multiplication in a fold expression, and could easily overflow:

https://github.com/tcbrindle/flux/blob/85b016eee0893b4971faaa3dbb415d308212a276/include/flux/op/cartesian_base.hpp#L219-L227

It should use num::checked_mul() instead to guard against UB.