OpenMcdf.CFCorruptedFileException: The file is corrupted.
See original GitHub issueI’m getting the above message when writing data. I’ve spent a fair amount of debugging and am still clueless how this could happen.
First of all, it doesn’t happen all the time. We’re writing to hundreds of streams that work all fine, but sometimes it fails with this message (here a 190M file). The stack trace looks like this:
OpenMcdf.CFCorruptedFileException : The file is corrupted.
at OpenMcdf.CompoundFile.EnsureUniqueSectorIndex(Int32 nextSecID, HashSet`1 processedSectors)
at OpenMcdf.CompoundFile.GetFatSectorChain()
at OpenMcdf.CompoundFile.GetNormalSectorChain(Int32 secID)
at OpenMcdf.CompoundFile.GetSectorChain(Int32 secID, SectorType chainType)
at OpenMcdf.CompoundFile.WriteData(CFItem cfItem, Byte[] buffer, Int64 position, Int32 offset, Int32 count)
at OpenMcdf.CompoundFile.WriteData(CFItem cfItem, Int64 position, Byte[] buffer)
at OpenMcdf.CompoundFile.WriteData(CFItem cfItem, Byte[] buffer)
at OpenMcdf.CFStream.SetData(Byte[] data)
at VisualPinball.Engine.IO.BiffData.WriteData(CFStorage gameStorage, HashWriter hashWriter) in VisualPinball.Engine\VisualPinball.Engine\IO\BiffData.cs:line 49
at VisualPinball.Engine.VPT.Table.TableWriter.WriteImages() in VisualPinball.Engine\VisualPinball.Engine\VPT\Table\TableWriter.cs:line 105
at VisualPinball.Engine.VPT.Table.TableWriter.WriteTable(String fileName) in VisualPinball.Engine\VisualPinball.Engine\VPT\Table\TableWriter.cs:line 40
at VisualPinball.Engine.VPT.Table.Table.Save(String fileName) in VisualPinball.Engine\VisualPinball.Engine\VPT\Table\Table.cs:line 165
at VisualPinball.Engine.Test.VPT.DebugTests.ShouldWriteChecksum() in VisualPinball.Engine\VisualPinball.Engine.Test\VPT\DebugTests.cs:line 13
The project is an open source pinball simulator, and it’s kind of awkward to reproduce, but here we go nevertheless:
- Clone freezy/VisualPinball.Engine
- Download the test file
writefail.vpx
here - Open
DebugTests.cs
and add this method:[Test] public void ShouldWrite() { var table = Engine.VPT.Table.Table.Load(@"path to writefail.vpx"); table.Save( @"some other path"); }
- Execute the test and verify it works
- Open
ItemData.cs
and removestring.Empty
fromEditorLayerName
on line 24, setting its default value tonull
- Re-run the test to reproduce the error
Thing is, it’s just binary data. Setting that field to null
just doesn’t write it into a binary blob. How this could trigger such an error is beyond me, but I admit I don’t entirely understand the compound doc format.
Any hints or suggestions would be greatly appreciated.
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (6 by maintainers)
Top Results From Across the Web
CompoundFile.cs - ironfede/openmcdf
This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL...
Read more >Using OpenMCDF to modify xls file results in corrupted output
I'm working on a project where I need to edit the contents of existing office files. I'm using the open source library OpenMCDF...
Read more >/usr/share/OpenMCDF/help/sample structured storage ...
The actual contents of the file can be viewed below. ... GetData(); //if 'reportRead.xls' is corrupted, openMcdf will try to lad it anyway ......
Read more >C# (CSharp) CompoundFile Examples
File : CompoundFileTest.cs Project: Notalib/OpenMCDF ... <exception cref="OEFileIsCorrupt">Raised when the file is corrupt</exception> internal static string ...
Read more >Stream to PDF creates a corrupt or damaged file
I am creating PDF files from stream: using (Stream file = File.Create($"C:\test.pdf")) ... Stream to PDF creates a corrupt or damaged file.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@freezy thank you for letting me know. Please notice that nuget pkg for openmcdf 2.2.1.6 is source link enabled to allow a deeper analysis and debug of suspected issues. Best regards, Federico
@freezy many thanks for reporting this issue . There was an issue in handling a limit condition while loading DIFAT sectors when exactly 508 bytes were written AND only one sector exists (I think that I really couldn’t create such a ‘perfect’ test 😉 ) I’ve committed the fix but I need time to extensively recheck potential regressions from this change before publishing a nuget package. Please, try to build and reference the new library from source to verify your use case: it looks ok to me. Best Regards, Federico