857fca710f
The dill file has an index at the end. The last 4 bytes of that index is a size that indicates how big the file is. This is done to support concatenated dill files. If the dill is invalid and the size is read as 0 both the VM and the dart kernel reader will go into an infinite loop where it allocates another list entry on every loop iteration (making the whole loop not infinate because we will run out of ram soon enough). This CL fixes the issue by checking the size to be possitive. Change-Id: I42da0557c6d4a274fdbe1a729fdaf5b8f149b187 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/148538 Reviewed-by: Johnni Winther <johnniwinther@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com> Commit-Queue: Jens Johansen <jensj@google.com>
30 lines
990 B
Dart
30 lines
990 B
Dart
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
import 'package:kernel/binary/ast_from_binary.dart' show ParseError;
|
|
|
|
import 'utils.dart';
|
|
|
|
main() {
|
|
Library lib1 = new Library(Uri.parse("foo://bar.dart"));
|
|
Component c1 = new Component(libraries: [lib1]);
|
|
List<int> serialized = serializeComponent(c1);
|
|
// The last 4 bytes is the size entry in the index. Overwrite that with 0's.
|
|
for (int i = serialized.length - 4; i < serialized.length; i++) {
|
|
serialized[i] = 0;
|
|
}
|
|
bool gotExpectedException = false;
|
|
try {
|
|
loadComponentFromBytes(serialized);
|
|
throw "The above line should have thrown.";
|
|
} on ParseError catch (e) {
|
|
if (e.toString().contains("invalid size")) {
|
|
gotExpectedException = true;
|
|
}
|
|
}
|
|
if (!gotExpectedException) {
|
|
throw "Didn't get the right exception!";
|
|
}
|
|
}
|