Skip to content

Commit

Permalink
#619 Improved report parsing to avoid integer overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpalme committed Aug 12, 2023
1 parent 255553e commit ce32b7c
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 14 deletions.
4 changes: 4 additions & 0 deletions src/Readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ For further details take a look at LICENSE.txt.

CHANGELOG

5.1.24.0

* Fix: #619 Improved report parsing to avoid integer overflow

5.1.23.0

* New: Added minimum coverage thresholds to validate coverage goals
Expand Down
4 changes: 2 additions & 2 deletions src/ReportGenerator.Core/Parser/CloverParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ private static Dictionary<int, ICollection<Branch>> GetBranches(IEnumerable<XEle

int lineNumber = int.Parse(line.Attribute("num").Value, CultureInfo.InvariantCulture);

int negativeBrancheCovered = int.Parse(line.Attribute("falsecount").Value, CultureInfo.InvariantCulture);
int positiveBrancheCovered = int.Parse(line.Attribute("truecount").Value, CultureInfo.InvariantCulture);
int negativeBrancheCovered = line.Attribute("falsecount").Value.ParseLargeInteger();
int positiveBrancheCovered = line.Attribute("truecount").Value.ParseLargeInteger();

if (result.ContainsKey(lineNumber))
{
Expand Down
4 changes: 2 additions & 2 deletions src/ReportGenerator.Core/Parser/CoberturaParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,8 @@ private static Dictionary<int, ICollection<Branch>> GetBranches(IEnumerable<XEle
{
int lineNumber = int.Parse(line.Attribute("number").Value, CultureInfo.InvariantCulture);

int numberOfCoveredBranches = int.Parse(match.Groups["NumberOfCoveredBranches"].Value, CultureInfo.InvariantCulture);
int numberOfTotalBranches = int.Parse(match.Groups["NumberOfTotalBranches"].Value, CultureInfo.InvariantCulture);
int numberOfCoveredBranches = match.Groups["NumberOfCoveredBranches"].Value.ParseLargeInteger();
int numberOfTotalBranches = match.Groups["NumberOfTotalBranches"].Value.ParseLargeInteger();

var branches = new HashSet<Branch>();

Expand Down
5 changes: 3 additions & 2 deletions src/ReportGenerator.Core/Parser/DynamicCodeCoverageParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Xml.Linq;
using Palmmedia.ReportGenerator.Core.Common;
using Palmmedia.ReportGenerator.Core.Logging;
using Palmmedia.ReportGenerator.Core.Parser.Analysis;
using Palmmedia.ReportGenerator.Core.Parser.Filtering;
Expand Down Expand Up @@ -263,8 +264,8 @@ private static void SetMethodMetrics(CodeFile codeFile, IEnumerable<XElement> me

var metrics = new[]
{
Metric.BlocksCovered(int.Parse(method.Attribute("blocks_covered").Value, CultureInfo.InvariantCulture)),
Metric.BlocksNotCovered(int.Parse(method.Attribute("blocks_not_covered").Value, CultureInfo.InvariantCulture))
Metric.BlocksCovered(method.Attribute("blocks_covered").Value.ParseLargeInteger()),
Metric.BlocksNotCovered(method.Attribute("blocks_not_covered").Value.ParseLargeInteger())
};

var methodMetric = new MethodMetric(fullName, shortName, metrics);
Expand Down
9 changes: 5 additions & 4 deletions src/ReportGenerator.Core/Parser/JaCoCoParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Xml.Linq;
using Palmmedia.ReportGenerator.Core.Common;
using Palmmedia.ReportGenerator.Core.Logging;
using Palmmedia.ReportGenerator.Core.Parser.Analysis;
using Palmmedia.ReportGenerator.Core.Parser.Filtering;
Expand Down Expand Up @@ -182,10 +183,10 @@ private static CodeFile ProcessFile(XElement[] modules, Class @class, string fil
.Select(line => new JaCoCoLineCoverage()
{
LineNumber = int.Parse(line.Attribute("nr").Value, CultureInfo.InvariantCulture),
MissedInstructions = int.Parse(line.Attribute("mi")?.Value ?? "0", CultureInfo.InvariantCulture),
CoveredInstructions = int.Parse(line.Attribute("ci")?.Value ?? "0", CultureInfo.InvariantCulture),
MissedBranches = int.Parse(line.Attribute("mb")?.Value ?? "0", CultureInfo.InvariantCulture),
CoveredBranches = int.Parse(line.Attribute("cb")?.Value ?? "0", CultureInfo.InvariantCulture)
MissedInstructions = (line.Attribute("mi")?.Value ?? "0").ParseLargeInteger(),
CoveredInstructions = (line.Attribute("ci")?.Value ?? "0").ParseLargeInteger(),
MissedBranches = (line.Attribute("mb")?.Value ?? "0").ParseLargeInteger(),
CoveredBranches = (line.Attribute("cb")?.Value ?? "0").ParseLargeInteger()
})
.OrderBy(seqpnt => seqpnt.LineNumber)
.ToArray();
Expand Down
2 changes: 1 addition & 1 deletion src/ReportGenerator.Core/Parser/LCovParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private void ProcessClass(Class @class, string fileName, string[] lines, ref int
int lineNumber = int.Parse(tokens[0], CultureInfo.InvariantCulture);

var branch = new Branch(
"-".Equals(tokens[3]) ? 0 : int.Parse(tokens[3], CultureInfo.InvariantCulture),
"-".Equals(tokens[3]) ? 0 : tokens[3].ParseLargeInteger(),
$"{tokens[0]}_{tokens[1]}_{tokens[2]}");

ICollection<Branch> branches = null;
Expand Down
2 changes: 1 addition & 1 deletion src/ReportGenerator.Core/Parser/OpenCoverParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ private static Dictionary<int, ICollection<Branch>> GetBranches(XElement[] metho
branchPoint.Attribute("path").Value,
branchPoint.Attribute("offset").Value,
branchPoint.Attribute("offsetend").Value);
int vc = int.Parse(branchPoint.Attribute("vc").Value, CultureInfo.InvariantCulture);
int vc = branchPoint.Attribute("vc").Value.ParseLargeInteger();

if (result.TryGetValue(lineNumber, out var branches))
{
Expand Down
5 changes: 3 additions & 2 deletions src/ReportGenerator.Core/Parser/VisualStudioParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Xml.Linq;
using Palmmedia.ReportGenerator.Core.Common;
using Palmmedia.ReportGenerator.Core.Logging;
using Palmmedia.ReportGenerator.Core.Parser.Analysis;
using Palmmedia.ReportGenerator.Core.Parser.Filtering;
Expand Down Expand Up @@ -251,8 +252,8 @@ private static void SetMethodMetrics(CodeFile codeFile, IEnumerable<XElement> me

var metrics = new[]
{
Metric.BlocksCovered(int.Parse(method.Element("BlocksCovered").Value, CultureInfo.InvariantCulture)),
Metric.BlocksNotCovered(int.Parse(method.Element("BlocksNotCovered").Value, CultureInfo.InvariantCulture))
Metric.BlocksCovered(method.Element("BlocksCovered").Value.ParseLargeInteger()),
Metric.BlocksNotCovered(method.Element("BlocksNotCovered").Value.ParseLargeInteger())
};

var methodMetric = new MethodMetric(fullName, shortName, metrics);
Expand Down

0 comments on commit ce32b7c

Please sign in to comment.