Hacker News new | ask | show | jobs
by hannob 7 days ago
It's been known for a while, and certainly long before the recent AI vuln flood, that ghostscript is really problematic in terms of security.

Ultimately, postscript is its own programming language, and executing a programming language in a secure, sandboxed way is not trivial. ghostscript has only a very poor pseudo sandbox that fails regularly. Unfortunately, ghostscript is the only implementation of postscript that's out there.

All of that would matter much less if people only used it to parse postscript. But it's used indirectly by imagemagick (you can disable it), which means many people using imagemagick to parse images from untrusted sources get exposed to ghostscript's poor security.

6 comments

> Unfortunately, ghostscript is the only implementation of postscript that's out there.

That needs lots of qualifiers. It's the only popular and widely distributed open-source implementation with known good performance and wide compatibility.

There were so many other implementations and vibed ports already that I expect ghostscript to be actually replaced in distros within a year or two. Very random example https://github.com/AndyCappDev/postforge

requirements: Cairo, psutils, Pillow.
Why is it interesting?
i imagine those dependencies are non-trivial outside of linux
They're trivial anywhere you have Python.
they're also a trivial way to call all amounts of random C-code with... Probably even gs...
Once you want to support everything ghostscript does, nothing is trivial. Ghostscript depends on fun stuff too https://packages.ubuntu.com/stonking/libgs10

But it could be worse. Cairo and Pillow are very established.

GS should be pledged under OpenBSD.
Isn't GS GPLd? I imagine they'd attempt to clone it or make their own GS-esque thing if they though it was a big enough problem to warrant stepping in
Yes, and people didn't previously write big webpages, come up with a fancy name, and notify about a dozen different companies before just writing a ghostscript fix.
No previously it was just confined to OpenSSL bugs (2014) [1], linux kernel race conditions (2016) [2], CPU speculative execution (2018) [3] just to randomly list some of the earlier ones.

It quickly became cringe, but the annoyance you're feeling right now is not due to folks branding vulns.. It's that the rate of these bugs has gone up 5-20x since ~July this year.

Unfortunately this is the new normal. It's not going to get "better" any time soon.

[1]: https://www.heartbleed.com/ [2]: https://dirtycow.ninja/ [3]: https://spectreattack.com

Oh I still regard 2014 as modern; remember Ghostscript came out in 1988 - I've been using it since the mid 90's!
I feel like the AI vulnerability flood is going to get called "2shell with that" after all the 4shell names.
A lot of these 4shell vulns are only theoretical RCE. That's not to say they aren't serious, but I think the severity is exaggerated a fair amount.
Hopefully few people install Ghostscript if they don't need it, on a server that processes user uploads
You install ImageMagick, it most likely depends on Ghostscript.

You use something else than ImageMagick, say, to resize an uploaded image, and the moment it sees a color-managed image, it will produce something that looks like puke.

I had to do a very custom build of ImageMagick to get rid of dependencies on libgs and libX11. It wasn't fun.

ImageMagick was problematic for so long by pulling everything and the kitchen sink as dependencies. It's just not something you'd like to replace because it's got nice features and... works. It feels absurd but right now, if you have a very narrow use case (like just resizing), it may be better to make an LLM create an alternative, in a safer language, with validated core components, tested on a large number of samples.
Something that uses CImg just for resizing could be a decent alternative. It’s a library but they provided a nice cli for it the last time i checked
Yes, it seems much smaller than ImageMagick.

ImageMagick has a big attack surface, when most people probably use it just for cropping and resizing.

Just use something leaner, when you can.

Another alternative is GraphicsMagick (http://www.graphicsmagick.org/) which aims to be API and utility compatible with ImageMagick, but spends most of its development effort on fuzzing, verification, etc. It's a more secure alternative to ImageMagick for those who've developed something significant that depends on ImageMagick.
„When you can” is doing the heavy lifting here. Also, sometimes you need to process PostScript-adjacent things.
Yeah, sadly true
I was looking through the PPDs a Brother printer installed for Linux (trying to get it working on FreeBSD), it had a pre-built ghostscript binary in there that hadn't been updated in god knows how long. I wonder if printing a PDF with an embedded font or something could trigger that.
> Unfortunately, ghostscript is the only implementation of postscript that's out there.

This sounds like an afternoon’s worth of prompting could double the number of implementations.

could be, but it's just ghostscript, rewritten