loic-sharma / BaGet

A lightweight NuGet and symbol server
https://loic-sharma.github.io/BaGet/
MIT License
2.62k stars 678 forks source link

Push package failed in linux docker when package's icon path contains '\' #513

Closed RayMMond closed 4 years ago

RayMMond commented 4 years ago

Describe the bug

Pushing a package icon path with '\' to baget linux container, will cause System.IO.FileNotFoundException.

fail: BaGet.Core.PackageIndexingService[0]
      Uploaded package is invalid
System.IO.FileNotFoundException: icons\mailkit-50.png
   at NuGet.Packaging.ZipArchiveExtensions.LookupEntry(ZipArchive zipArchive, String path)
   at NuGet.Packaging.ZipArchiveExtensions.OpenFile(ZipArchive zipArchive, String path)
   at NuGet.Packaging.PackageArchiveReader.GetStream(String path)
   at NuGet.Packaging.PackageReaderBase.GetStreamAsync(String path, CancellationToken cancellationToken)
   at BaGet.Core.PackageArchiveReaderExtensions.GetIconAsync(PackageArchiveReader package, CancellationToken cancellationToken) in /src/BaGet.Core/Extensions/PackageArchiveReaderExtensions.cs:line 54
   at BaGet.Core.PackageIndexingService.IndexAsync(Stream packageStream, CancellationToken cancellationToken) in /src/BaGet.Core/Indexing/PackageIndexingService.cs:line 61

To Reproduce

Steps to reproduce the behavior:

  1. Using latest BaGet image DIGEST '3fcb1e9f22c7'
  2. Push MailKit-2.4.1 to BaGet.
  3. See error

Additional context

After some digging, I found something interesting.

According to PackageArchiveReader:

https://github.com/loic-sharma/BaGet/blob/bd440199ba16f62bdb0c157c69b6479f3e2aa9f9/src/BaGet.Core/Extensions/PackageArchiveReaderExtensions.cs#L50-L55

And Nuget.Packaging:

https://github.com/NuGet/NuGet.Client/blob/e59333e773bbc4fed97e5534fe88e25332ca04b0/src/NuGet.Core/NuGet.Packaging/PackageArchiveReader.cs#L140-L150

        public override Stream GetStream(string path)
        {
            Stream stream = null;
            path = path.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
            if (!string.IsNullOrEmpty(path))
            {
                stream = _zipArchive.OpenFile(path);
            }

            return stream;
        }

package.NuspecReader.GetIcon() return icon path in nuspec, it could be window-style or linux-style. When it's windows-style, and BaGet is running in linux, path = path.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); will not replace '\' to '/'.

I'm not sure it is a BaGet bug or a Nuget.Packaging bug, any thoughts?

WernerMairl commented 4 years ago

hi i see your point: I have created a test that should execute exact this code areas with the same package and I'm hosting the test on linux/ubuntu (github actions) https://github.com/mssforks/BaGet/tree/issue/513

BUT i cannot reproduce the exception. Maybe just solved in one of the dependencies ?

@loic-sharma Maybe we should compile and test the entire codebase on a Linux based OS (additionally to the current full build on windows).

Can you setup this in Azure Pipelines ?

RayMMond commented 4 years ago

@WernerMairl Thanks for reply~😃 Did you try upload this MailKit 2.4.1 package to BaGet? Because only this package's icon path contains '\', which cause the problem.

WernerMairl commented 4 years ago

yes, you can give a look at my fork (link in my last post) the test project contains the package as as resx and the nupkg is added to BaGet

loic-sharma commented 4 years ago

Hi, This should be fixed by https://github.com/loic-sharma/BaGet/pull/517. Could you try again with the latest docker image? I'll update the GitHub release and nuget.org packages soon.

RayMMond commented 4 years ago

Tested OK on latest docker image.

aldy505 commented 1 year ago

Still happening on me. Using the latest image (docker pull loicsharma/baget:0.4.0-preview2).

Stack trace:

 fail: BaGet.Core.PackageIndexingService[0]
       Uploaded package is invalid
 System.IO.FileNotFoundException: docs\README.md
    at NuGet.Packaging.ZipArchiveExtensions.LookupEntry(ZipArchive zipArchive, String path)
    at NuGet.Packaging.ZipArchiveExtensions.OpenFile(ZipArchive zipArchive, String path)
    at NuGet.Packaging.PackageArchiveReader.GetStream(String path)
    at NuGet.Packaging.PackageReaderBase.GetStreamAsync(String path, CancellationToken cancellationToken)
    at BaGet.Core.PackageArchiveReaderExtensions.GetReadmeAsync(PackageArchiveReader package, CancellationToken cancellationToken) in /src/BaGet.Core/Extensions/PackageArchiveReaderExtensions.cs:line 32
    at BaGet.Core.PackageIndexingService.IndexAsync(Stream packageStream, CancellationToken cancellationToken) in /src/BaGet.Core/Indexing/PackageIndexingService.cs:line 56