Skip to content

Commit 9ae79e2

Browse files
dcharkescommit-bot@chromium.org
authored andcommitted
[vm/ffi] Make overflow checks consistent - fix asan
Moves a test that tries to allocate a too large amount of memory to a file which is not executed on asan. Fixes: #37388 Change-Id: I91101c05be509b670ff9ba82ee25424554468ec5 Cq-Include-Trybots: luci.dart.try:vm-kernel-asan-linux-release-x64-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107508 Commit-Queue: Daco Harkes <[email protected]> Auto-Submit: Daco Harkes <[email protected]> Reviewed-by: Teagan Strickland <[email protected]>
1 parent 613b645 commit 9ae79e2

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

tests/ffi/data_not_asan_test.dart

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
// BSD-style license that can be found in the LICENSE file.
44
//
55
// Dart test program for testing dart:ffi primitive data pointers.
6-
// This test tries to allocate too much memory on purpose to test the Exception
7-
// thrown on malloc failing.
8-
// This malloc also triggers an asan alarm, so this test is in a separate file
6+
//
7+
// These mallocs trigger an asan alarm, so these tests are in a separate file
98
// which is excluded in asan mode.
109

1110
library FfiTest;
@@ -16,14 +15,22 @@ import "package:expect/expect.dart";
1615

1716
void main() {
1817
testPointerAllocateTooLarge();
18+
testPointerAllocateNegative();
1919
}
2020

21-
/// This test is skipped in asan mode.
2221
void testPointerAllocateTooLarge() {
22+
// Try to allocate something that doesn't fit in 64 bit address space.
2323
int maxInt = 9223372036854775807; // 2^63 - 1
24-
Expect.throws(
25-
() => ffi.allocate<ffi.Int64>(count: maxInt)); // does not fit in range
24+
Expect.throws(() => ffi.allocate<ffi.Int64>(count: maxInt));
25+
26+
// Try to allocate almost the full 64 bit address space.
2627
int maxInt1_8 = 1152921504606846975; // 2^60 -1
27-
Expect.throws(
28-
() => ffi.allocate<ffi.Int64>(count: maxInt1_8)); // not enough memory
28+
Expect.throws(() => ffi.allocate<ffi.Int64>(count: maxInt1_8));
29+
}
30+
31+
void testPointerAllocateNegative() {
32+
// Passing in -1 will be converted into an unsigned integer. So, it will try
33+
// to allocate SIZE_MAX - 1 + 1 bytes. This will fail as it is the max amount
34+
// of addressable memory on the system.
35+
Expect.throws(() => ffi.allocate<ffi.Int8>(count: -1));
2936
}

tests/ffi/data_test.dart

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ void main() {
1515
testPointerFromPointer();
1616
testPointerPointerArithmetic();
1717
testPointerPointerArithmeticSizes();
18-
testPointerAllocateNonPositive();
18+
testPointerAllocateZero();
1919
testPointerCast();
2020
testCastGeneric();
2121
testCastGeneric2();
@@ -92,7 +92,7 @@ void testPointerPointerArithmeticSizes() {
9292
p3.free();
9393
}
9494

95-
void testPointerAllocateNonPositive() {
95+
void testPointerAllocateZero() {
9696
// > If size is 0, either a null pointer or a unique pointer that can be
9797
// > successfully passed to free() shall be returned.
9898
// http://pubs.opengroup.org/onlinepubs/009695399/functions/malloc.html
@@ -108,11 +108,6 @@ void testPointerAllocateNonPositive() {
108108
if (!returnedNullPointer) {
109109
p.free();
110110
}
111-
112-
// Passing in -1 will be converted into an unsigned integer. So, it will try
113-
// to allocate SIZE_MAX - 1 + 1 bytes. This will fail as it is the max amount
114-
// of addressable memory on the system.
115-
Expect.throws(() => ffi.allocate<ffi.Int8>(count: -1));
116111
}
117112

118113
void testPointerCast() {

0 commit comments

Comments
 (0)