Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
GitHub or Developer Community with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
Created attachment 16045 [details]
Patch to check a part's .Package is non-null before calling GetStream
I'm using Microsoft's Open XML SDK to mangle Office documents. I have a codebase that works well on Windows, but crashes on Mono. I've tracked down a couple of issues, and patches are attached.
Specifically, the WordprocessingDocument.ChangeDocumentType invariably fails with a packaging error, with an inner NullReferenceException from System.IO.Packaging. I've tracked the cause down to an interaction between ZipPackage.FlushCore() and Package. From Package.cs, in Package.DeletePart:
// FIXME: MS.NET doesn't remove the relationship part
// Instead it throws an exception if you try to use it
if (PartExists (part.RelationshipsPartUri))
GetPart (part.RelationshipsPartUri).Package = null;
Then when FlushCore() tries to write all the parts out, GetStream() attempts to dereference Package and bombs. A patch is attached.
After fixing that one, I found it was writing files that the Open XML SDK wouldn't accept as input. It turned out that _rels/.rels was being damaged when parts were deleted: if the new .rels file was shorter than the old, it wouldn't be truncated, and junk would remain after the end of the relationship XML. A second patch is attached for this one.
Many thanks for the hard work on System.IO.Packaging - it's a complicated beast and it's very, very useful!
Created attachment 16046 [details]
Patch: properly truncate .rels when rewriting
I've applied the first patch but the second one looks suspicious. Do you think you could write a test for it?
Created attachment 16096 [details]
Test case: check that rel deletion doesn't corrupt .rels
Here's a test case for the .rel truncation corruption.
Patches applied. Thanks!