Skip to content

Commit b857ada

Browse files
asbjornuarturcic
authored andcommitted
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.
1 parent 1b31f6a commit b857ada

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/GitVersion.Output/AssemblyInfo/ProjectFileUpdater.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ internal interface IProjectFileUpdater : IVersionConverter<AssemblyInfoContext>;
1212
internal sealed class ProjectFileUpdater(ILog log, IFileSystem fileSystem) : IProjectFileUpdater
1313
{
1414
internal const string AssemblyVersionElement = "AssemblyVersion";
15+
16+
private const int DefaultMaxRecursionDepth = 255;
1517
private const string FileVersionElement = "FileVersion";
1618
private const string InformationalVersionElement = "InformationalVersion";
1719
private const string VersionElement = "Version";
@@ -190,11 +192,18 @@ private IEnumerable<IFileInfo> GetProjectFiles(AssemblyInfoContext context)
190192
}
191193
else
192194
{
193-
foreach (var item in fileSystem.Directory.EnumerateFiles(workingDirectory, "*", SearchOption.AllDirectories).Where(IsSupportedProjectFile))
195+
var options = new EnumerationOptions
194196
{
195-
var assemblyInfoFile = fileSystem.FileInfo.New(item);
196-
197-
yield return assemblyInfoFile;
197+
RecurseSubdirectories = true,
198+
MaxRecursionDepth = DefaultMaxRecursionDepth
199+
};
200+
var projectFiles = fileSystem.Directory
201+
.EnumerateFiles(workingDirectory, "*proj", options)
202+
.Where(IsSupportedProjectFile);
203+
204+
foreach (var projectFile in projectFiles)
205+
{
206+
yield return fileSystem.FileInfo.New(projectFile);
198207
}
199208
}
200209
}

0 commit comments

Comments
 (0)