-
Notifications
You must be signed in to change notification settings - Fork 786
Memory flattening: Check for overflow #6233
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
Changes from 5 commits
9ee3dbc
2e1bb19
e04b3df
9183ef0
5fc182a
c426eba
ca35896
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2024 WebAssembly Community Group participants | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef wasm_safe_math_h | ||
#define wasm_safe_math_h | ||
|
||
namespace wasm { | ||
|
||
#if !__has_builtin(__builtin_add_overflow) | ||
template<typename T> bool __builtin_add_overflow(T a, T b, T* output) { | ||
// Atm this only supports unsigned types. | ||
static_assert(std::is_unsigned_v<T>); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does this support only unsigned types and what do you mean by LLVM-isms? If LLVM's version supports both, is there a reason why we wouldn't use that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By LLVM-isms I mean the code uses other LLVM headers and various Detecting signed overflow is harder as it can't just be |
||
|
||
T result = a + b; | ||
if (result < a) { | ||
return true; | ||
} | ||
*output = result; | ||
return false; | ||
} | ||
#endif | ||
|
||
} // namespace wasm | ||
|
||
#endif // wasm_safe_math_h |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
;; The data segment here is at an offset too large to fit into the memory due | ||
;; to an overflow. That will cause us to fail during flatten, so there are no | ||
;; changes to output here, but we should not error (if we don't check for | ||
;; overflow, we'd segfault). | ||
|
||
;; RUN: wasm-ctor-eval %s --ctors=test --kept-exports=test --quiet -all | ||
|
||
(module | ||
(memory $0 10 10) | ||
(data $0 (i32.const -1) "a") | ||
|
||
(export "test" (func $test)) | ||
|
||
(func $test | ||
) | ||
) |
Uh oh!
There was an error while loading. Please reload this page.