Skip to content

Commit

Permalink
Fix #179
Browse files Browse the repository at this point in the history
Possible Index Outside bounds of array when more than 128 packages are scanned
  • Loading branch information
digitalcoyote committed Mar 16, 2024
1 parent 88a80c0 commit 0257ba2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Src/NuGetDefense.Lib/NuGetDefense.Lib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<Description>NuGetDefense ~ Check for Known Vulnerabilities at Build</Description>
<PackageDescription>NuGetDefense was inspired by [OWASP SafeNuGet](https://nuget.org/packages/SafeNuGet/) but aims to check with multiple sources for known vulnerabilities.</PackageDescription>
<Copyright>Curtis Carter 2023</Copyright>
<Version>4.0.2.0</Version>
<Version>4.0.4.0</Version>
<RepositoryType>git</RepositoryType>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
Expand Down
16 changes: 9 additions & 7 deletions Src/NuGetDefense.Lib/Scanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace NuGetDefense;

public class Scanner
{
public const string Version = "4.0.2.0";
public const string Version = "4.0.4.0";
public const string UserAgentString = @$"NuGetDefense/{Version}";
public const string DefaultSettingsFileName = "NuGetDefense.json";
public const string DefaultVulnerabilityDataFileName = "VulnerabilityData.bin";
Expand Down Expand Up @@ -196,12 +196,13 @@ private void ScanVulnerabilities(ScanOptions options)
var modUncached = uncachedPkgs.Count % 128;
if (modUncached > 0 && cachedPackages.Length > 0)
{
for (var i = cachedPackages.Length - 1; i >= cachedPackages.Length - modUncached; i--)
var rescanCount = Math.Min(128 - modUncached, cachedPackages.Length);
for (var i = cachedPackages.Length - 1; i >= 0; i--)
{
uncachedPkgs.Add(cachedPackages[i]);
}
cachedPackages = cachedPackages[..^modUncached];

cachedPackages = cachedPackages[..^rescanCount];
}
// Round out the calls to have a full set of packages each to refresh oldest cached packages
if (uncachedPkgs.Count > 0) uncachedPkgs.AddRange(cachedPackages.Take(uncachedPkgs.Count % 128));
Expand Down Expand Up @@ -236,12 +237,13 @@ private void ScanVulnerabilities(ScanOptions options)
var modUncached = uncachedPkgs.Count % 128;
if (modUncached > 0 && cachedPackages.Length > 0)
{
for (var i = cachedPackages.Length - 1; i >= cachedPackages.Length - modUncached; i--)
var rescanCount = Math.Min(128 - modUncached, cachedPackages.Length);
for (var i = cachedPackages.Length - 1; i >= 0; i--)
{
uncachedPkgs.Add(cachedPackages[i]);
}
cachedPackages = cachedPackages[..^modUncached];

cachedPackages = cachedPackages[..^rescanCount];
}
Log.Logger.Verbose("Checking the GitHub Security Advisory Database for Vulnerabilities");
var ghsaVulnDict =
Expand Down
6 changes: 3 additions & 3 deletions Src/NuGetDefense/NuGetDefense.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<Nullable>enable</Nullable>
<AssemblyVersion>4.0.2.0</AssemblyVersion>
<FileVersion>4.0.2.0</FileVersion>
<AssemblyVersion>4.0.4.0</AssemblyVersion>
<FileVersion>4.0.4.0</FileVersion>
<PackageIcon>icon.png</PackageIcon>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release'">
Expand All @@ -37,7 +37,7 @@
<PackageId>NuGetDefense.Tool</PackageId>
<PackAsTool>true</PackAsTool>
<ToolCommandName>nugetdefense</ToolCommandName>
<Version>4.0.2.0</Version>
<Version>4.0.4.0</Version>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions Src/NuGetDefense/NuGetDefense.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<metadata>
<id>NuGetDefense</id>
<title>NuGetDefense</title>
<version>4.0.2.0</version>
<version>4.0.4.0</version>
<authors>Curtis Carter</authors>
<owners>Curtis Carter</owners>
<projectUrl>https://digitalcoyote.github.io/NuGetDefense/</projectUrl>
Expand All @@ -12,7 +12,7 @@
<description>
vulnerabilities.
</description>
<releaseNotes>https://github.com/digitalcoyote/NuGetDefense/releases/tag/v4.0.2.0</releaseNotes>
<releaseNotes>https://github.com/digitalcoyote/NuGetDefense/releases/tag/v4.0.4.0</releaseNotes>
<repository type="git" url="https://github.com/digitalcoyote/NuGetDefense.git"/>
<license type="expression">MIT</license>
<icon>images\icon.png</icon>
Expand Down

0 comments on commit 0257ba2

Please sign in to comment.