Is there something like this for formats other than ZIP like jpeg or pdf?

Idk, but there's an interesting project, wuffs: a programming language specifically aimed at efficiently and safely parsing document structure. There is a PNG decoder [2].

1. https://github.com/google/wuffs

2. https://news.ycombinator.com/item?id=26714831