using go to wrap a python script - this is some "hacker man" stuff right here
return bytes.ReplaceAll(script, []byte{0x09}, []byte{0x20, 0x20, 0x20, 0x20})
instead of bytes.ReplaceAll(script, []byte("\t"), []byte(" "))
Skimming through the code, there's a lot of other pretty basic mistakes.The most egregious is that the use of a python script has a security issue. Let's see if you can spot it, it's in these lines:
tmp := fmt.Sprintf("/var/tmp/invertpdf--%s/", time.Now().Format("20060102150405"))
os.Mkdir(tmp, 0700)
WriteText(tmp+"pngtopdf.py", GetPDFConv())
// later execute that .py file
So, what's the issue? Well, using a predictable temporary directory and then not checking for an error in `mkdir` means that an attacker can easily create that directory before you do (especially since it's a predictable name based on the time), and then write their own python script. That lets another user on your machine run arbitrary code as your user."But", you might say, "WriteText does an os.Exit if it can't write the file". That doesn't matter. If i create the directory with permissions 777, and then have a program waiting for the python script to be written in order to replace it with a malicious script, Mkdir will error (dir already exists), but WriteText will succeed, and so the vulnerability still happens.
This is the sort of dumb vulnerability you get if you don't know that `ioutil.TempDir` exists (or don't know about symlink races, tmpdir races, etc). `ioutil.TempDir("/var/tmp", "invertpdf-")` would be the more secure way to do this, though obviously you still should check that error too.
There's a lot of other problems with this program, but this vulnerability is the most obvious.
That said, I've seen messier things than python-in-go shipped and used reliably in production to solve business problems.
Edit: It appears to be Evince [0]
javascript:(function(){viewer.style = 'filter: grayscale(1) invert(1) sepia(1) contrast(75%)';})()Bookmarklet
javascript:(function() { var v = document.getElementsByTagName("html"); v[0].style.background = "white"; v[0].style.filter = "invert(90%) sepia(60%) brightness(70%)"; v[0].style.backgroundColor = "black"; document.getElementsByTagName("body")[0].style.background = "white"; })();
chrome://flags/#pdf-viewer-update
> Configure the dark theme: brightness, contrast and sepia. Enable for all websites or particular domains.
Works for PDFs too.
No affiliation.
Edit: the "Dynamic" (GPU) mode doesn't work on all sites. On HN I'll use Filter+ with the settings -20 brightness, contrast off, sepia +30, grayscale off.
While on Github I'll do -5, 0, +30, 0. Mainly just tweaking the brightness while having Sepia on most sites.
https://getpolarized.io/2020/10/05/Polar-2-0-Release.html
the issue we had was that we were using a CSS filter like other commenters mentioned.
The problem is that it inverts images too and pdfjs doesn't actually specify which parts of the document are an image as it's just writing to a canvas.
My plan moving forward is to fix pdfjs so it can invert natively and the actual canvas is inverted so that images won't be inverted.
I think figures would STILL be a problem though.
EPUBs are much easier and we're not inverting there because we can see which one is an img.