mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 02:47:36 +00:00
Avoid crashes in string concatenation 32-bit integer overflow test
The test standalone/string_overflow_test.dart is causing crashes and out-of-memory thrashing on some configurations. It was originally a regression test that concatenating a string with 2^31 characters did not overflow a 32-bit signed integer. It was changed to exponentially grow a string until an out-of-memory runtime exception is thrown in Dart. On some VM configurations, this crashes the machine instead. Restoring it to only check concatenating a string of 2^31 bytes. Bug: https://github.com/dart-lang/sdk/issues/46225 Change-Id: Ib50625fe14be2613c907a7bc30cd57766693f6aa Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/332423 Reviewed-by: Martin Kustermann <kustermann@google.com>
This commit is contained in:
parent
3a8d3cdf2f
commit
adc79bc389
|
@ -3,22 +3,22 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// Test to ensure that the VM does not have an integer overflow issue
|
||||
// when concatenating strings.
|
||||
// when concatenating strings and hitting length 2^31.
|
||||
// See https://github.com/dart-lang/sdk/issues/11214
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
main() {
|
||||
const length28bits = 1 << 28;
|
||||
String a = "a";
|
||||
|
||||
var caughtOutOfMemoryException = false;
|
||||
try {
|
||||
while (true) {
|
||||
a = "$a$a$a$a$a$a$a$a";
|
||||
}
|
||||
} on OutOfMemoryError {
|
||||
caughtOutOfMemoryException = true;
|
||||
while (a.length < length28bits) {
|
||||
a = a + a;
|
||||
}
|
||||
Expect.equals(a.length, length28bits);
|
||||
try {
|
||||
final concat = "$a$a$a$a$a$a$a$a";
|
||||
Expect.equals(concat.length, 8 * length28bits);
|
||||
} on OutOfMemoryError {
|
||||
// Allow test to run out of memory instead.
|
||||
}
|
||||
Expect.isTrue(caughtOutOfMemoryException);
|
||||
Expect.isTrue(a.startsWith('aaaaa') && a.length > 1024);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue