Skip to content

Commit 6c0e581

Browse files
committed
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] #25974 Signed-off-by: Paul Holzinger <[email protected]>
1 parent b4954ac commit 6c0e581

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pkg/bindings/images/pull.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,16 @@ LOOP:
7474
var report types.ImagePullReport
7575
if err := dec.Decode(&report); err != nil {
7676
if errors.Is(err, io.EOF) {
77+
// end of stream, exit loop
7778
break
7879
}
79-
report.Error = err.Error() + "\n"
80+
// Decoder error, it is unlikely that the next call would work again
81+
// so exit here as well, the Decoder can store the error and always
82+
// return the same one for all future calls which then causes a
83+
// infinity loop and memory leak in pullErrors.
84+
// https://github.com/containers/podman/issues/25974
85+
pullErrors = append(pullErrors, fmt.Errorf("failed to decode message from stream: %w", err))
86+
break
8087
}
8188

8289
select {

0 commit comments

Comments
 (0)