From 93863517e52de97a8c59ebe1167de912c3f184f2 Mon Sep 17 00:00:00 2001 From: Drew Smirnoff Date: Thu, 28 May 2026 18:18:30 +0400 Subject: [PATCH] fix: prevent a fork bomb (#1374) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## What? Add `view/main_test.go` with `TestMain` calling `termimage.MaybeRunWorker()` before `m.Run()`. ## Why? termimage.DisplayWithSize` (called by `view.prerenderImage`) sandboxes image decode by spawning `os.Executable()` as subprocess with `TERMIMAGE_WORKER=1`. Worker subprocess MUST call `termimage.MaybeRunWorker()` first to intercept, decode, exit. `main.go` does this for the real binary. Test binary did not. When `TestProcessBodyWithImageProtocol` ran Kitty/iTerm cases, `prerenderImage` spawned the test binary as worker. Child re-ran full test suite → triggered more `prerenderImage` calls → spawned more children → fork bomb. RAM exhausted, machine froze. Signed-off-by: drew --- view/main_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 view/main_test.go diff --git a/view/main_test.go b/view/main_test.go new file mode 100644 index 0000000000000000000000000000000000000000..8ec5503ed9f7188e067550cc260e3ff5f2090c3f --- /dev/null +++ b/view/main_test.go @@ -0,0 +1,18 @@ +package view + +import ( + "os" + "testing" + + "github.com/floatpane/termimage" +) + +// TestMain intercepts subprocess invocations made by termimage's sandbox +// worker (TERMIMAGE_WORKER=1). Without this, a test binary spawned as a +// worker would re-run the full test suite, which itself triggers more +// workers — a fork bomb that exhausts RAM and freezes the machine. +// Mirrors the call in main.go's main(). +func TestMain(m *testing.M) { + termimage.MaybeRunWorker() + os.Exit(m.Run()) +}