The vulnerability, identified as GHSA-54p8-x2m9-c593, is a resource exhaustion issue caused by improper resource management in multiple functions across the chainguard-dev/malcontent codebase. The root cause is a consistent programming error where resources such as file descriptors, memory buffers, and pooled objects (like scanners) were acquired, but the defer statements to release them were placed late in the function body.
In Go, defer schedules a function call to be run immediately before the surrounding function returns. The vulnerability arises when an error occurs after a resource has been acquired but before the corresponding defer statement is registered. In such cases, the function returns early due to the error, and the cleanup code is never executed, leading to a resource leak.
Repeatedly triggering these error paths could cause the application to exhaust available file descriptors or memory, leading to a denial of service. The fix applied across all affected files was to move the defer statement to execute immediately after the resource is successfully acquired, ensuring that the resource is always released regardless of subsequent errors.