Skip to content

Commit

Permalink
Fix reading large XML coverage files (crash on 2GB files)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Shepshelevich committed Jun 1, 2020
1 parent e1213cd commit c626cac
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/ReportGenerator.Core/Parser/CoverageReportParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,23 @@ private Task CreateProducer(IReadOnlyCollection<string> reportFiles, BlockingCol
Logger.DebugFormat(Resources.LoadingReport, reportFile, number, reportFiles.Count);
try
{
string line1 = File.ReadLines(reportFile).First();
bool isXml = false;
using (var sr = File.OpenText(reportFile))
{
// We need to read first non-space char in the file
var buf = new char[120];
while (sr.Read(buf, 0, buf.Length) > 0)
{
string block = new string(buf).TrimStart();
if (block.Length > 0)
{
isXml = block.StartsWith("<");
break;
}
}
}
List<ParserResult> parserResults = line1.Trim().StartsWith("<")
List<ParserResult> parserResults = isXml
? this.ParseXmlFile(reportFile).ToList()
: this.ParseTextFile(File.ReadAllLines(reportFile)).ToList();
foreach (ParserResult parserResult in parserResults)
Expand Down

0 comments on commit c626cac

Please sign in to comment.