Skip to content

Commit

Permalink
Fix #256 - wrong limit calculation for DIFAT sectors - added unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
ironfede committed Dec 1, 2024
1 parent 2a0b20b commit 03ef8cb
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
5 changes: 3 additions & 2 deletions sources/OpenMcdf/CompoundFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1042,8 +1042,9 @@ private void AllocateDIFATSectorChain(List<Sector> 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);
Expand Down
4 changes: 2 additions & 2 deletions sources/OpenMcdf/OpenMcdf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>2.2.1.9</ApplicationVersion>
<ApplicationVersion>2.4.1.0</ApplicationVersion>
<IsWebBootstrapper>true</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
Expand All @@ -78,7 +78,7 @@
</PropertyGroup>
<PropertyGroup>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>2.4.0.0</Version>
<Version>2.4.1.0</Version>
<Authors>ironfede</Authors>
<PackageProjectUrl>https://github.com/ironfede/openmcdf</PackageProjectUrl>
<PackageIconUrl></PackageIconUrl>
Expand Down
4 changes: 2 additions & 2 deletions sources/OpenMcdf/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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("")]
Expand All @@ -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")]
33 changes: 33 additions & 0 deletions sources/Test/OpenMcdf.Test/CFStreamTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1047,5 +1047,38 @@ public void TEST_RESIZE_STREAM_BUG_119()
cf.Commit();
}
}

/// <summary>
/// Resize without transition to smaller chain has a wrong behavior
/// </summary>
[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();
}
}
}
}

0 comments on commit 03ef8cb

Please sign in to comment.