That's why you need Rust in any image decoder. FFMPEG too.
The problem here is that pdf is over bloated with features and without strictly defined standard. Rust can't help you with that, or any language for that matter. It's akin to upgrading the security system on a house on fire.
The best solution would be ditching it completely for a simpler subset of features. But that will never happen.
Apple has been propagating Swift for more than a decade now and at least in theory, it should be on par with Rust in terms of safety I'd say.