Skip to content

Commit 03ef8cb

Browse files
committed
Fix #256 - wrong limit calculation for DIFAT sectors - added unit test
1 parent 2a0b20b commit 03ef8cb

File tree

4 files changed

+40
-6
lines changed

4 files changed

+40
-6
lines changed

sources/OpenMcdf/CompoundFile.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,8 +1042,9 @@ private void AllocateDIFATSectorChain(List<Sector> FATsectorChain)
10421042
nDIFATSectors = LowSaturation(nDIFATSectors - (int)header.DIFATSectorsNumber); //required DIFAT
10431043
}
10441044

1045-
1046-
for (int i = 0; i < (nDIFATSectors - difatSectors.Count); i++)
1045+
//for (int i = 0; i < (nDIFATSectors - difatSectors.Count); i++)
1046+
1047+
for (int i = 0; i < nDIFATSectors; i++)
10471048
{
10481049
Sector s = new Sector(SectorSize, sourceStream);
10491050
sectors.Add(s);

sources/OpenMcdf/OpenMcdf.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
<UpdateRequired>false</UpdateRequired>
6969
<MapFileExtensions>true</MapFileExtensions>
7070
<ApplicationRevision>0</ApplicationRevision>
71-
<ApplicationVersion>2.2.1.9</ApplicationVersion>
71+
<ApplicationVersion>2.4.1.0</ApplicationVersion>
7272
<IsWebBootstrapper>true</IsWebBootstrapper>
7373
<UseApplicationTrust>false</UseApplicationTrust>
7474
<BootstrapperEnabled>true</BootstrapperEnabled>
@@ -78,7 +78,7 @@
7878
</PropertyGroup>
7979
<PropertyGroup>
8080
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
81-
<Version>2.4.0.0</Version>
81+
<Version>2.4.1.0</Version>
8282
<Authors>ironfede</Authors>
8383
<PackageProjectUrl>https://github.com/ironfede/openmcdf</PackageProjectUrl>
8484
<PackageIconUrl></PackageIconUrl>

sources/OpenMcdf/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
[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.")]
99
[assembly: AssemblyConfiguration("")]
1010
[assembly: AssemblyCompany("Federico Blaseotto")]
11-
[assembly: AssemblyProduct("OpenMcdf 2.3")]
11+
[assembly: AssemblyProduct("OpenMcdf 2.4")]
1212
[assembly: AssemblyCopyright("Copyright © 2010-2024, Federico Blaseotto")]
1313
[assembly: AssemblyTrademark("")]
1414
[assembly: AssemblyCulture("")]
@@ -31,7 +31,7 @@
3131
// You can specify all the values or you can default the Build and Revision Numbers
3232
// by using the '*' as shown below:
3333
// [assembly: AssemblyVersion("1.0.*")]
34-
[assembly: AssemblyVersion("2.4.0.0")]
34+
[assembly: AssemblyVersion("2.4.1.0")]
3535
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("OpenMcdf.Tests,PublicKey=002400000480000094000000060200000024000052534131000400000100010085b50cbc1e40df696f8c30eaafc59a01e22303cb038fc832289b2c393f908a65c9aaa0d28026a47c6e5f85cc236f0735bea17236dbaaf91fea0003ddc1bb9c4cd318c5b855e7ef5877df5a7fc8394ee747d3573b69622e045837d546befb2fc13257e984db53a73dd59254a9a1d3c99a8ca6876c91304ea96899ac06a88d7bc6")]
3636
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("OpenMcdf.Test,PublicKey=002400000480000094000000060200000024000052534131000400000100010085b50cbc1e40df696f8c30eaafc59a01e22303cb038fc832289b2c393f908a65c9aaa0d28026a47c6e5f85cc236f0735bea17236dbaaf91fea0003ddc1bb9c4cd318c5b855e7ef5877df5a7fc8394ee747d3573b69622e045837d546befb2fc13257e984db53a73dd59254a9a1d3c99a8ca6876c91304ea96899ac06a88d7bc6")]
3737
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("OpenMcdf.Extensions,PublicKey=002400000480000094000000060200000024000052534131000400000100010085b50cbc1e40df696f8c30eaafc59a01e22303cb038fc832289b2c393f908a65c9aaa0d28026a47c6e5f85cc236f0735bea17236dbaaf91fea0003ddc1bb9c4cd318c5b855e7ef5877df5a7fc8394ee747d3573b69622e045837d546befb2fc13257e984db53a73dd59254a9a1d3c99a8ca6876c91304ea96899ac06a88d7bc6")]

sources/Test/OpenMcdf.Test/CFStreamTest.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,5 +1047,38 @@ public void TEST_RESIZE_STREAM_BUG_119()
10471047
cf.Commit();
10481048
}
10491049
}
1050+
1051+
/// <summary>
1052+
/// Resize without transition to smaller chain has a wrong behavior
1053+
/// </summary>
1054+
[TestMethod]
1055+
public void TEST_ADD_STREAM_BUG_256()
1056+
{
1057+
string tempFile = @"OpenMCDFCrash.dat";
1058+
1059+
// create big MCDF file
1060+
CFSVersion version = CFSVersion.Ver_3;
1061+
CFSConfiguration configuration = CFSConfiguration.Default;
1062+
CFSUpdateMode updateMode = CFSUpdateMode.Update;
1063+
1064+
using (CompoundFile compoundFile = new CompoundFile(version, configuration))
1065+
{
1066+
compoundFile.SaveAs(tempFile);
1067+
compoundFile.Close();
1068+
}
1069+
1070+
using (var compoundFile = new CompoundFile(tempFile, updateMode, configuration))
1071+
{
1072+
byte[] data = new byte[6617123];
1073+
1074+
for (int i = 0; i < 100; i++)
1075+
{
1076+
var cfStream = compoundFile.RootStorage.AddStream($"Stream {i}.dat");
1077+
cfStream.SetData(data);
1078+
}
1079+
1080+
compoundFile.Commit();
1081+
}
1082+
}
10501083
}
10511084
}

0 commit comments

Comments
 (0)