Word - File Corrupted Exception Loading valid RTF File into Word document

Hi,

We’re pulling the body from this email (attached in zip file) which is RTF format. We load the RTF into the Aspose library in the following manner (‘text’ is a string with the RTF payload):

// write the text to the stream
MemoryStream ms = new MemoryStream();
StreamWriter sw = new StreamWriter(ms, encoding);
sw.Write(text);
sw.Flush();
ms.Seek(0, SeekOrigin.Begin);
// load the document
AW.LoadOptions loadOptions = new AW.LoadOptions();
loadOptions.LoadFormat = AW.LoadFormat.Rtf;
AW.Document doc = new AW.Document(ms, loadOptions);

And an exception is thrown:

Aspose.Words.FileCorruptedException: The document appears to be corrupted and cannot be loaded. ---> System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: digit
at x6c95d9cf46ff5f25.x0d299f323d241756.xe3ec68422266caf1(Char xbc30138fc52cbe85)
at x2182451cabb5c30d.x03f56b37a0050a82.xbfeb690f3f95a932()
at x2182451cabb5c30d.xc71a5c7f64b2230d.xbd6083b329527c4e(x03f56b37a0050a82 x153c99a852375422)
at x2182451cabb5c30d.x66a12b1255ab95ec.x06b0e25aa6ad68a9()
at Aspose.Words.Document.x5d4db34d48fb3129(Stream xcf18e5243f8d5fd3, LoadOptions x27aceb70372bde46)

This seems to be specific to this email as other RTF emails are processed without issues. The email opens properly in Outlook so we’re wondering if this is a bug in the Aspose library.
We are using Aspose.Word version 13.3

Thanks,.

Hi Debra,

Thanks for your inquiry. First off, I would suggest you please upgrade to the latest version of Aspose.Words for .NET (13.11.0) from the following link. I hope, this helps.
https://releases.aspose.com/words/net

In case the problem still remains, please create a standalone/runnable simple application (for example a Console Application project) that helps me reproduce your problem on my end and attach it here for testing

As soon as you get this application ready for me, I’ll start investigation into your issue and provide you more information.

Best regards,

I tried with the latest version of your software and still have an issue.

Attached is a zip of a simple project that illustrates the issue. I’ve included 2 rtf files - sampledoesnotwork.rtf and sampledoeswork.rtf. Both files open correctly in Microsoft Word but Aspose Word will only open one of them.

For the record I’m not sure why you need a sample application from me as all I did was take one of the samples that Aspose provides and plugin the code snippet which I already gave you. (I’ll include it again below.). Anyway thanks again for the help.

string path = @"sampledoesnotwork.rtf";
// NOTE: comment out the line above and uncomment for working example. Both files open correctly in Microsoft Word but
// Aspose Word will not load sampledoesnotwork.
// string path = @"sampledoeswork.rtf";

// Get the contents of the RTF file. When the contents of the file are 
// stored in the string (rtfText), the contents are encoded as UTF-16. 
string body = System.IO.File.ReadAllText(path);
MemoryStream ms = new MemoryStream();
StreamWriter sw = new StreamWriter(ms, System.Text.Encoding.ASCII);
sw.Write(body);
sw.Flush();
ms.Seek(0, SeekOrigin.Begin);

// load the document
Aspose.Words.LoadOptions loadOptions = new Aspose.Words.LoadOptions();
loadOptions.LoadFormat = Aspose.Words.LoadFormat.Rtf;
Aspose.Words.Document doc = new Aspose.Words.Document(ms, loadOptions);
doc.Save(@"rtfdoc.docx");

Hi Debra,

Thanks for the additional information. While using the latest version of Aspose.Words i.e. 13.12.0, I managed to reproduce this issue on my side. Aspose.Words’ Document constructor threw Aspose.Words.FileCorruptedException when loading your “sampledoesnotwork.rtf” file on my side. I have logged this issue in our bug tracking system. The ID of this issue is WORDSNET-9566. Your request has also been linked to this issue and you will be notified as soon as it is resolved. Sorry for the inconvenience.

Best regards,

The issues you have found earlier (filed as WORDSNET-9566) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.