Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: PDFtk binary is invalid #3000

Closed
stepcellwolf opened this issue May 10, 2024 · 8 comments · Fixed by #3112
Closed

Error: PDFtk binary is invalid #3000

stepcellwolf opened this issue May 10, 2024 · 8 comments · Fixed by #3112
Labels
bug Something isn't working

Comments

@stepcellwolf
Copy link

Describe the bug and to reproduce
When I try to run the following command sudo -u nextcloud php8.2 --define apc.enable_cli=1 occ libresign:install --pdftk I do not get any error, where on the interface in NC version 28.0.5 and PHP Version: 8.2.18 on yunohost version 11.2.11.3 (stable).

Expected behavior
It should install.

Screenshots
image

Environment information (please complete the following information):

  • OS: Linux Debian
  • Browser either, safari, firefox and chrome
  • LibreSign Version 8.0.1
  • Nextcloud Server Version 28.0.5
  • No Logs

Additional context
I also installed pdftk with apt install pdftk output:

pdftk port to java 3.2.2 a Handy Tool for Manipulating PDF Documents
Copyright (c) 2017-2018 Marc Vinyals - https://gitlab.com/pdftk-java/pdftk
Copyright (c) 2003-2013 Steward and Lee, LLC.
pdftk includes a modified version of the iText library.
Copyright (c) 1999-2009 Bruno Lowagie, Paulo Soares, et al.
This is free software; see the source code for copying conditions. There is
NO warranty, not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Any idea what might be the problem? Thanks in advance.

@stepcellwolf stepcellwolf added the bug Something isn't working label May 10, 2024
@vitormattos
Copy link
Member

This is the point at code that throw this error:

$javaPath = $this->appConfig->getAppValue('java_path');
\exec($javaPath . ' -jar ' . $pdftkPath . " --version 2>&1", $version);
if (isset($version[0])) {
preg_match('/pdftk port to java (?<version>.*) a Handy Tool/', $version[0], $matches);
if (isset($matches['version'])) {
if ($matches['version'] === InstallService::PDFTK_VERSION) {
$return[] = (new ConfigureCheckHelper())
->setSuccessMessage('PDFtk version: ' . InstallService::PDFTK_VERSION)
->setResource('pdftk');
$return[] = (new ConfigureCheckHelper())
->setSuccessMessage('PDFtk path: ' . $pdftkPath)
->setResource('pdftk');
return $return;
}
$message = 'Necessary install the version ' . InstallService::PDFTK_VERSION;
$return[] = (new ConfigureCheckHelper())
->setErrorMessage($message)
->setResource('jsignpdf')
->setTip('Run occ libresign:install --jsignpdf');
}
}
return [
(new ConfigureCheckHelper())
->setErrorMessage('PDFtk binary is invalid: ' . $pdftkPath)
->setResource('pdftk')
->setTip('Run occ libresign:install --pdftk'),
];

You can try to mount the exec command with the path of downloaded files to check what's returned by --version.

Sounds that the return is empty or is an error in your case.

@mashedkeyboard
Copy link

I'm having this same issue, but am seeing a correct output from that command:

curtispf@server:~$ sudo -u www-data java -jar /var/www/cloud/data/appdata_PATH/libresign/pdftk.jar  --version
pdftk port to java 3.3.3 a Handy Tool for Manipulating PDF Documents
Copyright (c) 2017-2018 Marc Vinyals - https://gitlab.com/pdftk-java/pdftk
Copyright (c) 2003-2013 Steward and Lee, LLC.
pdftk includes a modified version of the iText library.
Copyright (c) 1999-2009 Bruno Lowagie, Paulo Soares, et al.
This is free software; see the source code for copying conditions. There is
NO warranty, not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

@vitormattos
Copy link
Member

The way to identify the version of pdftk that I implemented is this regex that is applied at first row:

/pdftk port to java (?<version>.*) a Handy Tool/

The first row is:
pdftk port to java 3.3.3 a Handy Tool for Manipulating PDF Documents

And the expected value for now is 3.3.3

The message PDFtk binary is invalid only is displayed when the return of --version is not a text or if the regex not match with the first row.

I think that will be necessary put more debugs/log points to identify what happening.

@vitormattos
Copy link
Member

I put points of log to be possible follow the code execution. If possible, would be good if you apply this changes adding the log rows at your ConfigureCheckService.php.

To check the log output, you can use a tail with grep:

tail -f data/nextcloud.log |grep libresign

I will need the output of tail to be possible check what's happening.

diff --git a/lib/Service/Install/ConfigureCheckService.php b/lib/Service/Install/ConfigureCheckService.php
index ccc79b20c..c73ca4dc5 100644
--- a/lib/Service/Install/ConfigureCheckService.php
+++ b/lib/Service/Install/ConfigureCheckService.php
@@ -131,13 +131,21 @@ class ConfigureCheckService {
         */
        public function checkPdftk(): array {
                $pdftkPath = $this->appConfig->getAppValue('pdftk_path');
+               \OC::$server->getLogger()->debug('Path of PDFTK', ['app' => 'libresign', 'pdftk_path' => $pdftkPath]);
                if ($pdftkPath) {
+                       \OC::$server->getLogger()->debug('PDFTK exists', ['app' => 'libresign']);
                        if (file_exists($pdftkPath)) {
                                $javaPath = $this->appConfig->getAppValue('java_path');
                                \exec($javaPath . ' -jar ' . $pdftkPath . " --version 2>&1", $version);
+                               \OC::$server->getLogger()->debug('executed command', ['app' => 'libresign', 'command' => $javaPath . ' -jar ' . $pdftkPath . " --version 2>&1"]);
+                               \OC::$server->getLogger()->debug('output of version', ['app' => 'libresign', 'version' => $version]);
+                               \OC::$server->getLogger()->debug('Exists first row', ['app' => 'libresign', 'exists' => isset($version[0]) ? 'yes': 'no']);
                                if (isset($version[0])) {
+                                       \OC::$server->getLogger()->debug('First row', ['app' => 'libresign', 'version' => $version[0]]);
                                        preg_match('/pdftk port to java (?<version>.*) a Handy Tool/', $version[0], $matches);
+                                       \OC::$server->getLogger()->debug('Return of regex', ['app' => 'libresign', 'version' => $matches]);
                                        if (isset($matches['version'])) {
+                                               \OC::$server->getLogger()->debug('Version identified', ['app' => 'libresign', 'version' => $matches['version']]);
                                                if ($matches['version'] === InstallService::PDFTK_VERSION) {
                                                        $return[] = (new ConfigureCheckHelper())
                                                                        ->setSuccessMessage('PDFtk version: ' . InstallService::PDFTK_VERSION)

@Raymo111
Copy link

@vitormattos I'm getting the same issue, here's the debug logs with those statements added:

{"reqId":"XXXXXXXX","level":0,"time":"2024-05-30T19:46:33+00:00","remoteAddr":"XX.XX.XX.XX","user":"raymo","app":"libresign","method":"GET","url":"/nextcloud/ocs/v2.php/apps/libresign/api/v1/admin/configure-check","message":"Path of PDFTK","userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36","version":"29.0.1.1","data":{"app":"libresign","pdftk_path":"/data/data/appdata_ocuvueakr11p/libresign/pdftk.jar"}}
{"reqId":"XXXXXXXX","level":0,"time":"2024-05-30T19:46:33+00:00","remoteAddr":"XX.XX.XX.XX","user":"raymo","app":"libresign","method":"GET","url":"/nextcloud/ocs/v2.php/apps/libresign/api/v1/admin/configure-check","message":"PDFTK exists","userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36","version":"29.0.1.1","data":{"app":"libresign"}}
{"reqId":"XXXXXXXX","level":0,"time":"2024-05-30T19:46:33+00:00","remoteAddr":"XX.XX.XX.XX","user":"raymo","app":"libresign","method":"GET","url":"/nextcloud/ocs/v2.php/apps/libresign/api/v1/admin/configure-check","message":"executed command","userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36","version":"29.0.1.1","data":{"app":"libresign","command":" -jar /data/data/appdata_ocuvueakr11p/libresign/pdftk.jar --version 2>&1"}}
{"reqId":"XXXXXXXX","level":0,"time":"2024-05-30T19:46:33+00:00","remoteAddr":"XX.XX.XX.XX","user":"raymo","app":"libresign","method":"GET","url":"/nextcloud/ocs/v2.php/apps/libresign/api/v1/admin/configure-check","message":"output of version","userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36","version":"29.0.1.1","data":{"app":"libresign","version":"[\"sh: 1: -jar: not found\"]"}}
{"reqId":"XXXXXXXX","level":0,"time":"2024-05-30T19:46:33+00:00","remoteAddr":"XX.XX.XX.XX","user":"raymo","app":"libresign","method":"GET","url":"/nextcloud/ocs/v2.php/apps/libresign/api/v1/admin/configure-check","message":"Exists first row","userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36","version":"29.0.1.1","data":{"app":"libresign","exists":"yes"}}
{"reqId":"XXXXXXXX","level":0,"time":"2024-05-30T19:46:33+00:00","remoteAddr":"XX.XX.XX.XX","user":"raymo","app":"libresign","method":"GET","url":"/nextcloud/ocs/v2.php/apps/libresign/api/v1/admin/configure-check","message":"First row","userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36","version":"29.0.1.1","data":{"app":"libresign","version":"sh: 1: -jar: not found"}}
{"reqId":"XXXXXXXX","level":0,"time":"2024-05-30T19:46:33+00:00","remoteAddr":"XX.XX.XX.XX","user":"raymo","app":"libresign","method":"GET","url":"/nextcloud/ocs/v2.php/apps/libresign/api/v1/admin/configure-check","message":"Return of regex","userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36","version":"29.0.1.1","data":{"app":"libresign","version":"[]"}}

@Raymo111
Copy link

Raymo111 commented May 30, 2024

Seems like javaPath is empty, and indeed if I add this:

$javaPath = $this->appConfig->getAppValue('java_path');
+ \OC::$server->getLogger()->debug('java path', ['app' => 'libresign', 'javaPath' => $javaPath]);

I get

{"reqId":"XXXXXXXX","level":0,"time":"2024-05-30T19:53:14+00:00","remoteAddr":"XX.XX.XX.XX","user":"raymo","app":"libresign","method":"GET","url":"/nextcloud/ocs/v2.php/apps/libresign/api/v1/admin/configure-check","message":"java path","userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36","version":"29.0.1.1","data":{"app":"libresign","javaPath":""}}

@Raymo111
Copy link

I can fix it by installing java instead of using OS java, (occ libresign:install --java).

I see in @stepcellwolf's screenshot that he also didn't run that. Perhaps the java check should set java_path if OS java is detected, or OS java shouldn't be allowed at all?

@vitormattos
Copy link
Member

vitormattos commented May 31, 2024

if OS java is detected, or OS java shouldn't be allowed at all?

Will be complex to check if have Java installed at OS to use this and also could have side effects using a java version that isn't the same that is used by LibreSign.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants