From ce32b7c0f26251ee13a147a383bae598a7b39cc8 Mon Sep 17 00:00:00 2001 From: danielpalme Date: Sat, 12 Aug 2023 19:04:56 +0200 Subject: [PATCH] #619 Improved report parsing to avoid integer overflow --- src/Readme.txt | 4 ++++ src/ReportGenerator.Core/Parser/CloverParser.cs | 4 ++-- src/ReportGenerator.Core/Parser/CoberturaParser.cs | 4 ++-- .../Parser/DynamicCodeCoverageParser.cs | 5 +++-- src/ReportGenerator.Core/Parser/JaCoCoParser.cs | 9 +++++---- src/ReportGenerator.Core/Parser/LCovParser.cs | 2 +- src/ReportGenerator.Core/Parser/OpenCoverParser.cs | 2 +- src/ReportGenerator.Core/Parser/VisualStudioParser.cs | 5 +++-- 8 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/Readme.txt b/src/Readme.txt index e455aa32..24e51af6 100644 --- a/src/Readme.txt +++ b/src/Readme.txt @@ -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 diff --git a/src/ReportGenerator.Core/Parser/CloverParser.cs b/src/ReportGenerator.Core/Parser/CloverParser.cs index 6888fa4d..0515834b 100644 --- a/src/ReportGenerator.Core/Parser/CloverParser.cs +++ b/src/ReportGenerator.Core/Parser/CloverParser.cs @@ -217,8 +217,8 @@ private static Dictionary> GetBranches(IEnumerable> GetBranches(IEnumerable(); diff --git a/src/ReportGenerator.Core/Parser/DynamicCodeCoverageParser.cs b/src/ReportGenerator.Core/Parser/DynamicCodeCoverageParser.cs index 74b4ae8f..a447bc4d 100644 --- a/src/ReportGenerator.Core/Parser/DynamicCodeCoverageParser.cs +++ b/src/ReportGenerator.Core/Parser/DynamicCodeCoverageParser.cs @@ -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; @@ -263,8 +264,8 @@ private static void SetMethodMetrics(CodeFile codeFile, IEnumerable 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); diff --git a/src/ReportGenerator.Core/Parser/JaCoCoParser.cs b/src/ReportGenerator.Core/Parser/JaCoCoParser.cs index 10fadc65..7e82e876 100644 --- a/src/ReportGenerator.Core/Parser/JaCoCoParser.cs +++ b/src/ReportGenerator.Core/Parser/JaCoCoParser.cs @@ -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; @@ -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(); diff --git a/src/ReportGenerator.Core/Parser/LCovParser.cs b/src/ReportGenerator.Core/Parser/LCovParser.cs index 1587d5b3..0c916353 100644 --- a/src/ReportGenerator.Core/Parser/LCovParser.cs +++ b/src/ReportGenerator.Core/Parser/LCovParser.cs @@ -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 branches = null; diff --git a/src/ReportGenerator.Core/Parser/OpenCoverParser.cs b/src/ReportGenerator.Core/Parser/OpenCoverParser.cs index 4388e7b7..1025a72b 100644 --- a/src/ReportGenerator.Core/Parser/OpenCoverParser.cs +++ b/src/ReportGenerator.Core/Parser/OpenCoverParser.cs @@ -467,7 +467,7 @@ private static Dictionary> 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)) { diff --git a/src/ReportGenerator.Core/Parser/VisualStudioParser.cs b/src/ReportGenerator.Core/Parser/VisualStudioParser.cs index fc96cee8..95a45458 100644 --- a/src/ReportGenerator.Core/Parser/VisualStudioParser.cs +++ b/src/ReportGenerator.Core/Parser/VisualStudioParser.cs @@ -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; @@ -251,8 +252,8 @@ private static void SetMethodMetrics(CodeFile codeFile, IEnumerable 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);