Skip to content

Commit c626cac

Browse files
author
Sergey Shepshelevich
committed
Fix reading large XML coverage files (crash on 2GB files)
1 parent e1213cd commit c626cac

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/ReportGenerator.Core/Parser/CoverageReportParser.cs

+16-2
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,23 @@ private Task CreateProducer(IReadOnlyCollection<string> reportFiles, BlockingCol
186186
Logger.DebugFormat(Resources.LoadingReport, reportFile, number, reportFiles.Count);
187187
try
188188
{
189-
string line1 = File.ReadLines(reportFile).First();
189+
bool isXml = false;
190+
using (var sr = File.OpenText(reportFile))
191+
{
192+
// We need to read first non-space char in the file
193+
var buf = new char[120];
194+
while (sr.Read(buf, 0, buf.Length) > 0)
195+
{
196+
string block = new string(buf).TrimStart();
197+
if (block.Length > 0)
198+
{
199+
isXml = block.StartsWith("<");
200+
break;
201+
}
202+
}
203+
}
190204

191-
List<ParserResult> parserResults = line1.Trim().StartsWith("<")
205+
List<ParserResult> parserResults = isXml
192206
? this.ParseXmlFile(reportFile).ToList()
193207
: this.ParseTextFile(File.ReadAllLines(reportFile)).ToList();
194208
foreach (ParserResult parserResult in parserResults)

0 commit comments

Comments
 (0)