From c42a2edc2025a86a4a10e99493d1c1597741dbaa Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Fri, 13 Jan 2017 17:08:24 -0800 Subject: [PATCH] Check if the canvas bounds rect contains infinite or NaN values (flutter/engine#3339) See https://github.com/flutter/flutter/issues/7431 --- engine/src/flutter/lib/ui/geometry.dart | 3 +++ engine/src/flutter/lib/ui/painting.dart | 2 ++ 2 files changed, 5 insertions(+) diff --git a/engine/src/flutter/lib/ui/geometry.dart b/engine/src/flutter/lib/ui/geometry.dart index e96ff4cc27..3bd313ec11 100644 --- a/engine/src/flutter/lib/ui/geometry.dart +++ b/engine/src/flutter/lib/ui/geometry.dart @@ -580,6 +580,9 @@ class Rect { /// Negative areas are considered empty. bool get isEmpty => left >= right || top >= bottom; + /// Whether all coordinates of this rectangle are finite. + bool get isFinite => left.isFinite && top.isFinite && right.isFinite && bottom.isFinite; + /// The lesser of the magnitudes of the width and the height of this /// rectangle. double get shortestSide { diff --git a/engine/src/flutter/lib/ui/painting.dart b/engine/src/flutter/lib/ui/painting.dart index 7abeed2a8e..b675c1c2bd 100644 --- a/engine/src/flutter/lib/ui/painting.dart +++ b/engine/src/flutter/lib/ui/painting.dart @@ -1116,6 +1116,8 @@ class Canvas extends NativeFieldWrapperClass2 { throw new ArgumentError('The given PictureRecorder was null.'); if (recorder.isRecording) throw new ArgumentError('The given PictureRecorder is already associated with another Canvas.'); + if (!cullRect.isFinite) + throw new ArgumentError('The cullRect contains infinite or NaN coordinates.'); // TODO(ianh): throw if recorder is defunct (https://github.com/flutter/flutter/issues/2531) _constructor(recorder, cullRect.left, cullRect.top, cullRect.right, cullRect.bottom); }