Skip to content

Commit

Permalink
Fix Issue 2 - wrong cutoff ministream size
Browse files Browse the repository at this point in the history
  • Loading branch information
ironfede committed Mar 17, 2017
1 parent 2d10dd4 commit b912d7d
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 37 deletions.
4 changes: 2 additions & 2 deletions sources/OpenMcdf/CompoundFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2100,8 +2100,8 @@ internal void SetStreamLength(CFItem cfItem, long length)
if (cfItem.DirEntry.StartSetc != Sector.ENDOFCHAIN)
{
if (
(length < header.MinSizeStandardStream && cfItem.DirEntry.Size > header.MinSizeStandardStream)
|| (length > header.MinSizeStandardStream && cfItem.DirEntry.Size < header.MinSizeStandardStream)
(length < header.MinSizeStandardStream && cfItem.DirEntry.Size >= header.MinSizeStandardStream)
|| (length >= header.MinSizeStandardStream && cfItem.DirEntry.Size < header.MinSizeStandardStream)
)
{
if (cfItem.DirEntry.Size < header.MinSizeStandardStream)
Expand Down
98 changes: 63 additions & 35 deletions sources/Test/OpenMcdf.Test/CompoundFileTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -783,39 +783,67 @@ public void Test_CORRUPTEDDOC_BUG36_SHOULD_THROW_CORRUPTED_FILE_EXCEPTION()

}

//[TestMethod]
//public void Test_CORRUPTED_CYCLIC_DIFAT_VALIDATION_CHECK()
//{

// CompoundFile cf = null;
// try
// {
// cf = new CompoundFile("CiclycDFAT.cfs");
// CFStorage s = cf.RootStorage.GetStorage("MyStorage");
// CFStream st = s.GetStream("MyStream");
// Assert.IsTrue(st.Size > 0);
// }
// catch (Exception ex)
// {
// Assert.IsTrue(ex is CFCorruptedFileException);
// }
// finally
// {
// if (cf != null)
// {
// cf.Close();
// }
// }
//}
//[TestMethod]
//public void Test_REM()
//{
// var f = new CompoundFile();

// byte[] bB = Helpers.GetBuffer(5 * 1024, 0x0B);
// f.RootStorage.AddStream("Test").AppendData(bB);
// f.Save("Astorage.cfs");
//}

}
[TestMethod]
public void Test_ISSUE_2_WRONG_CUTOFF_SIZE()
{
FileStream fs = null;
try
{
if (File.Exists("TEST_ISSUE_2"))
{
File.Delete("TEST_ISSUE_2");
}

CompoundFile cf = new CompoundFile(CFSVersion.Ver_3, CFSConfiguration.Default);
var s = cf.RootStorage.AddStream("miniToNormal");
s.Append(Helpers.GetBuffer(4090, 0xAA));

cf.Save("TEST_ISSUE_2");
cf.Close();
var cf2 = new CompoundFile("TEST_ISSUE_2",CFSUpdateMode.Update,CFSConfiguration.Default);
cf2.RootStorage.GetStream("miniToNormal").Append(Helpers.GetBuffer(6, 0xBB));
cf2.Commit();
cf2.Close();
}
catch (Exception ex)
{
Assert.IsTrue(fs.CanRead && fs.CanSeek && fs.CanWrite);
}
}

//[TestMethod]
//public void Test_CORRUPTED_CYCLIC_DIFAT_VALIDATION_CHECK()
//{

// CompoundFile cf = null;
// try
// {
// cf = new CompoundFile("CiclycDFAT.cfs");
// CFStorage s = cf.RootStorage.GetStorage("MyStorage");
// CFStream st = s.GetStream("MyStream");
// Assert.IsTrue(st.Size > 0);
// }
// catch (Exception ex)
// {
// Assert.IsTrue(ex is CFCorruptedFileException);
// }
// finally
// {
// if (cf != null)
// {
// cf.Close();
// }
// }
//}
//[TestMethod]
//public void Test_REM()
//{
// var f = new CompoundFile();

// byte[] bB = Helpers.GetBuffer(5 * 1024, 0x0B);
// f.RootStorage.AddStream("Test").AppendData(bB);
// f.Save("Astorage.cfs");
//}

}
}

0 comments on commit b912d7d

Please sign in to comment.