Potential fix for code scanning alert no. 36: Multiplication result converted to larger type #5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Potential fix for https://github.com/IntelLabs/HEC-openfhe-development-test/security/code-scanning/36
To fix the overflow issue, we need to ensure the multiplication
gap * iis performed in a type at least as wide assize_t(usually 64 bits), so that any intermediate result reflects the true value, not the overflowed value. This is done by casting eithergaporitosize_t(or another suitably wide type such asuint64_t) before the multiplication. The index is then passed to the vector access as usual.The fix should only update the line where
gap * iis used, i.e., in both lines(*nativeVec)[gap * i] = ...;in theFitToNativeVectorfunction forint64_t(and you may wish to align style with the other overload, if applicable). Only the multiplication should be changed, with as little disruption as possible.No additional headers or imports are needed, as both
std::size_tanduint64_tare available in standard C++.Suggested fixes powered by Copilot Autofix. Review carefully before merging.