File tree Expand file tree Collapse file tree
tests/NuGetGallery.Facts/OData/Interceptors Expand file tree Collapse file tree Original file line number Diff line number Diff 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;
Original file line number Diff line number Diff 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>
You can’t perform that action at this time.
0 commit comments