Skip to content

Commit c9c0f56

Browse files
feli-citascommit-bot@chromium.org
authored andcommitted
[dart/vm] Add 'small string' parameter specifier
Rationale: Forces the fuzzer to generate a string literal as the parameter of selected string functions (i.e. padLeft/Right) in order to avoid recursion of the form x = "".padLeft/Right(x). #37573 Change-Id: Icd9f5da07ccdd44e81c88a450c3d2cdd7c8e8f95 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/109893 Commit-Queue: Felicitas Hetzelt <[email protected]> Reviewed-by: Aart Bik <[email protected]>
1 parent eebbed2 commit c9c0f56

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

runtime/tools/dartfuzz/dartfuzz.dart

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import 'dartfuzz_api_table.dart';
1313
// Version of DartFuzz. Increase this each time changes are made
1414
// to preserve the property that a given version of DartFuzz yields
1515
// the same fuzzed program for a deterministic random seed.
16-
const String version = '1.14';
16+
const String version = '1.15';
1717

1818
// Restriction on statements and expressions.
1919
const int stmtLength = 2;
@@ -533,9 +533,9 @@ class DartFuzz {
533533
}
534534
}
535535

536-
void emitString() {
536+
void emitString({int length = 8}) {
537537
emit("'");
538-
for (int i = 0, n = rand.nextInt(8); i < n; i++) {
538+
for (int i = 0, n = rand.nextInt(length); i < n; i++) {
539539
emitChar();
540540
}
541541
emit("'");
@@ -1013,6 +1013,14 @@ class DartFuzz {
10131013
case 'S':
10141014
emitExpr(depth, DartType.STRING);
10151015
break;
1016+
case 's':
1017+
// Emit string literal of 2 characters maximum length
1018+
// for 'small string' parameters to avoid recursively constructed
1019+
// strings which might lead to exponentially growing data structures
1020+
// e.g. loop { var = 'x'.padLeft(8, var); }
1021+
// TODO (felih): detect recursion to eliminate such cases specifically
1022+
emitString(length: 2);
1023+
break;
10161024
case 'L':
10171025
emitExpr(depth, DartType.INT_LIST);
10181026
break;

runtime/tools/dartfuzz/dartfuzz_api_table.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
/// i int (small)
2121
/// D double
2222
/// S String
23+
/// s String (small)
2324
/// L List<int>
2425
/// X Set<int>
2526
/// M Map<int, String>
@@ -773,8 +774,8 @@ class DartLib {
773774
DartLib('trim', 'SV'),
774775
DartLib('trimLeft', 'SV'),
775776
DartLib('trimRight', 'SV'),
776-
DartLib('padLeft', 'SiS'),
777-
DartLib('padRight', 'SiS'),
777+
DartLib('padLeft', 'Sis'),
778+
DartLib('padRight', 'Sis'),
778779
DartLib('replaceRange', 'SIIS'),
779780
DartLib('toLowerCase', 'SV'),
780781
DartLib('toUpperCase', 'SV'),

runtime/tools/dartfuzz/gen_api_table.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ void addToTable(String ret, String name, String proto) {
263263
// for example, to avoid excessive runtime or memory
264264
// allocation in the generated fuzzing program.
265265
if (name == 'padLeft' || name == 'padRight') {
266-
proto = proto.replaceAll('I', 'i');
266+
proto = proto.replaceFirst('IS', 'is');
267267
} else if (name == 'List.filled') {
268268
proto = proto.replaceFirst('I', 'i');
269269
}
@@ -295,6 +295,7 @@ void dumpHeader() {
295295
/// i int (small)
296296
/// D double
297297
/// S String
298+
/// s String (small)
298299
/// L List<int>
299300
/// X Set<int>
300301
/// M Map<int, String>

0 commit comments

Comments
 (0)