mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
[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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user