ironfede / openmcdf

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

CFStreams cannot be larger than 2GB #15

Closed ArminFirecracker closed 6 years ago

ArminFirecracker commented 6 years ago

As I see, CFStreams cannot be larger than 2GB? Running the test code, I get an Exception. Probably it is not intended to support such large streams?

In StreamView.cs, line 319:

                    Buffer.BlockCopy(
                        buffer,
                        offset,
                        sectorChain[secOffset].GetData(),
                        secShift,
                        roundByteWritten
                        );

Exception:

System.ArgumentOutOfRangeException: 'Non-negative number required.

Test code:

            String filename = "MyFile.dat";
            String storageName = "MyStorage";
            String streamName = "MyStream";
            int bufferSize = 500000000;
            int iterationCount = 6;
            int streamCount = 1;

            CompoundFile compoundFile = new CompoundFile(CFSVersion.Ver_4, CFSConfiguration.Default);
            CFStorage st = compoundFile.RootStorage.AddStorage(storageName);

            for (int streamId = 0; streamId < streamCount; ++streamId)
            {
                CFStream sm = st.AddStream(streamName + streamId);
                for (int iteration = 0; iteration < iterationCount; ++iteration)
                {
                    sm.Append(new byte[bufferSize]);
                }
            }
            compoundFile.Save(filename);
            compoundFile.Close();

And thank you, for your fast respond on https://github.com/ironfede/openmcdf/issues/14!

ironfede commented 6 years ago

Committed to master bug fix and unit test. Many thanks ArminFirecracker. Please , let me know if you find other stream/file size issues. Release will follow asap. Best Regards, Federico