Merge INT_MAX % -1 patch to pdfium Upstream patch at https://crrev.com/772741 Bug: chromium:1086092 Change-Id: Idf9bd87bd833593a48ad4467c347e6623b2f9bb5 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/70131 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/third_party/base/numerics/checked_math_impl.h b/third_party/base/numerics/checked_math_impl.h index 4d1d80d..3227817 100644 --- a/third_party/base/numerics/checked_math_impl.h +++ b/third_party/base/numerics/checked_math_impl.h
@@ -252,13 +252,23 @@ using result_type = typename MaxExponentPromotion<T, U>::type; template <typename V> static constexpr bool Do(T x, U y, V* result) { + if (BASE_NUMERICS_UNLIKELY(!y)) + return false; + using Promotion = typename BigEnoughPromotion<T, U>::type; - if (BASE_NUMERICS_LIKELY(y)) { - Promotion presult = static_cast<Promotion>(x) % static_cast<Promotion>(y); - *result = static_cast<Promotion>(presult); - return IsValueInRangeForNumericType<V>(presult); + if (BASE_NUMERICS_UNLIKELY( + (std::is_signed<T>::value && std::is_signed<U>::value && + IsTypeInRangeForNumericType<T, Promotion>::value && + static_cast<Promotion>(x) == + std::numeric_limits<Promotion>::lowest() && + y == static_cast<U>(-1)))) { + *result = 0; + return true; } - return false; + + Promotion presult = static_cast<Promotion>(x) % static_cast<Promotion>(y); + *result = static_cast<Promotion>(presult); + return IsValueInRangeForNumericType<V>(presult); } };