pkg/bindings: fix infinite loop/memory leak in image pull

In the case of an Decoder error which is not EOF we loop forever, as the
Decoder stores some errors each next Decode() call will keep returning
the same error. Thus we loop forever until we run out of memory as each
error was stored in pullErrors array as described in [1].

Note this does not actually fix whatever causes the underlying
connection error in the issue, it just fixes the loop/memory leak.

[1] https://github.com/containers/podman/issues/25974

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
Paul Holzinger 2025-04-29 11:59:24 +02:00
parent b4954ac2e8
commit 6c0e581fa9
No known key found for this signature in database
GPG Key ID: EB145DD938A3CAF2
1 changed files with 8 additions and 1 deletions

View File

@ -74,9 +74,16 @@ LOOP:
var report types.ImagePullReport
if err := dec.Decode(&report); err != nil {
if errors.Is(err, io.EOF) {
// end of stream, exit loop
break
}
report.Error = err.Error() + "\n"
// Decoder error, it is unlikely that the next call would work again
// so exit here as well, the Decoder can store the error and always
// return the same one for all future calls which then causes a
// infinity loop and memory leak in pullErrors.
// https://github.com/containers/podman/issues/25974
pullErrors = append(pullErrors, fmt.Errorf("failed to decode message from stream: %w", err))
break
}
select {