From 155a2a61ee57eee7735d031c489c90255b39797b Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Mon, 14 Dec 2020 14:30:27 -0600 Subject: WIXBUG:6299 - Fix OverflowException in ReadUInt32. --- WixToolset.Core.sln | 15 ++++++++ appveyor.cmd | 1 + src/WixToolset.Core.Burn/Bundles/BurnCommon.cs | 10 ++--- .../WixToolset.Core.Burn.csproj | 3 ++ .../WixToolsetTest.Core.Burn/BurnReaderFixture.cs | 44 ++++++++++++++++++++++ .../WixToolsetTest.Core.Burn.csproj | 28 ++++++++++++++ 6 files changed, 96 insertions(+), 5 deletions(-) create mode 100644 src/test/WixToolsetTest.Core.Burn/BurnReaderFixture.cs create mode 100644 src/test/WixToolsetTest.Core.Burn/WixToolsetTest.Core.Burn.csproj diff --git a/WixToolset.Core.sln b/WixToolset.Core.sln index 6c804904..a97f38d9 100644 --- a/WixToolset.Core.sln +++ b/WixToolset.Core.sln @@ -14,6 +14,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Example.Extension", "src\te EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WixToolsetTest.CoreIntegration", "src\test\WixToolsetTest.CoreIntegration\WixToolsetTest.CoreIntegration.csproj", "{E8A08E86-1780-4ED4-8F63-AB2B52C1C16B}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WixToolsetTest.Core.Burn", "src\test\WixToolsetTest.Core.Burn\WixToolsetTest.Core.Burn.csproj", "{DF63F589-028E-45A1-A212-948FACF1FDCD}" +EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WixToolset.Core.TestPackage", "src\WixToolset.Core.TestPackage\WixToolset.Core.TestPackage.csproj", "{853716DB-C02C-41BD-91BC-79CDC0C17D10}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CompileCoreTestExtensionWixlib", "src\test\CompileCoreTestExtensionWixlib\CompileCoreTestExtensionWixlib.csproj", "{23FC60D7-B101-42F8-9786-DB7A9CD964A2}" @@ -88,6 +90,18 @@ Global {E8A08E86-1780-4ED4-8F63-AB2B52C1C16B}.Release|x64.Build.0 = Release|Any CPU {E8A08E86-1780-4ED4-8F63-AB2B52C1C16B}.Release|x86.ActiveCfg = Release|Any CPU {E8A08E86-1780-4ED4-8F63-AB2B52C1C16B}.Release|x86.Build.0 = Release|Any CPU + {DF63F589-028E-45A1-A212-948FACF1FDCD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DF63F589-028E-45A1-A212-948FACF1FDCD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DF63F589-028E-45A1-A212-948FACF1FDCD}.Debug|x64.ActiveCfg = Debug|Any CPU + {DF63F589-028E-45A1-A212-948FACF1FDCD}.Debug|x64.Build.0 = Debug|Any CPU + {DF63F589-028E-45A1-A212-948FACF1FDCD}.Debug|x86.ActiveCfg = Debug|Any CPU + {DF63F589-028E-45A1-A212-948FACF1FDCD}.Debug|x86.Build.0 = Debug|Any CPU + {DF63F589-028E-45A1-A212-948FACF1FDCD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DF63F589-028E-45A1-A212-948FACF1FDCD}.Release|Any CPU.Build.0 = Release|Any CPU + {DF63F589-028E-45A1-A212-948FACF1FDCD}.Release|x64.ActiveCfg = Release|Any CPU + {DF63F589-028E-45A1-A212-948FACF1FDCD}.Release|x64.Build.0 = Release|Any CPU + {DF63F589-028E-45A1-A212-948FACF1FDCD}.Release|x86.ActiveCfg = Release|Any CPU + {DF63F589-028E-45A1-A212-948FACF1FDCD}.Release|x86.Build.0 = Release|Any CPU {853716DB-C02C-41BD-91BC-79CDC0C17D10}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {853716DB-C02C-41BD-91BC-79CDC0C17D10}.Debug|Any CPU.Build.0 = Debug|Any CPU {853716DB-C02C-41BD-91BC-79CDC0C17D10}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -119,6 +133,7 @@ Global GlobalSection(NestedProjects) = preSolution {C66C2503-C671-4230-8B48-1D93A8532A28} = {1284331E-BC6C-426D-AAAF-140C0174F875} {E8A08E86-1780-4ED4-8F63-AB2B52C1C16B} = {1284331E-BC6C-426D-AAAF-140C0174F875} + {DF63F589-028E-45A1-A212-948FACF1FDCD} = {1284331E-BC6C-426D-AAAF-140C0174F875} {23FC60D7-B101-42F8-9786-DB7A9CD964A2} = {1284331E-BC6C-426D-AAAF-140C0174F875} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution diff --git a/appveyor.cmd b/appveyor.cmd index 9cfe85a6..e5cc4731 100644 --- a/appveyor.cmd +++ b/appveyor.cmd @@ -3,6 +3,7 @@ @set _P=%~dp0build\Release\publish dotnet test -c Release src\test\WixToolsetTest.CoreIntegration || exit /b +dotnet test -c Release src\test\WixToolsetTest.Core.Burn || exit /b dotnet pack -c Release src\WixToolset.Core || exit /b dotnet pack -c Release src\WixToolset.Core.Burn || exit /b diff --git a/src/WixToolset.Core.Burn/Bundles/BurnCommon.cs b/src/WixToolset.Core.Burn/Bundles/BurnCommon.cs index 5cff0b5a..01c9f9ca 100644 --- a/src/WixToolset.Core.Burn/Bundles/BurnCommon.cs +++ b/src/WixToolset.Core.Burn/Bundles/BurnCommon.cs @@ -354,7 +354,7 @@ namespace WixToolset.Core.Burn.Bundles /// Array from which to read. /// Beginning offset from which to read. /// value at offset - private static UInt16 ReadUInt16(byte[] bytes, UInt32 offset) + internal static UInt16 ReadUInt16(byte[] bytes, UInt32 offset) { Debug.Assert(offset + 2 <= bytes.Length); return (UInt16)(bytes[offset] + (bytes[offset + 1] << 8)); @@ -366,10 +366,10 @@ namespace WixToolset.Core.Burn.Bundles /// Array from which to read. /// Beginning offset from which to read. /// value at offset - private static UInt32 ReadUInt32(byte[] bytes, UInt32 offset) + internal static UInt32 ReadUInt32(byte[] bytes, UInt32 offset) { Debug.Assert(offset + 4 <= bytes.Length); - return (UInt32)(bytes[offset] + (bytes[offset + 1] << 8) + (bytes[offset + 2] << 16) + (bytes[offset + 3] << 24)); + return BurnCommon.ReadUInt16(bytes, offset) + ((UInt32)BurnCommon.ReadUInt16(bytes, offset + 2) << 16); } /// @@ -378,10 +378,10 @@ namespace WixToolset.Core.Burn.Bundles /// Array from which to read. /// Beginning offset from which to read. /// value at offset - private static UInt64 ReadUInt64(byte[] bytes, UInt32 offset) + internal static UInt64 ReadUInt64(byte[] bytes, UInt32 offset) { Debug.Assert(offset + 8 <= bytes.Length); - return BurnCommon.ReadUInt32(bytes, offset) + ((UInt64)(BurnCommon.ReadUInt32(bytes, offset + 4)) << 32); + return BurnCommon.ReadUInt32(bytes, offset) + ((UInt64)BurnCommon.ReadUInt32(bytes, offset + 4) << 32); } } } diff --git a/src/WixToolset.Core.Burn/WixToolset.Core.Burn.csproj b/src/WixToolset.Core.Burn/WixToolset.Core.Burn.csproj index 77e0856a..b0be1d3b 100644 --- a/src/WixToolset.Core.Burn/WixToolset.Core.Burn.csproj +++ b/src/WixToolset.Core.Burn/WixToolset.Core.Burn.csproj @@ -15,6 +15,9 @@ <_Parameter1>WixToolset.Core.TestPackage, PublicKey=0024000004800000940000000602000000240000525341310004000001000100a9967ec28982f42ee51a47dd5204315975a6ed69294b982146a99a70130a2fa13e226aaddde14c17d1bf3af69e8956d69a86585e74d208efcc5ac98a0686055327b2e87960d3c39bf3a6bc1e572863327d19dbf4fd2616dda124dbea260755a2d1d39d3cf1049ea526493eb2bf996b8ad985e3012308529e5b9b0f5cd5fa04bd + + <_Parameter1>WixToolsetTest.Core.Burn, PublicKey=0024000004800000940000000602000000240000525341310004000001000100a9967ec28982f42ee51a47dd5204315975a6ed69294b982146a99a70130a2fa13e226aaddde14c17d1bf3af69e8956d69a86585e74d208efcc5ac98a0686055327b2e87960d3c39bf3a6bc1e572863327d19dbf4fd2616dda124dbea260755a2d1d39d3cf1049ea526493eb2bf996b8ad985e3012308529e5b9b0f5cd5fa04bd + diff --git a/src/test/WixToolsetTest.Core.Burn/BurnReaderFixture.cs b/src/test/WixToolsetTest.Core.Burn/BurnReaderFixture.cs new file mode 100644 index 00000000..a83da7f6 --- /dev/null +++ b/src/test/WixToolsetTest.Core.Burn/BurnReaderFixture.cs @@ -0,0 +1,44 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. + +namespace WixToolsetTest.Core.Burn +{ + using System; + using WixToolset.Core.Burn.Bundles; + using Xunit; + + public class BurnReaderFixture + { + [Fact] + public void CanReadUInt16Max() + { + var bytes = new byte[] { 0xFF, 0xFF }; + var offset = 0u; + + var result = BurnCommon.ReadUInt16(bytes, offset); + + Assert.Equal(UInt16.MaxValue, result); + } + + [Fact] + public void CanReadUInt32Max() + { + var bytes = new byte[] { 0xFF, 0xFF, 0xFF, 0xFF }; + var offset = 0u; + + var result = BurnCommon.ReadUInt32(bytes, offset); + + Assert.Equal(UInt32.MaxValue, result); + } + + [Fact] + public void CanReadUInt64Max() + { + var bytes = new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; + var offset = 0u; + + var result = BurnCommon.ReadUInt64(bytes, offset); + + Assert.Equal(UInt64.MaxValue, result); + } + } +} diff --git a/src/test/WixToolsetTest.Core.Burn/WixToolsetTest.Core.Burn.csproj b/src/test/WixToolsetTest.Core.Burn/WixToolsetTest.Core.Burn.csproj new file mode 100644 index 00000000..da0985b1 --- /dev/null +++ b/src/test/WixToolsetTest.Core.Burn/WixToolsetTest.Core.Burn.csproj @@ -0,0 +1,28 @@ + + + + + + netcoreapp2.1 + false + embedded + + + + NU1701 + + + + + + + + + + + + + + + + -- cgit v1.2.3-55-g6feb