This is a migrated thread and some comments may be shown as answers.

RichTextBox crashes when loading RTF doc with numbered list style created in another editor

1 Answer 106 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Ryan
Top achievements
Rank 1
Ryan asked on 04 Oct 2013, 03:14 PM
A little while ago, we changed the rtf editor used in our application from another third party editor to the telerik RichTextBox editor.  However, I have recently found that Rtf docs created in the previous editor contain list styles that Telerik is unable to handle correctly.  In some cases it just won't display them properly, and in worse case it will crash my application.

The following document causes the editor to crash my application:

{\rtf1\ansi\deff0\uc1\ansicpg1252\deftab720{\fonttbl{\f0\fnil\fcharset1 Times New Roman;}{\f1\fnil\fcharset1 WingDings;}}{\colortbl\red0\green0\blue0;\red255\green0\blue0;\red0\green128\blue0;\red0\green0\blue255;\red255\green255\blue0;\red255\green0\blue255;\red128\green0\blue128;\red128\green0\blue0;\red0\green255\blue0;\red0\green255\blue255;\red0\green128\blue128;\red0\green0\blue128;\red255\green255\blue255;\red192\green192\blue192;\red128\green128\blue128;\red0\green0\blue0;}\wpprheadfoot1\paperw12240\paperh15840\margl1800\margr1800\margt1440\margb1440\headery254\footery254\endnhere\sectdefaultcl{\*\generator WPTools_5.18;}{\*\listtable{\list\listtemplateid1
{\listlevel\leveljc0\levelfollow0\levelstartat1\levelspace0\levelindent360\levelnfc1{\leveltext\'02\'00.;}{\levelnumbers\'01;}}
{\listlevel\leveljc0\levelfollow0\levelstartat1\levelspace0\levelindent360\levelnfc3{\leveltext\'02\'01.;}{\levelnumbers\'01;}}
{\listlevel\leveljc0\levelfollow0\levelstartat1\levelspace0\levelindent360\levelnfc0{\leveltext\'02\'02.;}{\levelnumbers\'01;}}
{\listlevel\leveljc0\levelfollow0\levelstartat1\levelspace0\levelindent360\levelnfc4{\leveltext\'02\'03);}{\levelnumbers\'01;}}
{\listlevel\leveljc0\levelfollow0\levelstartat1\levelspace0\levelindent360\levelnfc2{\leveltext\'03(\'04);}{\levelnumbers\'02;}}
{\listlevel\leveljc0\levelfollow0\levelstartat1\levelspace0\levelindent360\levelnfc4{\leveltext\'03(\'05);}{\levelnumbers\'02;}}
{\listlevel\leveljc0\levelfollow0\levelstartat1\levelspace0\levelindent360\levelnfc0{\leveltext\'03(\'06);}{\levelnumbers\'02;}}
{\listlevel\leveljc0\levelfollow0\levelstartat1\levelspace0\levelindent360\levelnfc0{\leveltext\'03(\'07);}{\levelnumbers\'02;}}
{\listlevel\leveljc0\levelfollow0\levelstartat1\levelspace0\levelindent360\levelnfc0{\leveltext\'03(\'08);}{\levelnumbers\'02;}}
\listid1}}{\*\listoverridetable{\listoverride\listid1\listoverridecount0\ls1}}{\plain\fs24 test @ test 123 /\par
\pard\plain\plain\fs24\par
\plain\fs24 test \'E0 test \par
\pard\plain\plain\fs24\par
\pard\plain\plain\fs24\par
\ls1\ilvl-1{\listtext\fs24 (1)\tab}\plain\fs24\line test   Resume\par
}}


When this document is loaded, using version 2012.3.1129.40 of the telerik wpf components, I initially get the following exception:

System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
   at System.ThrowHelper.ThrowArgumentOutOfRangeException()
   at System.Collections.Generic.List`1.get_Item(Int32 index)
   at Telerik.Windows.Documents.Model.Paragraph.get_LeftIndent()
   at Telerik.Windows.Documents.Model.Paragraph.get_LeftMargin()
   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.UI.DocumentWebLayoutPresenter.MeasureOverride(Size availableSize)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
   at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.ContextLayoutManager.UpdateLayout()
   at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
   at System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()
   at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
   at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
   at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)

The application will continue throwing exceptions until either it crashes or I have to kill it.  I've tried loading this document using the Demo control included in the Q2 2013 SP1 demos, and while it doesn't crash it won't load the document giving a modal dialog saying "The file cannot be opened".  If I manually strip out the \*\listtable section, the telerik editor will be able to load the document without problem, but the list will no longer be numbered as expected. MS Word & WordPad will display this document without any issue.

I have an immediate solution to this problem, using another rtf library to resave without list styling, but it would be ideal if I didn't have to do that, as it changes the styles of the lists in any of these documents.

1 Answer, 1 is accepted

Sort by
0
Alex
Telerik team
answered on 09 Oct 2013, 12:45 PM
Hi,

Thanks for the sample document. We examined and we found that the reason for the exception is in the following control word: "\ilvl-1".  According to the RTF specification v.1.9.1. which we follow:

  • \ilvlN - The 0-based level of the list to which the paragraph belongs.For all simple lists, N should always be 0. For multilevel lists, it can be 0 through 8.
The value -1 in the document is not valid and this is why the import fails. We tried changing the value to a valid one (for example "\ilvl6") and the document was imported successfully.  We tested with Q2 2013 SP1 version of the controls.

I hope that was helpful. If you have other document which are problematic you are welcome to open a support ticket and send them to us so that we can investigate and take the appropriate action.

Regards,
Alex
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
RichTextBox
Asked by
Ryan
Top achievements
Rank 1
Answers by
Alex
Telerik team
Share this question
or