Skip to content

fix: Exclude BLOCK_MAXSIZE and OBJECT_MAXSIZE from bounds checking #1842

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

Merged
merged 2 commits into from
May 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions std/assembly/rt/tcms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function initLazy(space: Object): Object {
// @ts-ignore: decorator
@global @unsafe
export function __new(size: usize, id: i32): usize {
if (size >= OBJECT_MAXSIZE) throw new Error(E_ALLOCATION_TOO_LARGE);
if (size > OBJECT_MAXSIZE) throw new Error(E_ALLOCATION_TOO_LARGE);
var obj = changetype<Object>(__alloc(OBJECT_OVERHEAD + size) - BLOCK_OVERHEAD);
obj.rtId = id;
obj.rtSize = <u32>size;
Expand All @@ -140,7 +140,7 @@ export function __renew(oldPtr: usize, size: usize): usize {
memory.copy(newPtr, oldPtr, min(size, oldObj.rtSize));
return newPtr;
}
if (size >= OBJECT_MAXSIZE) throw new Error(E_ALLOCATION_TOO_LARGE);
if (size > OBJECT_MAXSIZE) throw new Error(E_ALLOCATION_TOO_LARGE);
total -= oldObj.size;
var newPtr = __realloc(oldPtr - OBJECT_OVERHEAD, OBJECT_OVERHEAD + size) + OBJECT_OVERHEAD;
var newObj = changetype<Object>(newPtr - TOTAL_OVERHEAD);
Expand Down
2 changes: 1 addition & 1 deletion std/assembly/rt/tlsf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ function computeSize(size: usize): usize {

/** Prepares and checks an allocation size. */
function prepareSize(size: usize): usize {
if (size >= BLOCK_MAXSIZE) throw new Error(E_ALLOCATION_TOO_LARGE);
if (size > BLOCK_MAXSIZE) throw new Error(E_ALLOCATION_TOO_LARGE);
return computeSize(size);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/compiler/call-super.optimized.wat
Original file line number Diff line number Diff line change
Expand Up @@ -1244,12 +1244,12 @@
(local $4 i32)
local.get $1
i32.const 1073741820
i32.ge_u
i32.gt_u
if
i32.const 1104
i32.const 1440
i32.const 458
i32.const 30
i32.const 29
call $~lib/builtins/abort
unreachable
end
Expand Down
4 changes: 2 additions & 2 deletions tests/compiler/call-super.untouched.wat
Original file line number Diff line number Diff line change
Expand Up @@ -1590,12 +1590,12 @@
(func $~lib/rt/tlsf/prepareSize (param $0 i32) (result i32)
local.get $0
i32.const 1073741820
i32.ge_u
i32.gt_u
if
i32.const 80
i32.const 416
i32.const 458
i32.const 30
i32.const 29
call $~lib/builtins/abort
unreachable
end
Expand Down
4 changes: 2 additions & 2 deletions tests/compiler/class-implements.untouched.wat
Original file line number Diff line number Diff line change
Expand Up @@ -1600,12 +1600,12 @@
(func $~lib/rt/tlsf/prepareSize (param $0 i32) (result i32)
local.get $0
i32.const 1073741820
i32.ge_u
i32.gt_u
if
i32.const 32
i32.const 368
i32.const 458
i32.const 30
i32.const 29
call $~lib/builtins/abort
unreachable
end
Expand Down
4 changes: 2 additions & 2 deletions tests/compiler/class-overloading.untouched.wat
Original file line number Diff line number Diff line change
Expand Up @@ -1606,12 +1606,12 @@
(func $~lib/rt/tlsf/prepareSize (param $0 i32) (result i32)
local.get $0
i32.const 1073741820
i32.ge_u
i32.gt_u
if
i32.const 64
i32.const 400
i32.const 458
i32.const 30
i32.const 29
call $~lib/builtins/abort
unreachable
end
Expand Down
4 changes: 2 additions & 2 deletions tests/compiler/class.optimized.wat
Original file line number Diff line number Diff line change
Expand Up @@ -1251,12 +1251,12 @@
(local $4 i32)
local.get $1
i32.const 1073741820
i32.ge_u
i32.gt_u
if
i32.const 1056
i32.const 1392
i32.const 458
i32.const 30
i32.const 29
call $~lib/builtins/abort
unreachable
end
Expand Down
4 changes: 2 additions & 2 deletions tests/compiler/class.untouched.wat
Original file line number Diff line number Diff line change
Expand Up @@ -1702,12 +1702,12 @@
(func $~lib/rt/tlsf/prepareSize (param $0 i32) (result i32)
local.get $0
i32.const 1073741820
i32.ge_u
i32.gt_u
if
i32.const 32
i32.const 368
i32.const 458
i32.const 30
i32.const 29
call $~lib/builtins/abort
unreachable
end
Expand Down
4 changes: 2 additions & 2 deletions tests/compiler/constructor.optimized.wat
Original file line number Diff line number Diff line change
Expand Up @@ -1312,12 +1312,12 @@
(local $4 i32)
local.get $1
i32.const 1073741820
i32.ge_u
i32.gt_u
if
i32.const 1056
i32.const 1392
i32.const 458
i32.const 30
i32.const 29
call $~lib/builtins/abort
unreachable
end
Expand Down
4 changes: 2 additions & 2 deletions tests/compiler/constructor.untouched.wat
Original file line number Diff line number Diff line change
Expand Up @@ -1600,12 +1600,12 @@
(func $~lib/rt/tlsf/prepareSize (param $0 i32) (result i32)
local.get $0
i32.const 1073741820
i32.ge_u
i32.gt_u
if
i32.const 32
i32.const 368
i32.const 458
i32.const 30
i32.const 29
call $~lib/builtins/abort
unreachable
end
Expand Down
4 changes: 2 additions & 2 deletions tests/compiler/do.untouched.wat
Original file line number Diff line number Diff line change
Expand Up @@ -2003,12 +2003,12 @@
(func $~lib/rt/tlsf/prepareSize (param $0 i32) (result i32)
local.get $0
i32.const 1073741820
i32.ge_u
i32.gt_u
if
i32.const 64
i32.const 400
i32.const 458
i32.const 30
i32.const 29
call $~lib/builtins/abort
unreachable
end
Expand Down
4 changes: 2 additions & 2 deletions tests/compiler/empty-exportruntime.optimized.wat
Original file line number Diff line number Diff line change
Expand Up @@ -1262,12 +1262,12 @@
(local $4 i32)
local.get $1
i32.const 1073741820
i32.ge_u
i32.gt_u
if
i32.const 1056
i32.const 1392
i32.const 458
i32.const 30
i32.const 29
call $~lib/builtins/abort
unreachable
end
Expand Down
4 changes: 2 additions & 2 deletions tests/compiler/empty-exportruntime.untouched.wat
Original file line number Diff line number Diff line change
Expand Up @@ -1596,12 +1596,12 @@
(func $~lib/rt/tlsf/prepareSize (param $0 i32) (result i32)
local.get $0
i32.const 1073741820
i32.ge_u
i32.gt_u
if
i32.const 32
i32.const 368
i32.const 458
i32.const 30
i32.const 29
call $~lib/builtins/abort
unreachable
end
Expand Down
4 changes: 2 additions & 2 deletions tests/compiler/empty-new.untouched.wat
Original file line number Diff line number Diff line change
Expand Up @@ -1589,12 +1589,12 @@
(func $~lib/rt/tlsf/prepareSize (param $0 i32) (result i32)
local.get $0
i32.const 1073741820
i32.ge_u
i32.gt_u
if
i32.const 32
i32.const 368
i32.const 458
i32.const 30
i32.const 29
call $~lib/builtins/abort
unreachable
end
Expand Down
4 changes: 2 additions & 2 deletions tests/compiler/exports.untouched.wat
Original file line number Diff line number Diff line change
Expand Up @@ -1653,12 +1653,12 @@
(func $~lib/rt/tlsf/prepareSize (param $0 i32) (result i32)
local.get $0
i32.const 1073741820
i32.ge_u
i32.gt_u
if
i32.const 32
i32.const 368
i32.const 458
i32.const 30
i32.const 29
call $~lib/builtins/abort
unreachable
end
Expand Down
4 changes: 2 additions & 2 deletions tests/compiler/exportstar-rereexport.untouched.wat
Original file line number Diff line number Diff line change
Expand Up @@ -1634,12 +1634,12 @@
(func $~lib/rt/tlsf/prepareSize (param $0 i32) (result i32)
local.get $0
i32.const 1073741820
i32.ge_u
i32.gt_u
if
i32.const 80
i32.const 416
i32.const 458
i32.const 30
i32.const 29
call $~lib/builtins/abort
unreachable
end
Expand Down
4 changes: 2 additions & 2 deletions tests/compiler/extends-baseaggregate.optimized.wat
Original file line number Diff line number Diff line change
Expand Up @@ -1258,12 +1258,12 @@
(local $4 i32)
local.get $1
i32.const 1073741820
i32.ge_u
i32.gt_u
if
i32.const 1216
i32.const 1552
i32.const 458
i32.const 30
i32.const 29
call $~lib/builtins/abort
unreachable
end
Expand Down
4 changes: 2 additions & 2 deletions tests/compiler/extends-baseaggregate.untouched.wat
Original file line number Diff line number Diff line change
Expand Up @@ -1598,12 +1598,12 @@
(func $~lib/rt/tlsf/prepareSize (param $0 i32) (result i32)
local.get $0
i32.const 1073741820
i32.ge_u
i32.gt_u
if
i32.const 192
i32.const 528
i32.const 458
i32.const 30
i32.const 29
call $~lib/builtins/abort
unreachable
end
Expand Down
4 changes: 2 additions & 2 deletions tests/compiler/extends-recursive.untouched.wat
Original file line number Diff line number Diff line change
Expand Up @@ -1594,12 +1594,12 @@
(func $~lib/rt/tlsf/prepareSize (param $0 i32) (result i32)
local.get $0
i32.const 1073741820
i32.ge_u
i32.gt_u
if
i32.const 32
i32.const 368
i32.const 458
i32.const 30
i32.const 29
call $~lib/builtins/abort
unreachable
end
Expand Down
4 changes: 2 additions & 2 deletions tests/compiler/features/simd.optimized.wat
Original file line number Diff line number Diff line change
Expand Up @@ -747,12 +747,12 @@
(local $4 i32)
local.get $1
i32.const 1073741820
i32.ge_u
i32.gt_u
if
i32.const 1120
i32.const 1056
i32.const 458
i32.const 30
i32.const 29
call $~lib/builtins/abort
unreachable
end
Expand Down
4 changes: 2 additions & 2 deletions tests/compiler/features/simd.untouched.wat
Original file line number Diff line number Diff line change
Expand Up @@ -928,12 +928,12 @@
(func $~lib/rt/tlsf/prepareSize (param $0 i32) (result i32)
local.get $0
i32.const 1073741820
i32.ge_u
i32.gt_u
if
i32.const 96
i32.const 32
i32.const 458
i32.const 30
i32.const 29
call $~lib/builtins/abort
unreachable
end
Expand Down
4 changes: 2 additions & 2 deletions tests/compiler/field-initialization.optimized.wat
Original file line number Diff line number Diff line change
Expand Up @@ -1264,12 +1264,12 @@
(local $4 i32)
local.get $1
i32.const 1073741820
i32.ge_u
i32.gt_u
if
i32.const 1056
i32.const 1392
i32.const 458
i32.const 30
i32.const 29
call $~lib/builtins/abort
unreachable
end
Expand Down
4 changes: 2 additions & 2 deletions tests/compiler/field-initialization.untouched.wat
Original file line number Diff line number Diff line change
Expand Up @@ -1598,12 +1598,12 @@
(func $~lib/rt/tlsf/prepareSize (param $0 i32) (result i32)
local.get $0
i32.const 1073741820
i32.ge_u
i32.gt_u
if
i32.const 32
i32.const 368
i32.const 458
i32.const 30
i32.const 29
call $~lib/builtins/abort
unreachable
end
Expand Down
4 changes: 2 additions & 2 deletions tests/compiler/for.untouched.wat
Original file line number Diff line number Diff line change
Expand Up @@ -2016,12 +2016,12 @@
(func $~lib/rt/tlsf/prepareSize (param $0 i32) (result i32)
local.get $0
i32.const 1073741820
i32.ge_u
i32.gt_u
if
i32.const 64
i32.const 400
i32.const 458
i32.const 30
i32.const 29
call $~lib/builtins/abort
unreachable
end
Expand Down
4 changes: 2 additions & 2 deletions tests/compiler/function-call.untouched.wat
Original file line number Diff line number Diff line change
Expand Up @@ -1625,12 +1625,12 @@
(func $~lib/rt/tlsf/prepareSize (param $0 i32) (result i32)
local.get $0
i32.const 1073741820
i32.ge_u
i32.gt_u
if
i32.const 256
i32.const 592
i32.const 458
i32.const 30
i32.const 29
call $~lib/builtins/abort
unreachable
end
Expand Down
4 changes: 2 additions & 2 deletions tests/compiler/function-expression.untouched.wat
Original file line number Diff line number Diff line change
Expand Up @@ -1781,12 +1781,12 @@
(func $~lib/rt/tlsf/prepareSize (param $0 i32) (result i32)
local.get $0
i32.const 1073741820
i32.ge_u
i32.gt_u
if
i32.const 576
i32.const 912
i32.const 458
i32.const 30
i32.const 29
call $~lib/builtins/abort
unreachable
end
Expand Down
Loading