[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [AUCTeX-devel] [gs-devel] Asking help for preview-latex

From: Ken Sharp
Subject: Re: [AUCTeX-devel] [gs-devel] Asking help for preview-latex
Date: Thu, 20 Jun 2019 13:52:10 +0100

Hi Keita,

(or should that be Ikumi ? Please accept an apology if I'm wrong)

I asked this on our IRC channel, but it occurs to me that it may be outside working hours for you now, so I'm following up by email.

At 18:47 20/06/2019 +0900, Ikumi Keita wrote:

In short, Ghostscript stops with error when preview-latex tries to
adjust the foreground color of the generated image to be the same as
that of Emacs face.

So essentially what you are saying is that you want the rendered result of the PDF file to be in some colour other than the colour which it should be.

For example, if the PDF file uses black, and the Emacs current colour is (eg) green, then you want the PDF rendered as green.

The PDF specification offers a rich range of colour spaces and colours, and the format allows for objects to be drawn in any of those colours. PDF doesn't have a 'foreground' or 'background' colour, every object in the PDF file can be a different colour and potentially in different colour spaces.

The code you sent (below) appears only to alter the default colour (and colour space) of the PDF file. If the PDF contains any colour specifications then the code you have sent won't (unless I'm missing something, which is entirely possible) affect that.

So to take a concrete example; if a PDF file used the initial colour to draw a letter 'A' then what you would get rendered would be a capital A in black. However, if the PDF file set the current colour space to CMYK and drew a 'B' in Magenta, you would get a capital B in magenta.

Your code would affect the first case, causing the A to be rendered in (eg) green, but would not affect the second case, the B would still be rendered in magenta.

So I'm going to assume this is some highly limited application of PDF and Ghostscript where you can guarantee that the PDF file only uses the default colour space and colour and never sets any other colours.

We consider the reason of the problem is that preview-latex relies on
GS_PDF_ProcSet, which was removed in Ghostscript 9.27, from the
following three observations:

You really, really should not be patching the internals of the PDF interpreter. While this is, obviously, open source software, we regard the way the PDF interpreter works as 'private' (in the sense of udocumented), rather than a public API of any kind. We can and often will alter the way the internals of the PDF interpreter work without notice.

The reason we removed access to the dictionary is due to security concerns. You may or may not recall the security flap that Tavis Ormandy started (over a year ago) by publishing an exploit to demonstrate remote code execution using Ghostscript.

That started us down a long road of hardening the PostScript and PDF interpreters to prevent any recurrence. Its quite clear that permitting unfettered access to the PDF interpreter allowed malicious software to bypass the security in Ghostscript with varying degrees of ease. Obviously we don't want to undo any of that work and expose ourselves to potential vulnerabilities again.

Assuming the above consideration is correct, we would appreciate if you,
the Ghostscript developers, could kindly provide alternate Postscript
code to achieve the original purpose of preview-latex.  The relevant
elisp code is:
(defun preview-pdf-color-string (colors)
  "Return a string that patches PDF foreground color to work properly."
  ;; Actually, this is rather brutal.  It will only be invoked in
  ;; cases, however, where previously it was not expected that
  ;; anything readable turned up, anyway.
  (let ((fg (aref colors 1)))
    (if fg
    "/GS_PDF_ProcSet GS_PDF_ProcSet dup maxlength dict copy dup begin\
/graphicsbeginpage{//graphicsbeginpage exec "
    (mapconcat #'preview-gs-color-value fg " ")
    " 3 copy rg RG}bind store end readonly store "))))
.  What we would like to know is the code (string) to replace the
"/GS_PDF_ProcSet GS_PDF_ProcSet dup..." part.  Unfortunately, I don't
understand any Postscript language, but I hope that the above piece of
code together with the error message attached with this message is
enough to determine what to do, even without knowledge of elisp.  Please
note that these codes go through pdf2dsc.

I don't think pdf2dsc is relevant, but its always useful to know.

In order to investigate properly I need a file that I can run through Ghostscript, and a Ghostscript command line which will show the difference with and without the code above. I can probably invent a command line, but not the PDF file.

I believe that if you send me a PDF file which shows a difference, and the values substituted by the line '(mapconcat #'preview-gs-color-value fg " ")' above, I can probably simply render the file with and without that code to see what difference it makes.

I can't simply use a random PDF file which I have to hand, as all the ones I can find easily set the colour before trying to draw any objects, which defeats the use of the code above. Or at least it does for me, but I could be doing something wrong.....


                        Ken Sharp

reply via email to

[Prev in Thread] Current Thread [Next in Thread]