Skip to content

Commit

Permalink
Fix attaching containers larger than 2GB
Browse files Browse the repository at this point in the history
  • Loading branch information
nirbar committed Jan 30, 2024
1 parent 60f232c commit a35305c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
16 changes: 7 additions & 9 deletions src/wix/WixToolset.Core.Burn/Bundles/BurnCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace WixToolset.Core.Burn.Bundles
/// <summary>
/// Common functionality for Burn PE Writer &amp; Reader for the WiX toolset.
/// </summary>
/// <remarks>This class encapsulates common functionality related to
/// <remarks>This class encapsulates common functionality related to
/// bundled/chained setup packages.</remarks>
/// <example>
/// </example>
Expand Down Expand Up @@ -178,24 +178,22 @@ public void Dispose()
/// <param name="input">Input stream.</param>
/// <param name="output">Output stream.</param>
/// <param name="size">Optional count of bytes to copy. 0 indicates whole input stream from current should be copied.</param>
protected static int CopyStream(Stream input, Stream output, int size)
protected static void CopyStream(Stream input, Stream output, uint size)
{
var bytes = new byte[4096];
var total = 0;
var total = 0u;
do
{
var read = Math.Min(bytes.Length, size - total);
var read = (int)Math.Min(bytes.Length, size - total);
read = input.Read(bytes, 0, read);
if (0 == read)
{
break;
}

output.Write(bytes, 0, read);
total += read;
} while (0 == size || total < size);

return total;
total += (uint)read;
} while (0u == size || total < size);
}

/// <summary>
Expand Down Expand Up @@ -320,7 +318,7 @@ private bool GetWixburnSectionInfo(BinaryReader reader)

this.wixburnRawDataSize = BurnCommon.ReadUInt32(bytes, IMAGE_SECTION_HEADER_OFFSET_SIZEOFRAWDATA);

// we need 52 bytes for the manifest header, which is always going to fit in
// we need 52 bytes for the manifest header, which is always going to fit in
// the smallest alignment (512 bytes), but just to be paranoid...
if (BURN_SECTION_MIN_SIZE > this.wixburnRawDataSize)
{
Expand Down
4 changes: 2 additions & 2 deletions src/wix/WixToolset.Core.Burn/Bundles/BurnReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public bool ExtractUXContainer(string outputDirectory, string tempDirectory)
this.binaryReader.BaseStream.Seek(this.UXAddress, SeekOrigin.Begin);
using (Stream tempCab = this.fileSystem.OpenFile(null, tempCabPath, FileMode.Create, FileAccess.Write, FileShare.Read))
{
BurnCommon.CopyStream(this.binaryReader.BaseStream, tempCab, (int)uxContainerSlot.Size);
BurnCommon.CopyStream(this.binaryReader.BaseStream, tempCab, uxContainerSlot.Size);
}

var cabinet = new Cabinet(tempCabPath);
Expand Down Expand Up @@ -262,7 +262,7 @@ public bool ExtractAttachedContainers(string outputDirectory, string tempDirecto
this.binaryReader.BaseStream.Seek(nextAddress, SeekOrigin.Begin);
using (Stream tempCab = this.fileSystem.OpenFile(null, tempCabPath, FileMode.Create, FileAccess.Write, FileShare.Read))
{
BurnCommon.CopyStream(this.binaryReader.BaseStream, tempCab, (int)cntnr.Size);
BurnCommon.CopyStream(this.binaryReader.BaseStream, tempCab, cntnr.Size);
}

if (!(document.SelectSingleNode($"/burn:BurnManifest/burn:Container[@Attached = 'yes' and @AttachedIndex = {i}]", nsmgr) is XmlElement containerElement))
Expand Down
2 changes: 1 addition & 1 deletion src/wix/WixToolset.Core.Burn/Bundles/BurnWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ private bool AppendContainer(Stream containerStream, uint containerSize, uint bu

// Append the container to the end of the existing bits.
this.binaryWriter.BaseStream.Seek(0, SeekOrigin.End);
BurnCommon.CopyStream(containerStream, this.binaryWriter.BaseStream, (int)containerSize);
BurnCommon.CopyStream(containerStream, this.binaryWriter.BaseStream, containerSize);
this.binaryWriter.BaseStream.Flush();

return true;
Expand Down

0 comments on commit a35305c

Please sign in to comment.