From 0ce3a9b66da80c505fd8901df88d31b0ad43dac6 Mon Sep 17 00:00:00 2001 From: Alex Kubiesa Date: Mon, 15 Feb 2021 20:08:21 +0000 Subject: Fix file size overflow error in ProcessPayloadsCommand. Fixes #4008 --- .../Bundles/ProcessPayloadsCommand.cs | 2 +- .../BundleFixture.cs | 52 +++++++++++++++++++++ .../TestData/LargePayload/Bundle.en-us.wxl | 10 ++++ .../TestData/LargePayload/Bundle.wxs | 13 ++++++ .../LargePayload/data/MsiPackage/Shared.dll | 1 + .../TestData/LargePayload/data/MsiPackage/test.txt | 1 + .../TestData/LargePayload/data/fakeba.dll | 1 + .../TestData/LargePayload/data/large_file.dat | 2 + .../TestData/LargePayload/data/test.msi | Bin 0 -> 32768 bytes 9 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 src/test/WixToolsetTest.CoreIntegration/TestData/LargePayload/Bundle.en-us.wxl create mode 100644 src/test/WixToolsetTest.CoreIntegration/TestData/LargePayload/Bundle.wxs create mode 100644 src/test/WixToolsetTest.CoreIntegration/TestData/LargePayload/data/MsiPackage/Shared.dll create mode 100644 src/test/WixToolsetTest.CoreIntegration/TestData/LargePayload/data/MsiPackage/test.txt create mode 100644 src/test/WixToolsetTest.CoreIntegration/TestData/LargePayload/data/fakeba.dll create mode 100644 src/test/WixToolsetTest.CoreIntegration/TestData/LargePayload/data/large_file.dat create mode 100644 src/test/WixToolsetTest.CoreIntegration/TestData/LargePayload/data/test.msi diff --git a/src/WixToolset.Core.Burn/Bundles/ProcessPayloadsCommand.cs b/src/WixToolset.Core.Burn/Bundles/ProcessPayloadsCommand.cs index 8811c301..db5b03fb 100644 --- a/src/WixToolset.Core.Burn/Bundles/ProcessPayloadsCommand.cs +++ b/src/WixToolset.Core.Burn/Bundles/ProcessPayloadsCommand.cs @@ -117,7 +117,7 @@ namespace WixToolset.Core.Burn.Bundles if (null != fileInfo) { - payload.FileSize = (int)fileInfo.Length; + payload.FileSize = fileInfo.Length; payload.Hash = BundleHashAlgorithm.Hash(fileInfo); } diff --git a/src/test/WixToolsetTest.CoreIntegration/BundleFixture.cs b/src/test/WixToolsetTest.CoreIntegration/BundleFixture.cs index 094e4df2..0660dd7b 100644 --- a/src/test/WixToolsetTest.CoreIntegration/BundleFixture.cs +++ b/src/test/WixToolsetTest.CoreIntegration/BundleFixture.cs @@ -366,5 +366,57 @@ namespace WixToolsetTest.CoreIntegration Assert.InRange(result.ExitCode, 2, Int32.MaxValue); } } + + [Fact] + public void CanBuildBundleWithLargePayload() + { + var folder = TestData.Get(@"TestData\LargePayload"); + + // Overwrite the payload with a 2.5 GiB file. We do this dynamically to avoid committing such + // a large file to source control. + var largeFile = Path.Combine(folder, "data", "large_file.dat"); + const long TwoAndAHalfGigabytes = 2_684_354_560; + using (var stream = File.Create(largeFile)) + { + stream.Seek(TwoAndAHalfGigabytes - 1, SeekOrigin.Begin); + stream.WriteByte(1); + } + + using (var fs = new DisposableFileSystem()) + { + var baseFolder = fs.GetFolder(); + var intermediateFolder = Path.Combine(baseFolder, "obj"); + var exePath = Path.Combine(baseFolder, @"bin\test.exe"); + var pdbPath = Path.Combine(baseFolder, @"bin\test.wixpdb"); + + var result = WixRunner.Execute(new[] + { + "build", + Path.Combine(folder, "Bundle.wxs"), + "-loc", Path.Combine(folder, "Bundle.en-us.wxl"), + "-bindpath", Path.Combine(folder, "data"), + "-intermediateFolder", intermediateFolder, + "-o", exePath, + }); + + result.AssertSuccess(); + Assert.Empty(result.Messages.Where(m => m.Level == MessageLevel.Warning)); + + Assert.True(File.Exists(exePath)); + Assert.True(File.Exists(pdbPath)); + Assert.True(File.Exists(Path.Combine(baseFolder, @"bin\large_file.dat"))); + + using (var wixOutput = WixOutput.Read(pdbPath)) + { + var intermediate = Intermediate.Load(wixOutput); + var section = intermediate.Sections.Single(); + + var payloadSymbol = section.Symbols.OfType().Where(x => x.Name == "large_file.dat").Single(); + Assert.Equal(TwoAndAHalfGigabytes, payloadSymbol.FileSize); + } + } + + File.Delete(largeFile); + } } } diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/LargePayload/Bundle.en-us.wxl b/src/test/WixToolsetTest.CoreIntegration/TestData/LargePayload/Bundle.en-us.wxl new file mode 100644 index 00000000..bc1dee83 --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/LargePayload/Bundle.en-us.wxl @@ -0,0 +1,10 @@ + + + + + + ~TestBundle + + diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/LargePayload/Bundle.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/LargePayload/Bundle.wxs new file mode 100644 index 00000000..5c7735b5 --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/LargePayload/Bundle.wxs @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/LargePayload/data/MsiPackage/Shared.dll b/src/test/WixToolsetTest.CoreIntegration/TestData/LargePayload/data/MsiPackage/Shared.dll new file mode 100644 index 00000000..0e461ba8 --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/LargePayload/data/MsiPackage/Shared.dll @@ -0,0 +1 @@ +This is Shared.dll. \ No newline at end of file diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/LargePayload/data/MsiPackage/test.txt b/src/test/WixToolsetTest.CoreIntegration/TestData/LargePayload/data/MsiPackage/test.txt new file mode 100644 index 00000000..8b986220 --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/LargePayload/data/MsiPackage/test.txt @@ -0,0 +1 @@ +This is test.txt \ No newline at end of file diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/LargePayload/data/fakeba.dll b/src/test/WixToolsetTest.CoreIntegration/TestData/LargePayload/data/fakeba.dll new file mode 100644 index 00000000..970efdf0 --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/LargePayload/data/fakeba.dll @@ -0,0 +1 @@ +This is a fakeba.dll \ No newline at end of file diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/LargePayload/data/large_file.dat b/src/test/WixToolsetTest.CoreIntegration/TestData/LargePayload/data/large_file.dat new file mode 100644 index 00000000..8115cc60 --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/LargePayload/data/large_file.dat @@ -0,0 +1,2 @@ +When running the tests, this file will be overwritten with 2.5GB of data to test how Wix handles large files. We've avoided +committing such a large file to Git as it would bloat the repo. diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/LargePayload/data/test.msi b/src/test/WixToolsetTest.CoreIntegration/TestData/LargePayload/data/test.msi new file mode 100644 index 00000000..0722d60e Binary files /dev/null and b/src/test/WixToolsetTest.CoreIntegration/TestData/LargePayload/data/test.msi differ -- cgit v1.2.3-55-g6feb