ironfede / openmcdf

Microsoft Compound File .net component - pure C# - netstandard 2.0
Mozilla Public License 2.0
295 stars 72 forks source link

CFSStream.Resize does not work #119

Closed trash256 closed 4 months ago

trash256 commented 4 months ago
    public void Test()
    {
        var cf = new CompoundFile();
        const string DATA = "data";
        var st = cf.RootStorage.AddStream(DATA);
        const int size = 10;
        var data = Enumerable.Range(0, size).Select(v => (byte)v).ToArray();
        st.SetData(data);
        var ms = new MemoryStream();
        cf.Save(ms);
        cf.Close();

        ms.Position = 0;
        cf = new CompoundFile(ms, CFSUpdateMode.Update, CFSConfiguration.Default);
        st = cf.RootStorage.GetStream(DATA);
        st.Resize(5);   // <- can be any number smaller than the current size
        st.Write(new byte[] { 0 }, 0); // <- exception here!
        cf.Commit();
        cf.Close();
    }

Looks like truncating the stream does not work.

ironfede commented 4 months ago

Thank you @trash256 This is a really high priority bug. I'm going to immediately relase a new nuget package. Best Regards, Federico