[STLThumbnail]Fix crashes on invalid files (#29172)

* [StlThumbnailProvider] STL reader is added to try catch block. Model checks are increased.

* [StlThumbnailProvider] Spellcheck fix
This commit is contained in:
gokcekantarci
2023-10-17 19:53:20 +03:00
committed by GitHub
parent 413624397e
commit ec47805634

View File

@@ -2,11 +2,9 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.IO;
using System.Runtime.InteropServices.ComTypes;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Media3D;
using Common.Utilities;
using HelixToolkit.Wpf;
using Microsoft.PowerToys.Settings.UI.Library;
using Bitmap = System.Drawing.Bitmap;
@@ -61,9 +59,11 @@ namespace Microsoft.PowerToys.ThumbnailHandler.Stl
DefaultMaterial = new DiffuseMaterial(new SolidColorBrush(DefaultMaterialColor)),
};
try
{
var model = stlReader.Read(stream);
if (model.Bounds == Rect3D.Empty)
if (model == null || model.Children.Count == 0 || model.Bounds == Rect3D.Empty)
{
return null;
}
@@ -108,6 +108,11 @@ namespace Microsoft.PowerToys.ThumbnailHandler.Stl
bitmapStream.Position = 0;
thumbnail = new Bitmap(bitmapStream);
}
catch (Exception)
{
return null;
}
return thumbnail;
}