[SDK] Adds an SDK hash to kernels and the VM.
Adds a new SDK hash to kernels and the VM which is optionally checked to verify kernels are built for the same SDK as the VM. This helps catch incompatibilities that are currently causing subtle bugs and (not so subtle) crashes. The SDK hash is encoded in kernels as a new field in components. The hash is derived from the 10 byte git short hash. This new check can be disabled via: tools/gn.py ... --no-verify-sdk-hash This CL bumps the min. (and max.) supported kernel format version, making the VM backwards incompatible from this point back. Bug: https://github.com/dart-lang/sdk/issues/41802 Change-Id: I3cbb2d481239ee64dafdaa0e4aac36c80281931b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/150343 Commit-Queue: Clement Skau <cskau@google.com> Reviewed-by: Jens Johansen <jensj@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com>
This commit is contained in:
committed by
commit-bot@chromium.org
parent
d5120208b4
commit
edde575dcd
@@ -5,6 +5,7 @@ library kernel.ast_from_binary;
|
||||
|
||||
import 'dart:core' hide MapEntry;
|
||||
import 'dart:developer';
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import '../ast.dart';
|
||||
@@ -28,11 +29,22 @@ class InvalidKernelVersionError {
|
||||
InvalidKernelVersionError(this.version);
|
||||
|
||||
String toString() {
|
||||
return 'Unexpected Kernel version ${version} '
|
||||
return 'Unexpected Kernel Format Version ${version} '
|
||||
'(expected ${Tag.BinaryFormatVersion}).';
|
||||
}
|
||||
}
|
||||
|
||||
class InvalidKernelSdkVersionError {
|
||||
final String version;
|
||||
|
||||
InvalidKernelSdkVersionError(this.version);
|
||||
|
||||
String toString() {
|
||||
return 'Unexpected Kernel SDK Version ${version} '
|
||||
'(expected ${expectedSdkHash}).';
|
||||
}
|
||||
}
|
||||
|
||||
class CompilationModeError {
|
||||
final String message;
|
||||
|
||||
@@ -484,6 +496,13 @@ class BinaryBuilder {
|
||||
if (_bytes.length == 0) throw new StateError("Empty input given.");
|
||||
}
|
||||
|
||||
void _readAndVerifySdkHash() {
|
||||
final sdkHash = ascii.decode(readBytes(sdkHashLength));
|
||||
if (!isValidSdkHash(sdkHash)) {
|
||||
throw InvalidKernelSdkVersionError(sdkHash);
|
||||
}
|
||||
}
|
||||
|
||||
/// Deserializes a kernel component and stores it in [component].
|
||||
///
|
||||
/// When linking with a non-empty component, canonical names must have been
|
||||
@@ -511,6 +530,9 @@ class BinaryBuilder {
|
||||
if (version != Tag.BinaryFormatVersion) {
|
||||
throw InvalidKernelVersionError(version);
|
||||
}
|
||||
|
||||
_readAndVerifySdkHash();
|
||||
|
||||
_byteOffset = offset;
|
||||
List<int> componentFileSizes = _indexComponents();
|
||||
if (componentFileSizes.length > 1) {
|
||||
@@ -694,6 +716,8 @@ class BinaryBuilder {
|
||||
throw InvalidKernelVersionError(formatVersion);
|
||||
}
|
||||
|
||||
_readAndVerifySdkHash();
|
||||
|
||||
// Read component index from the end of this ComponentFiles serialized data.
|
||||
_ComponentIndex index = _readComponentIndex(componentFileSize);
|
||||
|
||||
@@ -718,6 +742,8 @@ class BinaryBuilder {
|
||||
throw InvalidKernelVersionError(formatVersion);
|
||||
}
|
||||
|
||||
_readAndVerifySdkHash();
|
||||
|
||||
List<String> problemsAsJson = readListOfStrings();
|
||||
if (problemsAsJson != null) {
|
||||
component.problemsAsJson ??= <String>[];
|
||||
|
||||
Reference in New Issue
Block a user