Skip to content

Commit b912d7d

Browse files
committed
Fix Issue 2 - wrong cutoff ministream size
1 parent 2d10dd4 commit b912d7d

File tree

2 files changed

+65
-37
lines changed

2 files changed

+65
-37
lines changed

sources/OpenMcdf/CompoundFile.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2100,8 +2100,8 @@ internal void SetStreamLength(CFItem cfItem, long length)
21002100
if (cfItem.DirEntry.StartSetc != Sector.ENDOFCHAIN)
21012101
{
21022102
if (
2103-
(length < header.MinSizeStandardStream && cfItem.DirEntry.Size > header.MinSizeStandardStream)
2104-
|| (length > header.MinSizeStandardStream && cfItem.DirEntry.Size < header.MinSizeStandardStream)
2103+
(length < header.MinSizeStandardStream && cfItem.DirEntry.Size >= header.MinSizeStandardStream)
2104+
|| (length >= header.MinSizeStandardStream && cfItem.DirEntry.Size < header.MinSizeStandardStream)
21052105
)
21062106
{
21072107
if (cfItem.DirEntry.Size < header.MinSizeStandardStream)

sources/Test/OpenMcdf.Test/CompoundFileTest.cs

Lines changed: 63 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -783,39 +783,67 @@ public void Test_CORRUPTEDDOC_BUG36_SHOULD_THROW_CORRUPTED_FILE_EXCEPTION()
783783

784784
}
785785

786-
//[TestMethod]
787-
//public void Test_CORRUPTED_CYCLIC_DIFAT_VALIDATION_CHECK()
788-
//{
789-
790-
// CompoundFile cf = null;
791-
// try
792-
// {
793-
// cf = new CompoundFile("CiclycDFAT.cfs");
794-
// CFStorage s = cf.RootStorage.GetStorage("MyStorage");
795-
// CFStream st = s.GetStream("MyStream");
796-
// Assert.IsTrue(st.Size > 0);
797-
// }
798-
// catch (Exception ex)
799-
// {
800-
// Assert.IsTrue(ex is CFCorruptedFileException);
801-
// }
802-
// finally
803-
// {
804-
// if (cf != null)
805-
// {
806-
// cf.Close();
807-
// }
808-
// }
809-
//}
810-
//[TestMethod]
811-
//public void Test_REM()
812-
//{
813-
// var f = new CompoundFile();
814-
815-
// byte[] bB = Helpers.GetBuffer(5 * 1024, 0x0B);
816-
// f.RootStorage.AddStream("Test").AppendData(bB);
817-
// f.Save("Astorage.cfs");
818-
//}
819-
820-
}
786+
[TestMethod]
787+
public void Test_ISSUE_2_WRONG_CUTOFF_SIZE()
788+
{
789+
FileStream fs = null;
790+
try
791+
{
792+
if (File.Exists("TEST_ISSUE_2"))
793+
{
794+
File.Delete("TEST_ISSUE_2");
795+
}
796+
797+
CompoundFile cf = new CompoundFile(CFSVersion.Ver_3, CFSConfiguration.Default);
798+
var s = cf.RootStorage.AddStream("miniToNormal");
799+
s.Append(Helpers.GetBuffer(4090, 0xAA));
800+
801+
cf.Save("TEST_ISSUE_2");
802+
cf.Close();
803+
var cf2 = new CompoundFile("TEST_ISSUE_2",CFSUpdateMode.Update,CFSConfiguration.Default);
804+
cf2.RootStorage.GetStream("miniToNormal").Append(Helpers.GetBuffer(6, 0xBB));
805+
cf2.Commit();
806+
cf2.Close();
807+
}
808+
catch (Exception ex)
809+
{
810+
Assert.IsTrue(fs.CanRead && fs.CanSeek && fs.CanWrite);
811+
}
812+
}
813+
814+
//[TestMethod]
815+
//public void Test_CORRUPTED_CYCLIC_DIFAT_VALIDATION_CHECK()
816+
//{
817+
818+
// CompoundFile cf = null;
819+
// try
820+
// {
821+
// cf = new CompoundFile("CiclycDFAT.cfs");
822+
// CFStorage s = cf.RootStorage.GetStorage("MyStorage");
823+
// CFStream st = s.GetStream("MyStream");
824+
// Assert.IsTrue(st.Size > 0);
825+
// }
826+
// catch (Exception ex)
827+
// {
828+
// Assert.IsTrue(ex is CFCorruptedFileException);
829+
// }
830+
// finally
831+
// {
832+
// if (cf != null)
833+
// {
834+
// cf.Close();
835+
// }
836+
// }
837+
//}
838+
//[TestMethod]
839+
//public void Test_REM()
840+
//{
841+
// var f = new CompoundFile();
842+
843+
// byte[] bB = Helpers.GetBuffer(5 * 1024, 0x0B);
844+
// f.RootStorage.AddStream("Test").AppendData(bB);
845+
// f.Save("Astorage.cfs");
846+
//}
847+
848+
}
821849
}

0 commit comments

Comments
 (0)