Is there an existing issue for this?
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();
}
Problem:
Calling ToArray() before disposing the GZipStream excludes the GZIP footer from the result, violating the GZIP format and breaking decompression.
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
- Setup a Blazor Web App
- Make sure the Accept-Encoding Header is set to contain
gzip
- Use curl to manually fetch the resource-collection.xxxx.js file
- use
tar or gzip to check for the integrity of the file
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)
Decompression fails (e.g., with System.IO.InvalidDataException: The archive entry was compressed using an unsupported compression method. or similar depending on the tool/client).
.NET Version
10.0.5
Anything else?
Is there an existing issue for this?
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.jsis 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
CreateGzipBytesmethod does not properly write the GZIP footer becauseDispose()on the GZipStream occurs after callingToArray(). 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-runtimeCode Location:
src/Components/Endpoints/src/Builder/ResourceCollectionUrlEndpoint.cs#L82
Current implementation:
Problem:
Calling
ToArray()before disposing the GZipStream excludes the GZIP footer from the result, violating the GZIP format and breaking decompression.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:
Steps To Reproduce
gziptarorgzipto check for the integrity of the filetar -xzf .\output.gzresults intar.exe: Error opening archive: Unrecognized archive formatOptional: Compare byte output before/after switching disposal order.
Exceptions (if any)
Decompression fails (e.g., with
System.IO.InvalidDataException: The archive entry was compressed using an unsupported compression method.or similar depending on the tool/client)..NET Version
10.0.5
Anything else?
CreateGzipBytesin ResourceCollectionUrlEndpoint