A simple endless loop with JavaScript in a PDF document can cause resource exhaustion (cpu or mem). If JavaScript in PDF documents really needs to be supported, its resources should be limited (similar to browsers).
Created attachment 125335 [details] Trivial PoC (01)
Created attachment 125336 [details] Trivial PoC (02)
yeah, it seems that sadly the JS engine we use doesn't support timing out (even thought it seems it wants to, I've asked one of the authors for confirmation). Anyhow the engine is almost unmaintained at this stage so we may need to port to some other engine both for better code future proofing and to fix this problem.
Fix for this has landed now https://invent.kde.org/kde/okular/merge_requests/106/