From d99b4454061146decd2340ad0b7e0a84c23723ec Mon Sep 17 00:00:00 2001 From: Vitek Karas Date: Fri, 4 Oct 2019 11:33:02 -0700 Subject: [PATCH] Fix bundle failing to extract empty file. (dotnet/core-setup#8462) The file entry validity check marked empty files as invalid. This is wrong, the file size must be non-negative number. Added a test and fixed the condition. Commit migrated from https://github.com/dotnet/core-setup/commit/ed7ec9a245cd1fc6ce052dbf2487fc516f7b3f19 --- .../corehost/cli/apphost/bundle/file_entry.cpp | 2 +- .../AppHost.Bundle.Tests/BundledAppWithSubDirs.cs | 31 ++++++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/installer/corehost/cli/apphost/bundle/file_entry.cpp b/src/installer/corehost/cli/apphost/bundle/file_entry.cpp index dec8fec..ba4b235 100644 --- a/src/installer/corehost/cli/apphost/bundle/file_entry.cpp +++ b/src/installer/corehost/cli/apphost/bundle/file_entry.cpp @@ -11,7 +11,7 @@ using namespace bundle; bool file_entry_t::is_valid() const { - return m_offset > 0 && m_size > 0 && + return m_offset > 0 && m_size >= 0 && static_cast(m_type) < file_type_t::__last; } diff --git a/src/installer/test/Microsoft.NET.HostModel.Tests/AppHost.Bundle.Tests/BundledAppWithSubDirs.cs b/src/installer/test/Microsoft.NET.HostModel.Tests/AppHost.Bundle.Tests/BundledAppWithSubDirs.cs index 0ca66e5..f3d64d3 100644 --- a/src/installer/test/Microsoft.NET.HostModel.Tests/AppHost.Bundle.Tests/BundledAppWithSubDirs.cs +++ b/src/installer/test/Microsoft.NET.HostModel.Tests/AppHost.Bundle.Tests/BundledAppWithSubDirs.cs @@ -7,6 +7,8 @@ using Xunit; using Microsoft.DotNet.Cli.Build.Framework; using BundleTests.Helpers; using Microsoft.DotNet.CoreSetup.Test; +using System.Xml.Linq; +using System.IO; namespace AppHost.Bundle.Tests { @@ -32,7 +34,7 @@ namespace AppHost.Bundle.Tests } [Fact] - private void Bundled_Framework_dependent_App_Run_Succeeds() + public void Bundled_Framework_dependent_App_Run_Succeeds() { var fixture = sharedTestState.TestFrameworkDependentFixture.Copy(); var singleFile = BundleHelper.BundleApp(fixture); @@ -45,7 +47,7 @@ namespace AppHost.Bundle.Tests } [Fact] - private void Bundled_Self_Contained_App_Run_Succeeds() + public void Bundled_Self_Contained_App_Run_Succeeds() { var fixture = sharedTestState.TestSelfContainedFixture.Copy(); var singleFile = BundleHelper.BundleApp(fixture); @@ -57,10 +59,21 @@ namespace AppHost.Bundle.Tests RunTheApp(singleFile); } + [Fact] + public void Bundled_With_Empty_File_Succeeds() + { + var fixture = sharedTestState.TestAppWithEmptyFileFixture.Copy(); + var singleFile = BundleHelper.BundleApp(fixture); + + // Run the app + RunTheApp(singleFile); + } + public class SharedTestState : IDisposable { public TestProjectFixture TestFrameworkDependentFixture { get; set; } public TestProjectFixture TestSelfContainedFixture { get; set; } + public TestProjectFixture TestAppWithEmptyFileFixture { get; set; } public RepoDirectoriesProvider RepoDirectories { get; set; } public SharedTestState() @@ -78,6 +91,20 @@ namespace AppHost.Bundle.Tests .EnsureRestoredForRid(TestSelfContainedFixture.CurrentRid, RepoDirectories.CorehostPackages) .PublishProject(runtime: TestSelfContainedFixture.CurrentRid, outputDirectory: BundleHelper.GetPublishPath(TestSelfContainedFixture)); + + TestAppWithEmptyFileFixture = new TestProjectFixture("AppWithSubDirs", RepoDirectories); + XDocument projectDoc = XDocument.Load(TestAppWithEmptyFileFixture.TestProject.ProjectFile); + projectDoc.Root.Add( + new XElement("ItemGroup", + new XElement("Content", + new XAttribute("Include", "empty.txt"), + new XElement("CopyToOutputDirectory", "PreserveNewest")))); + projectDoc.Save(TestAppWithEmptyFileFixture.TestProject.ProjectFile); + File.WriteAllBytes(Path.Combine(TestAppWithEmptyFileFixture.TestProject.Location, "empty.txt"), new byte[0]); + TestAppWithEmptyFileFixture + .EnsureRestoredForRid(TestAppWithEmptyFileFixture.CurrentRid, RepoDirectories.CorehostPackages) + .PublishProject(runtime: TestAppWithEmptyFileFixture.CurrentRid, + outputDirectory: BundleHelper.GetPublishPath(TestAppWithEmptyFileFixture)); } public void Dispose() -- 2.7.4