Visitar URL original
Close gzip.Writer in archiveTarGZIP to flush footer by SebTardif · Pull Request #23240 · pulumi/pulumi · GitHub
Skip to content

Close gzip.Writer in archiveTarGZIP to flush footer - #23240

Merged
julienp merged 1 commit into
pulumi:masterfrom
SebTardif:fix-gzip-writer-leak
May 18, 2026
Merged

julienp merged 1 commit into
pulumi:masterfrom
SebTardif:fix-gzip-writer-leak

Conversation

@SebTardif

Copy link
Copy Markdown
Contributor

Summary

archiveTarGZIP creates a gzip.NewWriter but returns the result of archiveTar without closing the gzip writer. gzip.Writer.Close flushes buffered data and writes the CRC32/size footer required by the gzip format. Without it, the output is a truncated, corrupt .tar.gz stream that tools like tar xzf may reject or produce incomplete extractions from.

Fix

Close the gzip writer after archiveTar returns, checking the error on both the tar and gzip close operations. If archiveTar fails, the gzip writer is still closed (error discarded since the primary error takes precedence). On success, z.Close() is returned so flush/footer errors propagate to the caller.

Call chain

Archive.Archive() -> archiveTarGZIP() -> archiveTar()

The TarGZIPArchive format is selected when the caller requests .tar.gz output, used in Pulumi's asset/archive serialization for deployment packages.

Origin

The bug was introduced in #15157 (2024-01-25) when assets and archives were moved to their own package.

Validation

  • go build, go vet, gofmt pass
  • go test ./resource/archive/... passes

Changelog

  • Yes, there are changes in this PR that warrants a changelog entry

@SebTardif
SebTardif requested a review from a team as a code owner May 18, 2026 13:55
@github-actions

Copy link
Copy Markdown

PR is now waiting for a maintainer to take action.

Note for the maintainer: Commands available:

  • /run-acceptance-tests - used to test run the acceptance tests for the project
  • /run-codegen - used to test the Pull Request against downstream codegen
  • /run-docs-gen - used to test the Pull Request against documentation generation

z.Close()
return err
}
return z.Close()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually care about the errors from z.Close() here? I think just a defer z.Close()` is probably fine?

archiveTarGZIP creates a gzip.NewWriter but returns the result of
archiveTar without closing the gzip writer. gzip.Writer.Close flushes
buffered data and writes the CRC32/size footer required by the gzip
format. Without it, the output is a truncated, corrupt .tar.gz stream.

Close the gzip writer after archiveTar returns, checking the error on
both the tar and gzip operations.

The bug was introduced in pulumi#15157 (2024-01-25).
@SebTardif
SebTardif force-pushed the fix-gzip-writer-leak branch from 1429f36 to b6d6406 Compare May 18, 2026 14:18
@SebTardif

Copy link
Copy Markdown
Contributor Author

Good point, simplified to defer z.Close(). The main fix is ensuring Close is called at all (to flush the gzip footer); checking its error is secondary. Force-pushed.

@github-actions

Copy link
Copy Markdown

PR is now waiting for a maintainer to take action.

Note for the maintainer: Commands available:

  • /run-acceptance-tests - used to test run the acceptance tests for the project
  • /run-codegen - used to test the Pull Request against downstream codegen
  • /run-docs-gen - used to test the Pull Request against documentation generation

@tgummerer

Copy link
Copy Markdown
Collaborator

Thanks!

@tgummerer
tgummerer enabled auto-merge May 18, 2026 14:29
@tgummerer
tgummerer added this pull request to the merge queue May 18, 2026
@julienp
julienp removed this pull request from the merge queue due to a manual request May 18, 2026
@julienp
julienp added this pull request to the merge queue May 18, 2026
Merged via the queue into pulumi:master with commit 9fa9bb0 May 18, 2026
6 checks passed
@pulumi-bot

Copy link
Copy Markdown
Contributor

This PR has been shipped in release v3.242.0.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants