From 5b706ae123c3ce69fc9866ea8ac3eb77d8c7cf2c Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Thu, 23 Apr 2015 23:19:09 +0100 Subject: [PATCH] Validate size returned by MeasureCore. --- Perspex.Layout/Layoutable.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Perspex.Layout/Layoutable.cs b/Perspex.Layout/Layoutable.cs index e15d9f7d85..e1974018a7 100644 --- a/Perspex.Layout/Layoutable.cs +++ b/Perspex.Layout/Layoutable.cs @@ -170,7 +170,17 @@ namespace Perspex.Layout if (force || !this.IsMeasureValid || this.previousMeasure != availableSize) { this.IsMeasureValid = true; - this.DesiredSize = this.MeasureCore(availableSize).Constrain(availableSize); + + var desiredSize = this.MeasureCore(availableSize).Constrain(availableSize); + + if (desiredSize.Width < 0 || desiredSize.Height < 0 || + double.IsInfinity(desiredSize.Width) || double.IsInfinity(desiredSize.Height) || + double.IsNaN(desiredSize.Width) || double.IsNaN(desiredSize.Height)) + { + throw new InvalidOperationException("Invalid size returned for Measure."); + } + + this.DesiredSize = desiredSize; this.previousMeasure = availableSize; this.Log().Debug(