In internal/blobgen/compress.go, CompressStream has both a defer w.Close() and an explicit w.Close() call:
funcCompressStream(dstio.Writer,srcio.Reader,compressionLevelint,recipients[]string)(writtenint64,hashstring,errerror){w,err:=NewWriter(dst,compressionLevel,recipients)iferr!=nil{return0,"",...}deferfunc(){_=w.Close()}()// <-- will always runif_,err:=io.Copy(w,src);err!=nil{return0,"",...}iferr:=w.Close();err!=nil{// <-- explicit closereturn0,"",...}// defer runs AGAIN here, double-closingreturnw.BytesWritten(),...}
The Writer.Close() calls compressor.Close() then encryptor.Close(). The second close on the zstd encoder returns an error ("use after close"), and the age encryptor close may write duplicate finalization bytes to the output, corrupting the stream.
Fix
Use a writerClosed flag pattern (already used in snapshot.gocompressFile) or remove the defer.
## Bug
In `internal/blobgen/compress.go`, `CompressStream` has both a `defer w.Close()` and an explicit `w.Close()` call:
```go
func CompressStream(dst io.Writer, src io.Reader, compressionLevel int, recipients []string) (written int64, hash string, err error) {
w, err := NewWriter(dst, compressionLevel, recipients)
if err != nil {
return 0, "", ...
}
defer func() { _ = w.Close() }() // <-- will always run
if _, err := io.Copy(w, src); err != nil {
return 0, "", ...
}
if err := w.Close(); err != nil { // <-- explicit close
return 0, "", ...
}
// defer runs AGAIN here, double-closing
return w.BytesWritten(), ...
}
```
The `Writer.Close()` calls `compressor.Close()` then `encryptor.Close()`. The second close on the zstd encoder returns an error ("use after close"), and the age encryptor close may write duplicate finalization bytes to the output, corrupting the stream.
## Fix
Use a `writerClosed` flag pattern (already used in `snapshot.go` `compressFile`) or remove the defer.
clawbot
self-assigned this 2026-02-08 21:01:09 +01:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Bug
In
internal/blobgen/compress.go,CompressStreamhas both adefer w.Close()and an explicitw.Close()call:The
Writer.Close()callscompressor.Close()thenencryptor.Close(). The second close on the zstd encoder returns an error ("use after close"), and the age encryptor close may write duplicate finalization bytes to the output, corrupting the stream.Fix
Use a
writerClosedflag pattern (already used insnapshot.gocompressFile) or remove the defer.