question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OpenMcdf.CFCorruptedFileException: The file is corrupted.

See original GitHub issue

I’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:

  1. Clone freezy/VisualPinball.Engine
  2. Download the test file writefail.vpx here
  3. 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");
    }
    
  4. Execute the test and verify it works
  5. Open ItemData.cs and remove string.Empty from EditorLayerName on line 24, setting its default value to null
  6. 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:closed
  • Created 3 years ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
ironfedecommented, Jul 24, 2020

@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

2reactions
ironfedecommented, Jul 17, 2020

@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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found