Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception in OpenMCDF 2.4.0 (Worked in 2.3.0) #256

Closed
aunverdorben-dap opened this issue Nov 29, 2024 · 4 comments
Closed

Exception in OpenMCDF 2.4.0 (Worked in 2.3.0) #256

aunverdorben-dap opened this issue Nov 29, 2024 · 4 comments
Assignees
Labels

Comments

@aunverdorben-dap
Copy link
Contributor

aunverdorben-dap commented Nov 29, 2024

When I run this code with OpenMCDF 2.4.0 it will crash when writing the 9th stream.

{
    string tempFile = @"d:\OpenMCDFCrash.dat";

    // create big MCDF file
    CFSVersion version = CFSVersion.Ver_3;
    CFSConfiguration configuration = CFSConfiguration.Default;
    CFSUpdateMode updateMode = CFSUpdateMode.Update;

    using (CompoundFile compoundFile = new CompoundFile(version, configuration))
    {
        compoundFile.SaveAs(tempFile);
        compoundFile.Close();
    }

    using (var compoundFile = new CompoundFile(tempFile, updateMode, configuration))
    {
        byte[] data = new byte[6617123];

        for (int i = 0; i < 100; i++)
        {
            var cfStream = compoundFile.RootStorage.AddStream($"Stream {i}.dat");
            cfStream.SetData(data);
        }

        compoundFile.Commit();
    }
}

I get:

System.IO.IOException: Seek before origin
at OpenMcdf.StreamView.Seek(Int64 offset, SeekOrigin origin)
at OpenMcdf.StreamRW.Seek(Int64 count, SeekOrigin origin)
at OpenMcdf.CompoundFile.AllocateDIFATSectorChain(List1 FATsectorChain) at OpenMcdf.CompoundFile.AllocateFATSectorChain(List1 sectorChain)
at OpenMcdf.CompoundFile.AllocateSectorChain(List1 sectorChain) at OpenMcdf.CompoundFile.SetSectorChain(List1 sectorChain)
at OpenMcdf.CompoundFile.SetStreamLength(CFItem cfItem, Int64 length)
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 OpenMCDF2._4._0CrashRepro.Program.Main(String[] args) in

@jeremy-visionaid
Copy link
Collaborator

jeremy-visionaid commented Nov 30, 2024

While I can verify that this is new to v2.4.0, I'm not sure if I'd be able to fix it... While I made a lot of changes on 2.4, most of them were for code quality improvements and validation rather than functional changes (I put in the check which meant that the seek arguments were validated, so it crashes instead of corrupting the file).

So, I suspect that this is probably a regression from fixing a different crash that was happening on v2.3 (#184). However, that issue was the thing that really made me think that a rewrite for v3 was probably a better course of action than trying to continue to improve/fix v2.

So, my advice would be to try 3.0.0-preview.4 and see if that resolves the problem for you. If there's any problems with 3.0.0 then I'll gladly fix it, otherwise I think this one would be down to @ironfede since he knows the v2 code better than I do.

@ironfede
Copy link
Owner

ironfede commented Dec 1, 2024

Fixed in 2.4.1 There was a wrong calculation for DFAT sectors numbers -> regression from 2.3 branch.
Thank you @aunverdorben-dap for having found this issue.

@ironfede ironfede closed this as completed Dec 1, 2024
@ironfede ironfede self-assigned this Dec 1, 2024
@ironfede ironfede added the bug label Dec 1, 2024
@jeremy-visionaid
Copy link
Collaborator

Awesome, thanks for handling that one @ironfede!

@aunverdorben-dap
Copy link
Contributor Author

Fixed in 2.4.1 There was a wrong calculation for DFAT sectors numbers -> regression from 2.3 branch. Thank you

Thank you for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants