Skip to content

Commit ed43f93

Browse files
authored
[Hotfix] Set download count to Int32.MaxValue for V2 feed packages exceeding this threshold (#9199)
1 parent ee1bd6b commit ed43f93

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

src/NuGetGallery/OData/PackageExtensions.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ internal static IQueryable<V2FeedPackage> ProjectV2FeedPackage(
8888
Created = p.Created,
8989
Dependencies = p.FlattenedDependencies,
9090
Description = p.Description,
91-
DownloadCount = p.PackageRegistration.DownloadCount,
91+
// Some of the older clients and packages (eg: NuGet.Core) suffer from integer overflow when the download count
92+
// exceeds the MaxValue due to usage of Int32 for "DownloadCount" field. As such, for the V2 Feed restrict the download
93+
// count to Int32.MaxValue in order to allow older clients to successfully fetch these values.
94+
DownloadCount = p.PackageRegistration.DownloadCount > Int32.MaxValue ? (long)Int32.MaxValue : p.PackageRegistration.DownloadCount,
9295
GalleryDetailsUrl = siteRoot + "packages/" + p.PackageRegistration.Id + "/" + p.NormalizedVersion,
9396
IconUrl = p.IconUrl,
9497
// We do not expose the internal IsLatestSemVer2 and IsLatestStableSemVer2 properties;

tests/NuGetGallery.Facts/OData/Interceptors/PackageExtensionsFacts.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,29 @@ public void ReturnsNullLicenseReportInfoIfFeatureDisabled()
132132
Assert.Null(actual.LicenseNames);
133133
Assert.Null(actual.LicenseReportUrl);
134134
}
135+
136+
[Fact]
137+
public void RestrictsExceedingDownloadCountsToInt32MaxValue()
138+
{
139+
// Arrange
140+
var package = CreateFakeBasePackage();
141+
package.PackageRegistration.DownloadCount = long.MaxValue;
142+
var packages = new List<Package>
143+
{
144+
package
145+
}.AsQueryable();
146+
147+
// Act
148+
var projected = PackageExtensions.ProjectV2FeedPackage(
149+
packages,
150+
siteRoot: "http://nuget.org",
151+
includeLicenseReport: false,
152+
semVerLevelKey: SemVerLevelKey.Unknown).ToList();
153+
154+
// Assert
155+
var actual = projected.Single();
156+
Assert.Equal(Int32.MaxValue, actual.DownloadCount);
157+
}
135158
}
136159

137160
/// <summary>

0 commit comments

Comments
 (0)