Skip to content

ExcelReaderFactory.CreateBinaryReader throws OutOfMemoryException #382

Description

@Metalnem

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.

Activity

  1. wizardgsz commented on Dec 28, 2018

    @wizardgsz
    Collaborator

    "Next sector cannot be 0. Possibly corrupt excel file" the error message

  2. Metalnem commented on Dec 28, 2018

    @Metalnem
    Author

    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
    
  3. andersnm commented on Dec 28, 2018

    @andersnm
    Collaborator

    @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

  4. added a commit that references this issue on Mar 28, 2024
    3810fbb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions