Bug 130354 - Cannot sign existing PDF, ' .tmp does not exist' from 6.4
Summary: Cannot sign existing PDF, ' .tmp does not exist' from 6.4
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Printing and PDF export (show other bugs)
Version:
(earliest affected)
6.4.0.3 release
Hardware: x86-64 (AMD64) All
: high major
Assignee: Miklos Vajna
URL:
Whiteboard: target:7.1.0 target:7.0.0.1 target:...
Keywords: bibisected, bisected, regression
: 132821 132866 (view as bug list)
Depends on:
Blocks: Digital-Signatures
  Show dependency treegraph
 
Reported: 2020-02-01 19:37 UTC by akrathod@protonmail.com
Modified: 2020-06-16 19:32 UTC (History)
8 users (show)

See Also:
Crash report or crash signature:


Attachments
Sample of the hybrid PDF which i could not sign using a (90.26 KB, application/pdf)
2020-02-18 22:10 UTC, akrathod@protonmail.com
Details
sign test (6.37 KB, application/pdf)
2020-03-04 12:24 UTC, moritz.herrmann
Details
libreoffice draw screenshot with the error I get (73.68 KB, image/png)
2020-05-20 12:52 UTC, Ioannis
Details
A PDF that can't be signed. (94.72 KB, application/pdf)
2020-06-04 12:36 UTC, Héctor Alexis Pérez Cifuentes
Details

Note You need to log in before you can comment on or make changes to this bug.
Description akrathod@protonmail.com 2020-02-01 19:37:52 UTC
When i try to sign a hybrid PDF, i get a variation of the following error message - '/home/rathodsa/Documents/lu166643uvpj7.tmp does not exist'. the variation is in temp file name.

Background
LinuxMint 19.3, 64 bit
The error occurs whether the PDF is a regular, hybrid, archive, single or multi page, form, etc. 
I am using a GPG certificate.  
Confirm that I can sign a document in ODT format.

This is reproducible at least in 6.3.2.  i don't know if it happened before that version.
Comment 1 ian 2020-02-18 14:24:00 UTC Comment hidden (obsolete)
Comment 2 akrathod@protonmail.com 2020-02-18 22:10:59 UTC
Created attachment 157991 [details]
Sample of the hybrid PDF which i could not sign using a

As requested, I have added a sample PDF that i created in LibreOffice 6.3.2.
Comment 3 moritz.herrmann 2020-03-04 12:23:33 UTC
Hi,
I have the same problem on arch linux.
If I try to sign a just exported pdf file I'll get the same error.

Version: 6.4.1.2
Build ID: 6.4.1-1
CPU threads: 8; OS: Linux 5.5; UI render: default; VCL: kf5; 
Locale: de-DE (en_US.UTF-8); UI-Language: en-US
Comment 4 moritz.herrmann 2020-03-04 12:24:28 UTC
Created attachment 158381 [details]
sign test
Comment 5 Dieter 2020-03-04 16:10:09 UTC
(In reply to moritz.herrmann from comment #3)
> Hi,
> I have the same problem on arch linux.
> If I try to sign a just exported pdf file I'll get the same error.

=> NEW
Comment 6 Robert 2020-04-19 09:37:58 UTC
I experience the same bug on Opensuse Tumbleweed with PDFs generated with LaTeX and any other PDF I tried.

Information for package libreoffice-draw:
-----------------------------------------
Repository     : openSUSE-Tumbleweed-Oss    
Name           : libreoffice-draw           
Version        : 6.4.3.2-1.2                
Arch           : x86_64                     
Vendor         : openSUSE                   
Installed Size : 583.0 KiB                  
Installed      : Yes                        
Status         : up-to-date                 
Source package : libreoffice-6.4.3.2-1.2.src
Summary        : LibreOffice Draw
Comment 7 Ioannis 2020-05-20 12:52:27 UTC
Created attachment 161038 [details]
libreoffice draw screenshot with the error I get

I am also affected by the bug.

I cannot sign an existing PDF.

Furthermore, I cannot view existing digital signatures, although LO Draw reports:
"This document is digitally signed and the signature is valid".

In the attached PNG, you can see the error I get
when I click on "Show Signatures".

Regards,
Yannis


For me, "lsb_release -a" gives
LSB Version:	core-11.1.0ubuntu2-noarch:security-11.1.0ubuntu2-noarch
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04 LTS
Release:	20.04
Codename:	focal

and "dpkg -l | grep '^ii *libreoffice'" gives
libreoffice-base 1:6.4.3-0ubuntu0.20.04.1
libreoffice-base-core 1:6.4.3-0ubuntu0.20.04.1
libreoffice-base-drivers 1:6.4.3-0ubuntu0.20.04.1
libreoffice-calc 1:6.4.3-0ubuntu0.20.04.1
libreoffice-common 1:6.4.3-0ubuntu0.20.04.1
libreoffice-core 1:6.4.3-0ubuntu0.20.04.1
libreoffice-draw 1:6.4.3-0ubuntu0.20.04.1
libreoffice-emailmerge 1:5.0.3~rc2-0ubuntu1~trusty2
libreoffice-gnome 1:6.4.3-0ubuntu0.20.04.1
libreoffice-gtk2 1:6.4.3-0ubuntu0.20.04.1
libreoffice-gtk3 1:6.4.3-0ubuntu0.20.04.1
libreoffice-help-common 1:6.4.3-0ubuntu0.20.04.1
libreoffice-help-en-gb 1:6.4.3-0ubuntu0.20.04.1
libreoffice-help-en-us 1:6.4.3-0ubuntu0.20.04.1
libreoffice-impress 1:6.4.3-0ubuntu0.20.04.1
libreoffice-java-common 1:6.4.3-0ubuntu0.20.04.1
libreoffice-l10n-en-gb 1:6.4.3-0ubuntu0.20.04.1
libreoffice-l10n-en-za 1:6.4.3-0ubuntu0.20.04.1
libreoffice-math 1:6.4.3-0ubuntu0.20.04.1
libreoffice-ogltrans 1:6.4.3-0ubuntu0.20.04.1
libreoffice-pdfimport 1:6.4.3-0ubuntu0.20.04.1
libreoffice-presentation-minimizer 1:5.0.3~rc2-0ubuntu1~trusty2
libreoffice-presenter-console 1:5.0.3~rc2-0ubuntu1~trusty2
libreoffice-sdbc-firebird 1:6.4.3-0ubuntu0.20.04.1
libreoffice-style-breeze 1:6.4.3-0ubuntu0.20.04.1
libreoffice-style-colibre 1:6.4.3-0ubuntu0.20.04.1
libreoffice-style-elementary 1:6.4.3-0ubuntu0.20.04.1
libreoffice-style-tango 1:6.4.3-0ubuntu0.20.04.1
libreoffice-writer 1:6.4.3-0ubuntu0.20.04.1
Comment 8 Timur 2020-05-20 13:51:52 UTC Comment hidden (obsolete)
Comment 9 Ioannis 2020-05-20 14:29:19 UTC
Let me give more details:
  - I use LibreOffice 6.4
  - I create an ODT file with Write: foo.odt
  - I export it to PDF which I sign with my x509 certificate: foo.pdf
  - I check foo.pdf using e.g. Adobe acrobat on another computer, and the signature is OK.
  - I open foo.pdf with LibreOffice Draw, and face the errors I described in my previous comment.


I remember having problems with pdf files in the past, trying to add an access password, and it was related to "policy" issues not allowing to access the pdf file.
Could the signing problem be due to something like this?
Comment 10 Timur 2020-05-21 07:29:08 UTC
Reporter akrathod used GPG anf that's likely a duplicate. 
moritz and Robert said "the same", but without conforming the cert.

Ioannis, I didn't understand, you say you sign with X509 and bug happens after that, when you just open in Draw, or sign again, please clarify.
Comment 11 Danilo Šegan 2020-05-24 09:42:26 UTC
There seem to be a problem somewhere in tempfile generation when attempting to start digital signing.  I've also tried LibreOffice 7.0alpha1 (LibreOfficeDev 7.0.0.0.alpha1 6a03b2a54143a9bc0c6d4c7f190b77cdc5a14733) and it behaves the same as LibreOffice 6.4.3 on Ubuntu 20.04 and the 18.04 (LibreOffice 6.4.3.2 747b5d0ebf89f41c860ec2a39efd7cb15b54f2d8).

Attempting to sign *any* existing PDF works behaves exactly the same:

 * libreoffice6.4 --view /tmp/a.pdf
 * Click on "Sign document"
 * I get a pop-up saying "/tmp/lu12004kv2p7v.tmp does not exist"
 * Without closing the pop-up, I can see a /tmp/lu12004kv2p7t.tmp directory containing lu12004kv2p7u.tmp file — note how it complains about not finding path with "v" in the name, there is a directory with "t" containing a file with "u".
 * After closing it, it pops-up another 4 times with exactly the same message (for a total of 5 times).
 * Attempting to re-sign it seems to use the same temporary file paths (i.e. the pop-up message remains the same).

(FWIW, attempting to "touch /tmp/lu12004kv2p7v.tmp" or "mkdir /tmp/lu12004kv2p7v.tmp" does not make it continue working, but it was probably already too late to "fix it up", i.e. the file handle is open already)
Comment 12 Danilo Šegan 2020-05-24 10:34:47 UTC
I've started following the tempfile creation logic would guess some tempfile creation logic around

  https://cgit.freedesktop.org/libreoffice/core/tree/xmlsecurity/source/helper/documentsignaturemanager.cxx#n227
  https://cgit.freedesktop.org/libreoffice/core/tree/xmlsecurity/source/helper/pdfsignaturehelper.cxx#n123
  https://cgit.freedesktop.org/libreoffice/core/tree/unotools/source/ucbhelper/ucbstreamhelper.cxx#n46

is related, but for someone unfamiliar with LibreOffice code and without a dev environment, it's hard to test any hypothesis, and it's quickly turning into a rabbit hole.

Is there a debug build for x64 Linux system with which I can see SAL_INFO/SAL_WARN messages on the console?

FWIW, my Firefox has a security token device set up (AET SafeSign smart card), but signing an ODF file works well, so the problem seems to strictly be in some of the temp streams being created and then wrong file paths being used.
Comment 13 Danilo Šegan 2020-05-24 10:47:10 UTC
And I have a strong suspicion is that the error being thrown is ERRCODE_IO_NOTEXISTS (error message matches) — https://cgit.freedesktop.org/libreoffice/core/tree/uui/inc/ids.hrc#n83

Forgot to mention that the number of times a pop-up shows up seems to depend on the PDF file size (on smaller PDF file like http://africau.edu/images/default/sample.pdf, I only got it twice).
Comment 14 Danilo Šegan 2020-05-24 11:17:48 UTC
Another data point: signing works with older LibreOffice version (LibreOffice 6.3.6.2 2196df99b074d8a661f4036fca8fa0cbfa33a497) from https://downloadarchive.documentfoundation.org/libreoffice/old/6.3.6.2/deb/x86_64/LibreOffice_6.3.6.2_Linux_x86-64_deb.tar.gz

I guess people can use this as a work-around.

(And I'll stop spamming now :))
Comment 15 Ioannis 2020-05-24 12:50:38 UTC
Danilo, thank you for getting me to this direction.

I downloaded the libreoffice source code and think I found the file where the buggy code is:
libreoffice/sal/osl/unx/tempfile.cxx


Checking the "sign document" behaviour,
I saw that after the first error pops up,
if I touch the reported file in /tmp instead of the path suggested,
no more error popups come out!

It seems that the temporary file in question should be created as
/tmp/lu<PID number><some letters>.tmp
instead of being searched in the PDF location path.

So, I guess that the problem is the way the prepended path is handled in the suspicious file (libreoffice/sal/osl/unx/tempfile.cxx).
Comment 17 Timur 2020-05-29 08:57:20 UTC
*** Bug 132821 has been marked as a duplicate of this bug. ***
Comment 18 Héctor Alexis Pérez Cifuentes 2020-05-29 13:30:58 UTC Comment hidden (me-too)
Comment 19 Héctor Alexis Pérez Cifuentes 2020-05-29 13:31:36 UTC
Same problem here, With version 7.x and 6.4.x.

Thanks in advance.
Comment 20 Buovjaga 2020-05-29 16:04:41 UTC
(In reply to Danilo Šegan from comment #11)
> Attempting to sign *any* existing PDF works behaves exactly the same:
> 
>  * libreoffice6.4 --view /tmp/a.pdf
>  * Click on "Sign document"
>  * I get a pop-up saying "/tmp/lu12004kv2p7v.tmp does not exist"
>  * Without closing the pop-up, I can see a /tmp/lu12004kv2p7t.tmp directory
> containing lu12004kv2p7u.tmp file — note how it complains about not finding
> path with "v" in the name, there is a directory with "t" containing a file
> with "u".
>  * After closing it, it pops-up another 4 times with exactly the same
> message (for a total of 5 times).
>  * Attempting to re-sign it seems to use the same temporary file paths (i.e.
> the pop-up message remains the same).
> 
> (FWIW, attempting to "touch /tmp/lu12004kv2p7v.tmp" or "mkdir
> /tmp/lu12004kv2p7v.tmp" does not make it continue working, but it was
> probably already too late to "fix it up", i.e. the file handle is open
> already)

Bibisected with Linux 6.4 repo to https://git.libreoffice.org/core/+/9112c18524c9f5e67d6cbb282586a439e3020cdb%5E!/
Don't create unnecessary tempfiles for opened doc

Adding Cc: to Samuel Mehrbrodt
Comment 21 Timur 2020-05-30 08:37:48 UTC
(In reply to Danilo Šegan from comment #12)
> Is there a debug build for x64 Linux system with which I can see
> SAL_INFO/SAL_WARN messages on the console?
Yes, seen on https://dev-builds.libreoffice.org/daily/master/current.html.
Comment 22 Miklos Vajna 2020-06-02 11:58:07 UTC
I'll take a look.
Comment 23 Commit Notification 2020-06-02 17:01:49 UTC
Miklos Vajna committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/058caeef45f9abf12e4e243aafbbb1c2ebcbc057

tdf#130354 sfx2: make PDF signing UI work again

It will be available in 7.1.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 24 Commit Notification 2020-06-03 07:08:08 UTC
Miklos Vajna committed a patch related to this issue.
It has been pushed to "libreoffice-7-0":

https://git.libreoffice.org/core/commit/35ec66f8766bd3d8f17c9e0ea68d1e260a9fbc32

tdf#130354 sfx2: make PDF signing UI work again

It will be available in 7.0.0.1.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 25 Héctor Alexis Pérez Cifuentes 2020-06-03 17:42:30 UTC
Thanks very much, is working in 7.1 dev edition, but take care it doesn't work on certain PDFs, I think they are the compressed ones.
Comment 26 Timur 2020-06-04 06:11:31 UTC
 Héctor, please attach a pdf where it doesn't work, if not private.
Comment 27 Timur 2020-06-04 07:07:47 UTC
*** Bug 132866 has been marked as a duplicate of this bug. ***
Comment 28 Commit Notification 2020-06-04 10:47:03 UTC
Miklos Vajna committed a patch related to this issue.
It has been pushed to "libreoffice-6-4":

https://git.libreoffice.org/core/commit/b52d304969a15e00d82745f4d2f96c04f188eb97

tdf#130354 sfx2: make PDF signing UI work again

It will be available in 6.4.5.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 29 Héctor Alexis Pérez Cifuentes 2020-06-04 12:36:19 UTC
Created attachment 161609 [details]
A PDF that can't be signed.

A PDF that can't be signed, this PDF can't be signed, If You export It to a LibreOffice PDF and Re-Sign I works.
Comment 30 Héctor Alexis Pérez Cifuentes 2020-06-04 12:37:11 UTC Comment hidden (obsolete)
Comment 31 Miklos Vajna 2020-06-04 12:38:04 UTC
Please open a separate bug for that. Thanks.
Comment 32 Timur 2020-06-05 07:25:01 UTC
(In reply to Héctor Alexis Pérez Cifuentes from comment #25)
> Thanks very much, is working in 7.1 dev edition, but take care it doesn't
> work on certain PDFs, I think they are the compressed ones.

Bug 104815.
Comment 33 Timur 2020-06-05 07:35:35 UTC
(In reply to akrathod@protonmail.com from comment #0)
> When i try to sign a hybrid PDF
Bug 108808.

> I am using a GPG certificate.  
Bug 113278 and Bug 115884.