Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation of constraints Length and CharCount might panic #4

Closed
haraldmaida opened this issue Sep 6, 2019 · 2 comments
Closed

Validation of constraints Length and CharCount might panic #4

haraldmaida opened this issue Sep 6, 2019 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@haraldmaida
Copy link
Member

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.

@haraldmaida haraldmaida added the bug Something isn't working label Sep 6, 2019
@haraldmaida haraldmaida self-assigned this Sep 6, 2019
@haraldmaida
Copy link
Member Author

haraldmaida commented Sep 6, 2019

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.

@haraldmaida
Copy link
Member Author

fixed with commit d3feb44

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant