Skip to content

Commit

Permalink
Ensure that width+height scale check account for divide-by-zero, whic…
Browse files Browse the repository at this point in the history
…h returns infinity (#22283)

Co-authored-by: Mike Corsaro <mikecorsaro@microsoft.com>
  • Loading branch information
Foda and Mike Corsaro committed May 8, 2024
1 parent 4ede8f9 commit 1dfae6f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Controls/src/Core/Shapes/Shape.cs
Expand Up @@ -310,8 +310,8 @@ internal void TransformPathForBounds(PathF path, Graphics.Rect viewBounds)
float calculatedWidth = (float)(viewBounds.Width / pathBounds.Width);
float calculatedHeight = (float)(viewBounds.Height / pathBounds.Height);

float widthScale = float.IsNaN(calculatedWidth) ? 0 : calculatedWidth;
float heightScale = float.IsNaN(calculatedHeight) ? 0 : calculatedHeight;
float widthScale = float.IsNaN(calculatedWidth) || float.IsInfinity(calculatedWidth) ? 0 : calculatedWidth;
float heightScale = float.IsNaN(calculatedHeight) || float.IsInfinity(calculatedHeight) ? 0 : calculatedHeight;

switch (Aspect)
{
Expand Down Expand Up @@ -393,8 +393,8 @@ protected override Size MeasureOverride(double widthConstraint, double heightCon

double scaleX = widthConstraint / result.Width;
double scaleY = heightConstraint / result.Height;
scaleX = double.IsNaN(scaleX) ? 0 : scaleX;
scaleY = double.IsNaN(scaleY) ? 0 : scaleY;
scaleX = double.IsNaN(scaleX) || double.IsInfinity(scaleX) ? 0 : scaleX;
scaleY = double.IsNaN(scaleY) || double.IsInfinity(scaleY) ? 0 : scaleY;

switch (Aspect)
{
Expand Down

0 comments on commit 1dfae6f

Please sign in to comment.