Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.OutOfMemoryException from CsvParser.FillBuffer #2306

Open
michaeldahlke opened this issue Dec 16, 2024 · 0 comments
Open

System.OutOfMemoryException from CsvParser.FillBuffer #2306

michaeldahlke opened this issue Dec 16, 2024 · 0 comments
Labels

Comments

@michaeldahlke
Copy link

Describe the bug
Trying to read a very large file that is not correctly formatted as CSV may result in an out of memory exception when calling Read().

To Reproduce

// create a large file using cmd.exe
// fsutil file createnew 1gb.tst 1073741824

const string filePath = @"C:\1gb.tst";

try
{
    using (var stream = File.OpenRead(filePath))
    {
        using (var csvReader = new CsvReader(new StreamReader(stream), CultureInfo.InvariantCulture))
        {
            csvReader.Read();
        }
    }
}
catch (CsvHelperException)
{
    // pass
}
catch (OutOfMemoryException)
{
    // fail
}

Expected behavior
CsvHelper does not use an excessive amount of memory and a more appropriate exception such as BadDataException is thrown.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant