Skip to content

System.OverflowException for ParseInt32[Bug] #2390

@OatmealOgre

Description

@OatmealOgre

Describe the bug
When gitversion tries to parse a prerelease tag followed by a 10+ digit number an exception is thrown.

Expected Behavior

Gitversion should catch the exception and handle it some other way

Actual Behavior

Gitversion doesn't handle any exceptions inside a method called TryParse

Possible Fix

Make TryParse method of GitVersionCore/VersionCalculation/SemanticVersioning/SemanticVersion.cs actually use a try-catch as the name would suggest.
Alternatively have GitVersionCore/VersionCalculation/SemanticVersioning/SemanticVersionPreReleaseTag.cs Parse method use a TryParse for parsing the Int

Steps to Reproduce

Use a tag with a long number in it. Ours has been automated.
Here's the exception along with the tag that likely caused the issue:

System.OverflowException: Value was either too large or too small for an Int32.
   at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
   at GitVersion.SemanticVersionPreReleaseTag.Parse(String preReleaseTag)
   at GitVersion.SemanticVersion.TryParse(String version, String tagPrefixRegex, SemanticVersion& semanticVersion)
   at GitVersion.GitRepoMetadataProvider.GetValidVersionTags(IRepository repository, String tagPrefixRegex, Nullable`1 olderThan)
   at GitVersion.VersionCalculation.BaseVersionCalculators.TaggedCommitVersionStrategy.GetTaggedVersions(GitVersionContext context, Branch currentBranch, Nullable`1 olderThan)
   at GitVersion.VersionCalculation.BaseVersionCalculators.TaggedCommitVersionStrategy.GetVersions(GitVersionContext context)
   at System.Linq.Enumerable.<SelectManyIterator>d__17`2.MoveNext()
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at GitVersion.VersionCalculation.BaseVersionCalculator.GetBaseVersion(GitVersionContext context)
   at GitVersion.VersionCalculation.NextVersionCalculator.FindVersion(GitVersionContext context)
   at GitVersion.GitVersionFinder.FindVersion(GitVersionContext context)
   at GitVersion.ExecuteCore.<>c__DisplayClass7_0.<ExecuteInternal>b__0(IRepository repo)
   at GitVersion.GitPreparer.WithRepository[TResult](Func`2 action)
   at GitVersion.ExecuteCore.ExecuteGitVersion(String targetUrl, String dynamicRepositoryLocation, Authentication authentication, String targetBranch, Boolean noFetch, String workingDirectory, String commitId, Config overrideConfig, Boolean noCache)
   at GitVersion.SpecifiedArgumentRunner.Run(Arguments arguments, IFileSystem fileSystem)
   at GitVersion.Program.VerifyArgumentsAndRun()
  INFO [08/21/20 7:08:34:93] 
  INFO [08/21/20 7:08:34:93] Attempting to show the current git graph (please include in issue): 
  INFO [08/21/20 7:08:34:93] Showing max of 100 commits
  INFO [08/21/20 7:08:34:99] *   a401875 18 hours ago  (HEAD -> pull/22012/merge, pull/22012/merge)
|\  
| * 38895d1 18 hours ago  (origin/573637-fix-gitversion-issue, 573637-fix-gitversion-issue)
| * be84a2e 20 hours ago 
|/  
| *   5a4a29d 21 hours ago  (tag: 5.2.14, origin/release, release)
| |\  
| |/  
|/|   
| | *   513ba3f 4 days ago  (tag: 5.2.14-PullRequest2189021890, tag: 5.2.14-PullRequest21890.5)
| | |\ 

Context

Our CI build pipeline fails and we are unable to rebuild

Your Environment

Azure DevOps Task. Gitversion is 5.01 there, however this issue is also present in more recent versions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions