Validation of constraints `Length` and `CharCount` might panic
Closed this issue · 2 comments
The current implementation of Validate
for the constraints Length
and CharCount
might panic. The limits are of type u32
and to perform the checks the limit values are casted to usize
. If an actual value does not fit into usize it will panic. This might be the case on 16bit or 8bit targets.
A solution will be to change the type of the limit parameters from u32
to usize
. There is one small issue with this solution though. In case of a constraint violations the actual value and the expected value should be converted to Value
. This conversion is needed to include the parameters in the ValidationError
, or more precisly in the InvalidValue
struct.
usize
can not be converted to Value
for values that are greater than i64::max_value()
. To overcome this we can implement TryFrom<usize>
for Value
and include this parameters only if the convertion is successful.
fixed with commit d3feb44