Allocate a buffer and copy compressed chunk rather

Otherwise the compression buffer will get stomped on before the results channel is consumed
This commit is contained in:
Neil Macneale IV
2025-05-27 11:57:04 -07:00
parent 21d8828eb5
commit 8b48b472a1

View File

@@ -385,7 +385,6 @@ func writeDataToArchive(
groupCount++
cmpBuff = gozstd.Compress(cmpBuff[:0], cg.dict)
dictId, err := arcW.writeByteSpan(cmpBuff)
if err != nil {
return 0, 0, 0, err
@@ -473,7 +472,11 @@ func compressChunksInParallel(
return
}
cmpBuff = gozstd.CompressDict(cmpBuff[:0], c.Data(), defaultDict)
resultCh <- compressedChunk{h: h, data: cmpBuff}
// Make a private copy of the compressed data
privateCopy := make([]byte, len(cmpBuff))
copy(privateCopy, cmpBuff)
resultCh <- compressedChunk{h: h, data: privateCopy}
}
}
}()