mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 20:57:22 +02: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.
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Runtime.InteropServices.ComTypes;
|
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Media.Media3D;
|
using System.Windows.Media.Media3D;
|
||||||
using Common.Utilities;
|
|
||||||
using HelixToolkit.Wpf;
|
using HelixToolkit.Wpf;
|
||||||
using Microsoft.PowerToys.Settings.UI.Library;
|
using Microsoft.PowerToys.Settings.UI.Library;
|
||||||
using Bitmap = System.Drawing.Bitmap;
|
using Bitmap = System.Drawing.Bitmap;
|
||||||
@@ -61,9 +59,11 @@ namespace Microsoft.PowerToys.ThumbnailHandler.Stl
|
|||||||
DefaultMaterial = new DiffuseMaterial(new SolidColorBrush(DefaultMaterialColor)),
|
DefaultMaterial = new DiffuseMaterial(new SolidColorBrush(DefaultMaterialColor)),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
var model = stlReader.Read(stream);
|
var model = stlReader.Read(stream);
|
||||||
|
|
||||||
if (model.Bounds == Rect3D.Empty)
|
if (model == null || model.Children.Count == 0 || model.Bounds == Rect3D.Empty)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -108,6 +108,11 @@ namespace Microsoft.PowerToys.ThumbnailHandler.Stl
|
|||||||
bitmapStream.Position = 0;
|
bitmapStream.Position = 0;
|
||||||
|
|
||||||
thumbnail = new Bitmap(bitmapStream);
|
thumbnail = new Bitmap(bitmapStream);
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return thumbnail;
|
return thumbnail;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user