Check the matrix in pushTransform (flutter/engine#8758)

Fixes flutter/flutter#31650
This commit is contained in:
liyuqian
2019-04-26 14:09:53 -07:00
committed by GitHub
parent bc686574ae
commit 41077726ae
4 changed files with 58 additions and 6 deletions

View File

@@ -15,8 +15,8 @@ TransformLayer::~TransformLayer() = default;
void TransformLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
// Checks (in some degree) that SkMatrix transform_ is valid and initialized.
//
// We need this even if is_set_ is true since one can call set_transform with
// an uninitialized SkMatrix.
// We need this even if transform_ is initialized to identity since one can
// call set_transform with an uninitialized SkMatrix.
//
// If transform_ is uninitialized, this assert may look flaky as it doesn't
// fail all the time, and some rerun may make it pass. But don't ignore it and

View File

@@ -57,10 +57,7 @@ class SceneBuilder extends NativeFieldWrapperClass2 {
///
/// See [pop] for details about the operation stack.
EngineLayer pushTransform(Float64List matrix4) {
if (matrix4 == null)
throw new ArgumentError('"matrix4" argument cannot be null');
if (matrix4.length != 16)
throw new ArgumentError('"matrix4" must have 16 entries.');
assert(_matrix4IsValid(matrix4));
return _pushTransform(matrix4);
}
EngineLayer _pushTransform(Float64List matrix4) native 'SceneBuilder_pushTransform';

View File

@@ -42,6 +42,7 @@ bool _offsetIsValid(Offset offset) {
bool _matrix4IsValid(Float64List matrix4) {
assert(matrix4 != null, 'Matrix4 argument was null.');
assert(matrix4.length == 16, 'Matrix4 must have 16 entries.');
assert(matrix4.every((double value) => value.isFinite), 'Matrix4 entries must be finite.');
return true;
}

View File

@@ -0,0 +1,54 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:typed_data' show Float64List;
import 'dart:ui';
import 'package:test/test.dart';
void main() {
test('pushTransform validates the matrix', () {
final SceneBuilder builder = SceneBuilder();
final Float64List matrix4 = Float64List.fromList(<double>[
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1,
]);
expect(builder.pushTransform(matrix4), isNotNull);
final Float64List matrix4WrongLength = Float64List.fromList(<double>[
1, 0, 0, 0,
0, 1, 0,
0, 0, 1, 0,
0, 0, 0,
]);
expect(
() => builder.pushTransform(matrix4WrongLength),
throwsA(const TypeMatcher<AssertionError>()),
);
final Float64List matrix4NaN = Float64List.fromList(<double>[
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, double.nan,
]);
expect(
() => builder.pushTransform(matrix4NaN),
throwsA(const TypeMatcher<AssertionError>()),
);
final Float64List matrix4Infinity = Float64List.fromList(<double>[
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, double.infinity,
]);
expect(
() => builder.pushTransform(matrix4NaN),
throwsA(const TypeMatcher<AssertionError>()),
);
});
}