From 03ef8cb7a735cdf569886d6c8b21809be3bc38e6 Mon Sep 17 00:00:00 2001 From: Federico Blaseotto Date: Sun, 1 Dec 2024 23:18:44 +0100 Subject: [PATCH] Fix #256 - wrong limit calculation for DIFAT sectors - added unit test --- sources/OpenMcdf/CompoundFile.cs | 5 ++-- sources/OpenMcdf/OpenMcdf.csproj | 4 +-- sources/OpenMcdf/Properties/AssemblyInfo.cs | 4 +-- sources/Test/OpenMcdf.Test/CFStreamTest.cs | 33 +++++++++++++++++++++ 4 files changed, 40 insertions(+), 6 deletions(-) diff --git a/sources/OpenMcdf/CompoundFile.cs b/sources/OpenMcdf/CompoundFile.cs index 9d4e2de1..d07024d0 100644 --- a/sources/OpenMcdf/CompoundFile.cs +++ b/sources/OpenMcdf/CompoundFile.cs @@ -1042,8 +1042,9 @@ private void AllocateDIFATSectorChain(List FATsectorChain) nDIFATSectors = LowSaturation(nDIFATSectors - (int)header.DIFATSectorsNumber); //required DIFAT } - - for (int i = 0; i < (nDIFATSectors - difatSectors.Count); i++) + //for (int i = 0; i < (nDIFATSectors - difatSectors.Count); i++) + + for (int i = 0; i < nDIFATSectors; i++) { Sector s = new Sector(SectorSize, sourceStream); sectors.Add(s); diff --git a/sources/OpenMcdf/OpenMcdf.csproj b/sources/OpenMcdf/OpenMcdf.csproj index e13e53ea..5df84ac4 100644 --- a/sources/OpenMcdf/OpenMcdf.csproj +++ b/sources/OpenMcdf/OpenMcdf.csproj @@ -68,7 +68,7 @@ false true 0 - 2.2.1.9 + 2.4.1.0 true false true @@ -78,7 +78,7 @@ true - 2.4.0.0 + 2.4.1.0 ironfede https://github.com/ironfede/openmcdf diff --git a/sources/OpenMcdf/Properties/AssemblyInfo.cs b/sources/OpenMcdf/Properties/AssemblyInfo.cs index f2cddf67..e3fefb6e 100644 --- a/sources/OpenMcdf/Properties/AssemblyInfo.cs +++ b/sources/OpenMcdf/Properties/AssemblyInfo.cs @@ -8,7 +8,7 @@ [assembly: AssemblyDescription("OpenMcdf is a 100% .net / C# component that allows developers to manipulate Microsoft Compound Document File Format for OLE structured storage. It supports read/write operations on streams and storages and traversal of structures tree.")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Federico Blaseotto")] -[assembly: AssemblyProduct("OpenMcdf 2.3")] +[assembly: AssemblyProduct("OpenMcdf 2.4")] [assembly: AssemblyCopyright("Copyright © 2010-2024, Federico Blaseotto")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -31,7 +31,7 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.4.0.0")] +[assembly: AssemblyVersion("2.4.1.0")] [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("OpenMcdf.Tests,PublicKey=002400000480000094000000060200000024000052534131000400000100010085b50cbc1e40df696f8c30eaafc59a01e22303cb038fc832289b2c393f908a65c9aaa0d28026a47c6e5f85cc236f0735bea17236dbaaf91fea0003ddc1bb9c4cd318c5b855e7ef5877df5a7fc8394ee747d3573b69622e045837d546befb2fc13257e984db53a73dd59254a9a1d3c99a8ca6876c91304ea96899ac06a88d7bc6")] [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("OpenMcdf.Test,PublicKey=002400000480000094000000060200000024000052534131000400000100010085b50cbc1e40df696f8c30eaafc59a01e22303cb038fc832289b2c393f908a65c9aaa0d28026a47c6e5f85cc236f0735bea17236dbaaf91fea0003ddc1bb9c4cd318c5b855e7ef5877df5a7fc8394ee747d3573b69622e045837d546befb2fc13257e984db53a73dd59254a9a1d3c99a8ca6876c91304ea96899ac06a88d7bc6")] [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("OpenMcdf.Extensions,PublicKey=002400000480000094000000060200000024000052534131000400000100010085b50cbc1e40df696f8c30eaafc59a01e22303cb038fc832289b2c393f908a65c9aaa0d28026a47c6e5f85cc236f0735bea17236dbaaf91fea0003ddc1bb9c4cd318c5b855e7ef5877df5a7fc8394ee747d3573b69622e045837d546befb2fc13257e984db53a73dd59254a9a1d3c99a8ca6876c91304ea96899ac06a88d7bc6")] \ No newline at end of file diff --git a/sources/Test/OpenMcdf.Test/CFStreamTest.cs b/sources/Test/OpenMcdf.Test/CFStreamTest.cs index 4f76a617..27865061 100644 --- a/sources/Test/OpenMcdf.Test/CFStreamTest.cs +++ b/sources/Test/OpenMcdf.Test/CFStreamTest.cs @@ -1047,5 +1047,38 @@ public void TEST_RESIZE_STREAM_BUG_119() cf.Commit(); } } + + /// + /// Resize without transition to smaller chain has a wrong behavior + /// + [TestMethod] + public void TEST_ADD_STREAM_BUG_256() + { + string tempFile = @"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(); + } + } } }