ExcelReaderFactory.CreateBinaryReader throws OutOfMemoryException
Metalnem opened this issue · comments
ExcelReaderFactory.CreateBinaryReader throws OutOfMemoryException after trying to open a 26KB invalid Excel file for more than 25s. The file can be found in the attached archive. You can run the following code to reproduce it (the path variable should contain the path to the extracted file):
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
using (var file = File.OpenRead(path))
{
ExcelReaderFactory.CreateBinaryReader(file);
}
Found via SharpFuzz.
"Next sector cannot be 0. Possibly corrupt excel file" the error message
The stack trace that I'm getting on macOS running .NET Core 2.1 looks like this:
An unhandled exception of type 'System.OutOfMemoryException' occurred in System.Private.CoreLib.dll
at System.Collections.Generic.List`1.set_Capacity(Int32 value)
at System.Collections.Generic.List`1.AddWithResize(T item)
at ExcelDataReader.Core.CompoundFormat.CompoundDocument.GetSectorChain(UInt32 sector, List`1 sectorTable)
at ExcelDataReader.Core.CompoundFormat.CompoundDocument..ctor(Stream stream)
at ExcelDataReader.ExcelReaderFactory.CreateBinaryReader(Stream fileStream, ExcelReaderConfiguration configuration)
at ExcelDataReader.Run.Program.Main(String[] args) in
@Metalnem Thanks for the report and repro! There is a problem where cyclic sector chains in the Compound Document parser are not handled.
@wizardgsz Looks like you are testing with ExcelDataReader 2.x? This case was handled before, but was removed around 3.0 - likely due to lack of test data. Although the original code looks to only handle certain kinds of circular chains: 4605ce8#diff-b7be87d681fb2b3432dc0dcca0c20840L80