Duplicated
Last Updated: 13 Jan 2025 11:28 by Maximilian
Maximilian
Created on: 10 Jan 2025 12:41
Category: UI for WPF
Type: Bug Report
0
HtmlDataProvider throws a hard to handle exception when containing invalid html-length value "NaN"

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()


 

Duplicated
This item is a duplicate of an already existing item. You can find the original item here:
2 comments
Maximilian
Posted on: 13 Jan 2025 11:28
Thanks, the update has resolved the Issue.
ADMIN
Dimitar
Posted on: 13 Jan 2025 08:17

Hi Maximilian,

This was fixed in a more recent version of the suite. Here are the details: RichTextBox: HTML NaN values cause InvalidOperationException

I am afraid I cannot suggest a workaround for your version. I am marking this thread as duplicated. 

Let me know if you have additional questions.

Regards,
Dimitar
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.