Skip to content

resource-collection.xxxx.js gzip footer not passed #66218

Description

@ThibaultLesuisse

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

We noticed that the resource-collection.x.js file misses the GZIP footer so that some decompression tools fail. GZIP itself returns "gzip: unexpected end of file". It could of course be that our setup is missing something and that the contents of resource-collection.x.js is corrupt because of this. I've checked with a few LLM's that tell me this could be a bug so here I am.

The CreateGzipBytes method does not properly write the GZIP footer because Dispose() on the GZipStream occurs after calling ToArray(). This means the output byte array is missing the footer, which results in incomplete or corrupted GZIP data. Behavior of the GZIP library is explained here dotnet-runtime

Code Location:
src/Components/Endpoints/src/Builder/ResourceCollectionUrlEndpoint.cs#L82

Current implementation:

private static byte[] CreateGzipBytes(byte[] bytes)
{
    using var gzipContent = new MemoryStream();
    using var gzipStream = new GZipStream(gzipContent, CompressionLevel.Optimal, leaveOpen: true);
    gzipStream.Write(bytes);
    gzipStream.Flush();
    return gzipContent.ToArray();
}

Expected Behavior

I expect the returned byte array to include the GZIP footer so it can be decompressed by clients.

The code should dispose/close the GZipStream (which writes the footer) before reading from the MemoryStream:

private static byte[] CreateGzipBytes(byte[] bytes)
{
    using var gzipContent = new MemoryStream();
    using (var gzipStream = new GZipStream(gzipContent, CompressionLevel.Optimal, leaveOpen: true))
    {
        gzipStream.Write(bytes);
    }
    return gzipContent.ToArray();
}

Steps To Reproduce

  1. Setup a Blazor Web App
  2. Make sure the Accept-Encoding Header is set to contain gzip
  3. Use curl to manually fetch the resource-collection.xxxx.js file
  4. use tar or gzip to check for the integrity of the file
  5. tar -xzf .\output.gz results in tar.exe: Error opening archive: Unrecognized archive format

Optional: Compare byte output before/after switching disposal order.

Exceptions (if any)

No Exceptions

.NET Version

10.0.5

Anything else?

Duplicate of #66213 because I'm an idiot who closes issues too soon

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-blazorIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions