Hello,
HtmlDataProvider will throw an exception on export or when used by a RadRichTextBox, when using a html containing the length value "NaN", which doesn't seem to be a standard approved value, but nevetheless it is a special case because other invaild values are simply ignored while this one triggers two exceptions - one of which is hard to catch and crashes the whole application.
Code to reproduce: Console App / .Net Framework 4.8 / Package Telerik.Windows.Documents.FormatProviders.Html.for.Wpf 2022.3.912
using System;
using Telerik.Windows.Documents.FormatProviders.Html;
using Telerik.Windows.Documents.Model;
namespaceHtmlProviderCrash
{
internalclassProgram
{
static void Main(string[] args)
{
var htmlContent = "<img src=\"https://static.cleverpush.com/notification/icon/92fYF7FtKbthsezwS.png?element=Le7adDwC\" " +
"alt=\"\" style=\"display: inline-table;max-width: 100%;width: 300px;\" width=\"300\" height=\"NaN\" class=\"cp-element-image light-img\">";
HtmlFormatProvider htmlProvider = new HtmlFormatProvider();
RadDocument document = htmlProvider.Import(htmlContent);
try
{
var export = htmlProvider.Export(document);
}
catch (Exception ex)
{
var ka = ex.ToString();
}
while (Console.ReadKey().KeyChar != 'x') { }
}
}
}
Message "MeasureOverride returned NaN: Telerik.Windows.Documents.Layout.ImageLayoutBox" string at Telerik.Windows.Documents.Layout.LayoutElement.Measure(SizeF availableSize) at Telerik.Windows.Documents.Layout.ParagraphLayoutBox.MeasureCurrentGroupSize(ParagraphLayoutBoxMeasureContext context, SizeF measureSize, Func`1 GetCurrentXDefaultValue, LinkedList`1 currentGroupInlines) at Telerik.Windows.Documents.Layout.ParagraphLayoutBox.MeasureOverride(SizeF availableSize) at Telerik.Windows.Documents.Layout.LayoutElement.MeasureCore(SizeF availableSize) at Telerik.Windows.Documents.Layout.LayoutElement.Measure(SizeF availableSize) at Telerik.Windows.Documents.Layout.SectionLayoutBox.MeasureOverrideInternal(SizeF availableSize) at Telerik.Windows.Documents.Layout.SectionLayoutBox.MeasureOverride(SizeF availableSize) at Telerik.Windows.Documents.Layout.LayoutElement.MeasureCore(SizeF availableSize) at Telerik.Windows.Documents.Layout.LayoutElement.Measure(SizeF availableSize) at Telerik.Windows.Documents.Layout.DocumentLayoutBox.MeasureOverrideInternal(SizeF availableSize) at Telerik.Windows.Documents.Layout.DocumentLayoutBox.MeasureOverride(SizeF availableSize) at Telerik.Windows.Documents.Layout.LayoutElement.MeasureCore(SizeF availableSize) at Telerik.Windows.Documents.Layout.LayoutElement.Measure(SizeF availableSize) at Telerik.Windows.Documents.Model.RadDocument.Measure(SizeF measureSize) at Telerik.Windows.Documents.Model.RadDocument.MeasureAndArrangeInDefaultSize() at Telerik.Windows.Documents.Model.RadDocument.EnsureDocumentMeasuredAndArranged() at Telerik.Windows.Documents.FormatProviders.Html.Export.HtmlDocumentExporter.Export(RadDocument document, Stream output) at Telerik.Windows.Documents.FormatProviders.Html.HtmlFormatProvider.Export(RadDocument document, Stream output) at Telerik.Windows.Documents.FormatProviders.Html.HtmlFormatProvider.Export(RadDocument document) at HtmlProviderCrash.Program.Main(String[] args)
Message "The image data generated an overflow during processing"
at System.Windows.Media.Imaging.TransformedBitmap.FinalizeCreation() in System.Windows.Media.Imaging\TransformedBitmap.cs:line 216
at System.Windows.Media.Imaging.TransformedBitmap.EndInit() in System.Windows.Media.Imaging\TransformedBitmap.cs:line 112
at System.Windows.Media.Imaging.BitmapImage.FinalizeCreation() in System.Windows.Media.Imaging\BitmapImage.cs:line 505
at System.Windows.Media.Imaging.BitmapImage.EndInit() in System.Windows.Media.Imaging\BitmapImage.cs:line 319
at Telerik.Windows.Documents.Model.ImageDocumentElementHelper.CreateImageSourceCore(BitmapCreateOptions createOptions, Byte[] bytes, Size renderingSize, String& extension, Byte[]& resultBytes)
at Telerik.Windows.Documents.Model.ImageDocumentElementHelper.CreateImageSource(Byte[] bytes, Size imageSize, Size scaleFactor, String& extension, Byte[]& resultBytes)
at Telerik.Windows.Documents.Model.ImageDocumentElementHelper.InitializeRawImageData(IImageDocumentElement imageElement, Byte[] bytes, Size scaleFactor, String& extension)
at Telerik.Windows.Documents.Model.ImageDocumentElementHelper.InitInternal(IImageDocumentElement imageElement, Byte[] bytes, Size size, String extension, Boolean isUserInitiated)
at Telerik.Windows.Documents.Model.ImageInline.InitImageElementFromUriStream(Stream stream)
at Telerik.Windows.Documents.Model.ImageInline.<SetStreamFromUriSource>b__0(Object s, StreamReadyEventArgs a)
at Telerik.Windows.Documents.Utils.ResourceStreamLocator.OnStreamReady()
at Telerik.Windows.Documents.Utils.ResourceStreamLocator.<GetStreamAsync>b__0(Object sender, OpenReadCompletedEventArgs e)
at System.Net.WebClient.OnOpenReadCompleted(OpenReadCompletedEventArgs e)
at System.Net.WebClient.OpenReadOperationCompleted(Object arg)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()