Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RichEditTextDocument crashes when loading RTF file that contains RTL list (bullets/numbering) #10162

Open
Khiro95 opened this issue Nov 13, 2024 · 0 comments
Labels
bug Something isn't working needs-triage Issue needs to be triaged by the area owners

Comments

@Khiro95
Copy link

Khiro95 commented Nov 13, 2024

Describe the bug

Using RichEditTextDocument.LoadFromStream(TextSetOptions, IRandomAccessStream) or RichEditTextDocument.SetText(TextSetOptions, String) throws exception when I attempt to load a RTF file/text which contains a RTL bulleted list and a numbered list.

Exception:

System.AccessViolationException
  HResult=0x80004003
  Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
  • When using RichEditTextDocument.LoadFromStream(TextSetOptions, IRandomAccessStream):
    at Microsoft.WinUI.dll!ABI.Microsoft.UI.Xaml.IFrameworkElementOverridesMethods.MeasureOverride(WinRT.IObjectReference _obj, Windows.Foundation.Size availableSize)
  • When using RichEditTextDocument.SetText(TextSetOptions, String):
    at Microsoft.WinUI.dll!ABI.Microsoft.UI.Text.ITextDocumentMethods.SetText(WinRT.IObjectReference _obj, Microsoft.UI.Text.TextSetOptions options, string value)

This is a sample RTF block that reproduce the issue:

\pard{\pntext\f2\'B7\tab}{\*\pn\pnlvlblt\pnf2\pnindent0{\pntxtb\'B7}}\rtlpar\fi-360\li720\sa200\sl276\slmult1\qr\f0\rtlch\fs22\lang5121\'c7\'e1\'da\'e4\'d5\'d1 \'c7\'e1\'c3\'e6\'e1\par
{\pntext\f2\'B7\tab}\f0\rtlch\lang5121\'c7\'e1\'da\'e4\'d5\'d1 \'c7\'e1\'cb\'c7\'e4\'ed\par

The \rtlpar control word is what makes the app crash since removing it, or even replacing it with \ltrpar control word, doesn't cause crash.

Steps to reproduce the bug

  1. Add a RichEditBox element.
<RichEditBox x:Name="richTB"/>
  1. Load a .rtf file that contains RTL list
StorageFile file = await StorageFile.GetFileFromPathAsync(@"C:\test.rtf");
IRandomAccessStream randAccStream = await file.OpenAsync(FileAccessMode.Read);
richTB.Document.LoadFromStream(TextSetOptions.FormatRtf | TextSetOptions.UnicodeBidi, randAccStream);

test.rtf file has the following content (in Arabic):

{\rtf1\fbidis\ansi\deff0\nouicompat{\fonttbl{\f0\fnil\fcharset178 Segoe UI;}{\f1\fnil\fcharset0 Calibri;}{\f2\fnil\fcharset2 Symbol;}}
{\*\generator Riched20 10.0.19041}\viewkind4\uc1 
\pard{\pntext\f2\'B7\tab}{\*\pn\pnlvlblt\pnf2\pnindent0{\pntxtb\'B7}}\rtlpar\fi-360\li720\sa200\sl276\slmult1\qr\f0\rtlch\fs22\lang5121\'c7\'e1\'da\'e4\'d5\'d1 \'c7\'e1\'c3\'e6\'e1\par
{\pntext\f2\'B7\tab}\f0\rtlch\lang5121\'c7\'e1\'da\'e4\'d5\'d1 \'c7\'e1\'cb\'c7\'e4\'ed\par
}
  1. Run the app and observe the crash

Expected behavior

I expect RichEditTextDocument to be able to load any valid RTF file/text including those containing RTL lists.

Screenshots

That's what I see when open the sample .rtf file using WordPad:
Image

NuGet package version

WinUI 3 - Windows App SDK 1.6.2: 1.6.241106002

Windows version

Windows 10 (21H2): Build 19044

Additional context

Loading the same file works fine in a WPF app!

@Khiro95 Khiro95 added the bug Something isn't working label Nov 13, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-triage Issue needs to be triaged by the area owners
Projects
None yet
Development

No branches or pull requests

1 participant