Skip to content

GZipStream compression of zero length byte[] in .NET 8.0 results in stream length 20 while in .NET 10.0 it results in length 0 #122928

@vbunde

Description

@vbunde

Description

GZipStream compression of zero length byte[] in .NET 8.0 results in length 20 while in .NET 10.0 it results in length 0
var zeroByteArray = Array.Empty();

.NET 8.0 stream.Length is 20
.NET 10.0 stream.Length is 0

Reproduction Steps

using System;
using System.IO;
using System.IO.Compression;

var zeroByteArray = Array.Empty();
using var stream = new MemoryStream();

using (var zipStream = new GZipStream(stream, CompressionMode.Compress, true))
{
zipStream.Write(zeroByteArray, 0, zeroByteArray.Length);
}

Console.WriteLine(stream.Length);

Expected behavior

stream.Length should not change between frameworks 8 and 10

Actual behavior

stream.Length changes between frameworks 8 and 10

Regression?

Yes

Known Workarounds

No response

Configuration

No response

Other information

fiddle link - https://dotnetfiddle.net/lCithR

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions