sergey-tihon / Clippit

Fresh PowerTools for OpenXml
https://sergey-tihon.github.io/Clippit/
MIT License
50 stars 19 forks source link

fix: PtOpenXmlUtil: process corrupted OpenXmlPart items #56

Closed f1nzer closed 2 years ago

f1nzer commented 2 years ago

Fixes #55

FileFormatException is thrown only on classic NetFramework.

The root cause of this exception is that OpenXmlPart's content is corrupted. That's why ProgressiveCrcCalculatingStream throws exception during Crc32 validation check. As a hacky workaround Stream.SetLength(...) is used to disable crc validation.

CanSeek is used to prevent bad situations and reduce unnecessary calls. Opposite to that RuntimeInformation.FrameworkDescription could be used to determine the NetFramework in runtime.

sergey-tihon commented 2 years ago

It is the only fix that it needed?

What about the place where Clippit copy from old part to new part https://github.com/sergey-tihon/Clippit/blob/master/OpenXmlPowerTools/PowerPoint/FluentPresentationBuilder.cs#L889-L890

f1nzer commented 2 years ago

Hash calculation is the first place where the data is accessed.

NetFramework-only details: Part.GetStream() returns ZipIOModeEnforcingStream that uses ProgressiveCrcCalculatingStream as a base (inner) stream. This inner stream is reused all the time while the parent stream can be disposed/etc. That's why only initial `SetLength" is required and after that Crc calculation will be disabled for every other stream-related operation.

sergey-tihon commented 2 years ago

Thank you for the fix @f1nzer !