NuGet / Home

Repo for NuGet Client issues
Other
1.49k stars 250 forks source link

Exception when extracting files while executing ProjectRestoreCommand #13538

Closed bstordrup closed 1 week ago

bstordrup commented 1 month ago

NuGet Product Used

dotnet.exe

Product Version

dotnet 6.0.423 dotnet 8

Worked before?

Not sure if it worked in dotnet5

Impact

I'm unable to use this version - it fails my github action.

Repro Steps & Context

I get the error if I try to add a nuget using the command

dotnet add ConsoleTest2.csproj package MyImportantPackage --version 1.0.0 --package-directory packages

Looking in the packages folder, the unpacked package looks like this:

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d----          11-06-2024    16:34                lib
-a---          11-06-2024    16:34         149872 25yi3iue.eh1
-a---          07-06-2024    11:04            582 myimportantpackage.nuspec

But if I use the command

nuget install MyImportantPackage -OutputDirectory packages -DirectDownload -Version 1.0.0

the package is correct installed and no error reported, and the contents of the installed package in packages folder is correct.

In both attempts, the nuget package resides in a GitHub package repository.

Verbose Logs

Stack trace: The error is from executing the

dotnet restore MyConsumingSolution.sln --verbosity diagnostic

command in a GitHub action flow.

