Files
brave-core/patches/base-numerics-checked_math_impl.h.patch
T
cdesouza-chromium 275bd15340 [ubsan][wallet] Fix number overflow in base10 funcs (#25873)
[ubsan] Fix number overflow inside base10 funcs

This PR fixes `int256_t`/`uint256_t` overflow inside `base10` conversion
functions. The checks in place for overflow were not covering the
arithmetic operations correctly. Due to being a large number, this was
also causing a crash on ubsan, which was not producing a report.

This change also does an upstream change to make it possible to use
`base/numerics` for the necessary overflow checks over `int256_t`. A
CL[1] has been submitted upstream, to have this issue correct in
chromium. This is an incidental fix, and large numbers are not supported
by clang's builtins. Nonetheless this upstream change allows us to use
the slower path.

[1] https://crrev.com/c/5914985
2024-10-08 15:48:23 +01:00

14 lines
663 B
Diff

diff --git a/base/numerics/checked_math_impl.h b/base/numerics/checked_math_impl.h
index e619956a16e0b5ed2b1ecadeeb97deb6d4df4b94..027c46ed08fac68e0cf715a172ba736e3bc9101f 100644
--- a/base/numerics/checked_math_impl.h
+++ b/base/numerics/checked_math_impl.h
@@ -189,7 +189,7 @@ struct CheckedMulOp<T, U> {
Promotion presult = {};
bool is_valid = true;
- if (CheckedMulFastOp<Promotion, Promotion>::is_supported) {
+ if constexpr (CheckedMulFastOp<Promotion, Promotion>::is_supported) {
// The fast op may be available with the promoted type.
// The casts here are safe because of the "value in range" conditional
// above.