Lurker News
I realized that the PDF engines of modern desktop browsers (PDFium and PDF.js) support JavaScript with enough I/O primitives to make a basic game like Tetris.

It was a bit tricky to find a union of features that work in both engines, but in the end it turns out that showing/hiding annotation "fields" works well to make monochrome pixels, and keyboard input can be achieved by typing in a text input box.
All in all it's quite janky but a nice reminder of how general purpose PDF scripting can be. The linked PDF is all ASCII so you can just open it in a text editor, or have a look at the source code here: https://github.com/ThomasRinsma/pdftris/blob/main/gengrid.py

Comments (223) 81 threads

Earlier comments
efitz5 replies#
This is amazing and terrifying (I am a security engineer and parsing complex document formats is a never-ending treasure trove of vulnerabilities).
tashian1 reply#
AI agents run in isolated VMs, but PDFs have been out here running in the open for 30 years!
miohtama4 replies#
But can your PDF run an AI agent?
freedomben#
Looking forward to a day when you may not have a powerful enough GPU to open a PDF
hnlmorg3 replies#
In my opinion the question isn’t so much “if” but rather “when”.

When will AI research and hardware capabilities reach a point that it’s practical to embed something like that into a regular document?
We’ve already seen proof of concept LLMs embedded into OpenType fonts.
I guess the other question is then “what capabilities would these AI agents have?” You’d hope just permission to present within that document. But that depends entirely on what unpatched vulnerabilities are lurking (such as the Microsoft ANSI RCE also featured on the HN front page)

Continue this thread — 3 replies

siva71 reply#
The first widespread AI Malware will be a historic moment in this century. It will adapt like a real biological virus to its host and we have no cure for this.

Continue this thread — 1 reply

Continue this thread — 3 replies

neuroelectron#
This isn't even the beginning of what's possible in PDFs.
wayvey#
The amount of attack surface in various format parsers is pretty stunning and terrifying indeed
kccqzy1 reply#
That exploit is indeed legendary but the code execution involved is not JavaScript. In fact the iOS PDF renderer does not have JavaScript enabled.
saagarjha#
Obviously a skill issue; a true hacker would re-enable it.
enews011 reply#
Theres a malaysian movie where the main premise is a hacker who uses pdf executions to steal one cent from every persons bank account. Its pretty interesting.
brettermeier1 reply#
Do you know the name of the movie?
bityard5 replies#
Not just web browsers, Acrobat (and probably other PDF readers) have supported executing Javascript in PDFs for decades.
unnouinceput#
I was joking in 2007, when I was working at Siemens, to my boss, that an Excel cell can contain God and the Multiverse when I put an ActiveX inside that was basically a program I made which would draw a 3D animation based on parameters contained on other cells. Let's say the boss was impressed though for me was just basic OLE.

I see from time to time that younger generations reinvent/rediscover the wheel and I chuckle.

brumar#
This is even in the ISO standard now
pimlottc1 reply#
Which makes sense, why would browsers randomly add JS to PDF if it wasn’t already part of the standard?
kzrdude#
What a nightmare that JS is a part of the PDF standard. I suppose that it's optional.
Aaron22221 reply#
Doesn't work in Preview unfortunately.
jeffhuys#
Fortunately*
swyx1 reply#
why??? for what possible secure white hat reason could you want to run js in pdfs??!? is nobody sane running the pdf org?
andreamonaco#
Yeah, I agree.

I first met an interactive PDF when filing a form for some state matter (I live in Italy).
I thought that it was over-engineered and dangerous.
Also, this kind of things tend to gratuitously exclude non-mainstream (especially free) software.

LetsGetTechnicl#
This is an affront against god. Good work.
btown#
I, for one, was surprised that Chrome's PDF renderer would allow persistent JS code like this to run - not just limited code in response to user actions, but a real game loop.

But there's a spec for all this and everything! https://www.t10.org/ftp/js_api_reference.pdf (2007) - be warned, the light of Ecma TC39 standardization does not extend to this place.
Chromium's implementation of setInterval for instance (which, in this world, takes a string to evaluate): https://pdfium.googlesource.com/pdfium/+/refs/heads/main/fxj... -> https://pdfium.googlesource.com/pdfium/+/refs/heads/main/fxj...
From a security perspective, they're able to build on top of V8 isolate primitives and Chrome's sandboxing systems - but from the logs, security improvements in PDFium are being continuously developed as recently as the past few weeks! I feel like I've stumbled upon a parallel universe, in the best possible way.

Load more comments