C:\Users\runneradmin\AppData\Local\Microsoft\dotnet\sdk\6.0.423\NuGet.targets(132,5): error : The archive entry was compressed using an unsupported compression method. [D:\a\Visma.Diagnostics\Visma.Diagnostics\Visma.Diagnostics.Tracing.sln]
                     System.IO.InvalidDataException: The archive entry was compressed using an unsupported compression method.
                        at System.IO.Compression.Inflater.Inflate(FlushCode flushCode)
                        at System.IO.Compression.Inflater.ReadInflateOutput(Byte* bufPtr, Int32 length, FlushCode flushCode, Int32& bytesRead)
                        at System.IO.Compression.Inflater.InflateVerified(Byte* bufPtr, Int32 length)
                        at System.IO.Compression.DeflateStream.ReadCore(Span`1 buffer)
                        at System.IO.Compression.DeflateStream.Read(Byte[] buffer, Int32 offset, Int32 count)
                        at System.IO.Stream.CopyTo(Stream destination, Int32 bufferSize)
                        at NuGet.Packaging.StreamExtensions.Testable.MmapCopy(Stream inputStream, String fileFullPath, Int64 size)
                        at NuGet.Packaging.StreamExtensions.Testable.CopyToFile(Stream inputStream, String fileFullPath)
                        at NuGet.Packaging.PackageFileExtractor.ExtractPackageFile(String source, String target, Stream stream)
                        at NuGet.Packaging.PackageArchiveReader.CopyFiles(String destination, IEnumerable`1 packageFiles, ExtractPackageFileDelegate extractFile, ILogger logger, CancellationToken token)
                        at NuGet.Packaging.PackageReaderBase.CopyFilesAsync(String destination, IEnumerable`1 packageFiles, ExtractPackageFileDelegate extractFile, ILogger logger, CancellationToken cancellationToken)
                        at NuGet.Packaging.PackageExtractor.<>c__DisplayClass5_0.<<InstallFromSourceAsync>b__0>d.MoveNext()
                     --- End of stack trace from previous location ---
                        at NuGet.Common.ConcurrencyUtilities.ExecuteWithFileLockedAsync[T](String filePath, Func`2 action, CancellationToken token)
                        at NuGet.Common.ConcurrencyUtilities.ExecuteWithFileLockedAsync[T](String filePath, Func`2 action, CancellationToken token)
                        at NuGet.Packaging.PackageExtractor.InstallFromSourceAsync(PackageIdentity packageIdentity, IPackageDownloader packageDownloader, VersionFolderPathResolver versionFolderPathResolver, PackageExtractionContext packageExtractionContext, CancellationToken token, Guid parentId)
                        at NuGet.Commands.ProjectRestoreCommand.InstallPackageAsync(RemoteMatch installItem, NuGetv3LocalRepository userPackageFolder, PackageExtractionContext packageExtractionContext, CancellationToken token)
                        at NuGet.Commands.ProjectRestoreCommand.<>c__DisplayClass15_1.<<InstallPackagesAsync>b__4>d.MoveNext()
                     --- End of stack trace from previous location ---
                        at NuGet.Commands.ProjectRestoreCommand.InstallPackagesAsync(HashSet`1 uniquePackages, IEnumerable`1 graphs, IList`1 downloadDependencyInformations, NuGetv3LocalRepository userPackageFolder, CancellationToken token)
                        at NuGet.Commands.ProjectRestoreCommand.TryRestoreAsync(LibraryRange projectRange, IEnumerable`1 frameworkRuntimePairs, NuGetv3LocalRepository userPackageFolder, IReadOnlyList`1 fallbackPackageFolders, RemoteDependencyWalker remoteWalker, RemoteWalkContext context, Boolean forceRuntimeGraphCreation, CancellationToken token, TelemetryActivity telemetryActivity, String telemetryPrefix)
                        at NuGet.Commands.RestoreCommand.ExecuteRestoreAsync(NuGetv3LocalRepository userPackageFolder, IReadOnlyList`1 fallbackPackageFolders, RemoteWalkContext context, CancellationToken token, TelemetryActivity telemetryActivity)
                        at NuGet.Commands.RestoreCommand.ExecuteAsync(CancellationToken token)
                        at NuGet.Commands.RestoreRunner.ExecuteAsync(RestoreSummaryRequest summaryRequest, CancellationToken token)
                        at NuGet.Commands.RestoreRunner.ExecuteAndCommitAsync(RestoreSummaryRequest summaryRequest, IRestoreProgressReporter progressReporter, CancellationToken token)
                        at NuGet.Commands.RestoreRunner.CompleteTaskAsync(List`1 restoreTasks)
                        at NuGet.Commands.RestoreRunner.RunAsync(IEnumerable`1 restoreRequests, RestoreArgs restoreArgs, CancellationToken token)
                        at NuGet.Commands.RestoreRunner.RunAsync(RestoreArgs restoreContext, CancellationToken token)
                        at NuGet.Build.Tasks.BuildTasksUtility.RestoreAsync(DependencyGraphSpec dependencyGraphSpec, Boolean interactive, Boolean recursive, Boolean noCache, Boolean ignoreFailedSources, Boolean disableParallel, Boolean force, Boolean forceEvaluate, Boolean hideWarningsAndErrors, Boolean restorePC, Boolean cleanupAssetsForUnsupportedProjects, ILogger log, CancellationToken cancellationToken)
                        at NuGet.Build.Tasks.RestoreTask.ExecuteAsync(ILogger log) (TaskId:212)
                   Done executing task "RestoreTask" -- FAILED. (TaskId:212)
nkolev92 commented 1 month ago

@bstordrup

I think a repro would be the most helpful thing, but I'm guessing that might be harder to provide. Even a copy of the package might be helpful (assuming the issue is the compression algorithm that's confusing nuget). If we had a copy, we could put it in a local feed and try to repro.

It's likely that some of the extraction code paths are slightly different.

bstordrup commented 1 month ago

Hi @nkolev92

Actually, I think this issue is related to pushing the package to an authenticated repository. I have not seen this issue again after applying the -DisableBuffering parameter.

nkolev92 commented 1 month ago

Are you suggesting that the package got corrupted at push time server side, so then the downloading fails due to that?

dotnet-policy-service[bot] commented 3 weeks ago

This issue has been automatically marked as stale because we have not received a response in 14 days. It will be closed if no further activity occurs within another 14 days of this comment.