mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 13:49:16 +00:00
LibJS+AK: Fix integer overflow UB on (any Int32 - -2147483648)
It wasn't safe to use addition_would_overflow(a, -b) to check if subtraction (a - b) would overflow, since it doesn't cover this case. I don't know why we didn't have subtraction_would_overflow(), so this patch adds it. :^)
This commit is contained in:
parent
1de475b404
commit
b2e6843055
Notes:
sideshowbarker
2024-07-17 07:31:31 +09:00
Author: https://github.com/awesomekling
Commit: b2e6843055
Pull-request: https://github.com/SerenityOS/serenity/pull/24354
3 changed files with 27 additions and 1 deletions
|
@ -948,7 +948,7 @@ ThrowCompletionOr<void> Sub::execute_impl(Bytecode::Interpreter& interpreter) co
|
|||
|
||||
if (lhs.is_number() && rhs.is_number()) {
|
||||
if (lhs.is_int32() && rhs.is_int32()) {
|
||||
if (!Checked<i32>::addition_would_overflow(lhs.as_i32(), -rhs.as_i32())) {
|
||||
if (!Checked<i32>::subtraction_would_overflow(lhs.as_i32(), rhs.as_i32())) {
|
||||
interpreter.set(m_dst, Value(lhs.as_i32() - rhs.as_i32()));
|
||||
return {};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue