From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.bugs Subject: bug#33684: DocView bombs out upon password protected PDFs Date: Fri, 01 Feb 2019 11:12:51 +0100 Message-ID: <87h8dn7r6k.fsf@gnu.org> References: <87d0qb3rb1.fsf@jidanni.org> <87sgxesv6u.fsf@gmail.com> <83womjyhrw.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="160804"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: 33684@debbugs.gnu.org, Federico Tedin , jidanni@jidanni.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Feb 01 11:14:12 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gpVpr-000fjT-P2 for geb-bug-gnu-emacs@m.gmane.org; Fri, 01 Feb 2019 11:14:12 +0100 Original-Received: from localhost ([127.0.0.1]:50800 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpVpq-0006el-Nh for geb-bug-gnu-emacs@m.gmane.org; Fri, 01 Feb 2019 05:14:10 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:34769) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpVpk-0006eH-Pe for bug-gnu-emacs@gnu.org; Fri, 01 Feb 2019 05:14:05 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpVpi-0005qf-S9 for bug-gnu-emacs@gnu.org; Fri, 01 Feb 2019 05:14:04 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:54474) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gpVpi-0005qQ-Cq for bug-gnu-emacs@gnu.org; Fri, 01 Feb 2019 05:14:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gpVpi-00075x-0Z for bug-gnu-emacs@gnu.org; Fri, 01 Feb 2019 05:14:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Tassilo Horn Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 01 Feb 2019 10:14:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 33684 X-GNU-PR-Package: emacs Original-Received: via spool by 33684-submit@debbugs.gnu.org id=B33684.154901598327200 (code B ref 33684); Fri, 01 Feb 2019 10:14:01 +0000 Original-Received: (at 33684) by debbugs.gnu.org; 1 Feb 2019 10:13:03 +0000 Original-Received: from localhost ([127.0.0.1]:53755 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gpVol-00074e-3D for submit@debbugs.gnu.org; Fri, 01 Feb 2019 05:13:03 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:48358) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gpVoi-000749-D5 for 33684@debbugs.gnu.org; Fri, 01 Feb 2019 05:13:01 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:56771) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpVoc-0005Y6-U2; Fri, 01 Feb 2019 05:12:54 -0500 Original-Received: from auth2-smtp.messagingengine.com ([66.111.4.228]:52991) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.82) (envelope-from ) id 1gpVoc-00018M-QG; Fri, 01 Feb 2019 05:12:54 -0500 Original-Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailauth.nyi.internal (Postfix) with ESMTP id 2A893217CF; Fri, 1 Feb 2019 05:12:54 -0500 (EST) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Fri, 01 Feb 2019 05:12:54 -0500 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedtledrjeekgddufecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfhuthenuceurghilhhouhhtmecufedt tdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvufhfffgjkf gfgggtgfesthhqredttderjeenucfhrhhomhepvfgrshhsihhlohcujfhorhhnuceothhs ughhsehgnhhurdhorhhgqeenucfkphepvdduvddrudekhedrvddtfedrudefgeenucfrrg hrrghmpehmrghilhhfrhhomhepthhhohhrnhdomhgvshhmthhprghuthhhphgvrhhsohhn rghlihhthidqkeeijeefkeejkeegqdeifeehvdelkedqthhsughhpeepghhnuhdrohhrgh esfhgrshhtmhgrihhlrdhfmhenucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Original-Received: from pchta-and (portal.shd.de [212.185.203.134]) by mail.messagingengine.com (Postfix) with ESMTPA id 746E1E4068; Fri, 1 Feb 2019 05:12:52 -0500 (EST) In-Reply-To: <83womjyhrw.fsf@gnu.org> (Eli Zaretskii's message of "Fri, 01 Feb 2019 11:33:55 +0200") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:154968 Archived-At: Eli Zaretskii writes: Hi Federico, Dan & Eli, >> From: Federico Tedin >> Date: Sat, 26 Jan 2019 23:14:49 -0300 > > Thanks. > > Tassilo, any comments on the proposal below? Should I push it? It would be great if we could support opening password protected PDFs also when we're using mupdf as a converter. That has a "-p" option for the very same sake which could be set analogously in `doc-view-pdf->png-converter-mupdf'. So, yes, please push it with that small addition. Bye, Tassilo >> =E7=A9=8D=E4=B8=B9=E5=B0=BC Dan Jacobson writes: >>=20 >> > When trying to view a password protected PDF: >> > DocView: process pdf/ps->png changed status to exited abnormally with = code 1. >> > Maybe it should ask for the password. >> > emacs-version "25.2.2" >>=20 >> Would something like this make sense? A short patch that adds >> `doc-view-pdf-password-protected-p', and an extra option to pass to >> Ghostscript (-sPDFPassword=3D) when the command is invoked (only when the >> PDF file is password protected). I tried it out by creating a >> password-protected PDF using LibreOffice Writer, and then opening it >> with find-file. >>=20 >>=20 >> diff --git a/lisp/doc-view.el b/lisp/doc-view.el >> index df8a9fc70f..8691d2a3a6 100644 >> --- a/lisp/doc-view.el >> +++ b/lisp/doc-view.el >> @@ -183,11 +183,16 @@ doc-view-pdf->png-converter-function >> (defcustom doc-view-ghostscript-options >> '("-dSAFER" ;; Avoid security problems when rendering files from untr= usted >> ;; sources. >> - "-dNOPAUSE" "-sDEVICE=3Dpng16m" "-dTextAlphaBits=3D4" >> - "-dBATCH" "-dGraphicsAlphaBits=3D4" "-dQUIET") >> + "-dNOPAUSE" "-dTextAlphaBits=3D4" "-dBATCH" >> + "-dGraphicsAlphaBits=3D4" "-dQUIET") >> "A list of options to give to ghostscript." >> :type '(repeat string)) >>=20=20 >> +(defcustom doc-view-ghostscript-device "png16m" >> + "Output device to give to ghostscript." >> + :type 'string >> + :version "27.1") >> + >> (defcustom doc-view-resolution 100 >> "Dots per inch resolution used to render the documents. >> Higher values result in larger images." >> @@ -950,16 +955,30 @@ doc-view-dvi->pdf >> (list "-o" pdf dvi) >> callback))) >>=20=20 >> +(defun doc-view-pdf-password-protected-p (pdf) >> + "Using Ghostscript, check if a PDF file is password-protected." >> + (with-temp-buffer >> + (apply #'call-process doc-view-ghostscript-program nil (current-buf= fer) >> + nil `(,@doc-view-ghostscript-options >> + "-sNODISPLAY" >> + ,pdf)) >> + (goto-char (point-min)) >> + (search-forward "This file requires a password for access." nil t))) >> + >> (defun doc-view-pdf->png-converter-ghostscript (pdf png page callback) >> - (doc-view-start-process >> - "pdf/ps->png" doc-view-ghostscript-program >> - `(,@doc-view-ghostscript-options >> - ,(format "-r%d" (round doc-view-resolution)) >> - ,@(if page `(,(format "-dFirstPage=3D%d" page))) >> - ,@(if page `(,(format "-dLastPage=3D%d" page))) >> - ,(concat "-sOutputFile=3D" png) >> - ,pdf) >> - callback)) >> + (let ((pdf-passwd (if (doc-view-pdf-password-protected-p pdf) >> + (read-passwd "Enter password for PDF file: ")))) >> + (doc-view-start-process >> + "pdf/ps->png" doc-view-ghostscript-program >> + `(,@doc-view-ghostscript-options >> + ,(concat "-sDEVICE=3D" doc-view-ghostscript-device) >> + ,(format "-r%d" (round doc-view-resolution)) >> + ,@(if page `(,(format "-dFirstPage=3D%d" page))) >> + ,@(if page `(,(format "-dLastPage=3D%d" page))) >> + ,@(if pdf-passwd `(,(format "-sPDFPassword=3D%s" pdf-passwd))) >> + ,(concat "-sOutputFile=3D" png) >> + ,pdf) >> + callback))) >>=20=20 >> (defalias 'doc-view-ps->png-converter-ghostscript >> 'doc-view-pdf->png-converter-ghostscript) >