diff --git a/sources/OpenMcdf/CompoundFile.cs b/sources/OpenMcdf/CompoundFile.cs index 698ac9e8..8925cd6c 100644 --- a/sources/OpenMcdf/CompoundFile.cs +++ b/sources/OpenMcdf/CompoundFile.cs @@ -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) diff --git a/sources/Test/OpenMcdf.Test/CompoundFileTest.cs b/sources/Test/OpenMcdf.Test/CompoundFileTest.cs index fd63af88..ccc5ee5c 100644 --- a/sources/Test/OpenMcdf.Test/CompoundFileTest.cs +++ b/sources/Test/OpenMcdf.Test/CompoundFileTest.cs @@ -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"); + //} + + } }