From b857ada92bed3d9a2e1c55d2aca35beec60535bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Sat, 9 Aug 2025 01:09:18 +0200 Subject: [PATCH] Limit search pattern and directory recursion Narrow the scope of the search pattern to only include project files and limit directory recursion to 255 subdirectories to avoid infinite loops and subsequent `PathTooLongException`. May fix GH-4411. --- .../AssemblyInfo/ProjectFileUpdater.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/GitVersion.Output/AssemblyInfo/ProjectFileUpdater.cs b/src/GitVersion.Output/AssemblyInfo/ProjectFileUpdater.cs index 375e37ad75..797cbc12ba 100644 --- a/src/GitVersion.Output/AssemblyInfo/ProjectFileUpdater.cs +++ b/src/GitVersion.Output/AssemblyInfo/ProjectFileUpdater.cs @@ -12,6 +12,8 @@ internal interface IProjectFileUpdater : IVersionConverter; internal sealed class ProjectFileUpdater(ILog log, IFileSystem fileSystem) : IProjectFileUpdater { internal const string AssemblyVersionElement = "AssemblyVersion"; + + private const int DefaultMaxRecursionDepth = 255; private const string FileVersionElement = "FileVersion"; private const string InformationalVersionElement = "InformationalVersion"; private const string VersionElement = "Version"; @@ -190,11 +192,18 @@ private IEnumerable GetProjectFiles(AssemblyInfoContext context) } else { - foreach (var item in fileSystem.Directory.EnumerateFiles(workingDirectory, "*", SearchOption.AllDirectories).Where(IsSupportedProjectFile)) + var options = new EnumerationOptions { - var assemblyInfoFile = fileSystem.FileInfo.New(item); - - yield return assemblyInfoFile; + RecurseSubdirectories = true, + MaxRecursionDepth = DefaultMaxRecursionDepth + }; + var projectFiles = fileSystem.Directory + .EnumerateFiles(workingDirectory, "*proj", options) + .Where(IsSupportedProjectFile); + + foreach (var projectFile in projectFiles) + { + yield return fileSystem.FileInfo.New(projectFile); } } }