chunked: prevent reuse of chunkedDiffer
The chunkedDiffer object holds state and resources that are managed within a single ApplyDiff call. Reusing the same differ instance for multiple ApplyDiff calls could lead to incorrect state or errors related to already-closed resources. Add a flag and check to ensure ApplyDiff cannot be called more than once on the same chunkedDiffer instance, making its usage pattern explicit and preventing potential misuse. Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
parent
65b1dc9e06
commit
719ebe0f4c
|
|
@ -108,6 +108,7 @@ type chunkedDiffer struct {
|
|||
zstdReader *zstd.Decoder
|
||||
rawReader io.Reader
|
||||
useFsVerity graphdriver.DifferFsVerity
|
||||
used bool // the differ object was already used and cannot be used again for .ApplyDiff
|
||||
}
|
||||
|
||||
var xattrsToIgnore = map[string]any{
|
||||
|
|
@ -1388,6 +1389,11 @@ func typeToOsMode(typ string) (os.FileMode, error) {
|
|||
}
|
||||
|
||||
func (c *chunkedDiffer) ApplyDiff(dest string, options *archive.TarOptions, differOpts *graphdriver.DifferOptions) (graphdriver.DriverWithDifferOutput, error) {
|
||||
if c.used {
|
||||
return graphdriver.DriverWithDifferOutput{}, fmt.Errorf("internal error: chunked differ already used")
|
||||
}
|
||||
c.used = true
|
||||
|
||||
defer c.layersCache.release()
|
||||
defer func() {
|
||||
if c.zstdReader != nil {
|
||||
|
|
|
|||
Loading…
Reference in New Issue