nextcloud / previewgenerator

Nextcloud app to do preview generation in the background.
https://apps.nextcloud.com/apps/previewgenerator
GNU Affero General Public License v3.0
450 stars 56 forks source link

Preview Generation stop when encrypted PDF file occurs #329

Closed major-mayer closed 1 year ago

major-mayer commented 1 year ago

Of course, it's not possible to generate previews for encrypted PDFs, but this shouldn't stop the process of preview generation. When I just browse through the files app, an error is created in the logs, but Nextcloud continues to run.

The preview generator reports the following:

2022-11-23T17:02:17+00:00 Generating previews for /path/to/my/Antrag.pdf
                 Cannot decrypt PDF file.
   **** The file was produced by: 
   **** >>>> �N5.T}�6   ߀#1^������0�Y���8���

And in the Nextcloud logs this appears:

[core] Fehler: ImagickException: Failed to read the file at <<closure>>

 0. /var/www/html/lib/private/Preview/Bitmap.php line 95
    Imagick->readImage("/var/www/html/d ... ]")
 1. /var/www/html/lib/private/Preview/Bitmap.php line 56
    OC\Preview\Bitmap->getResizedPreview("/var/www/html/d ... f", 2048, 2048)
 2. /var/www/html/lib/private/Preview/GeneratorHelper.php line 65
    OC\Preview\Bitmap->getThumbnail(OC\Files\Node\File {}, 2048, 2048)
 3. /var/www/html/lib/private/Preview/Generator.php line 335
    OC\Preview\GeneratorHelper->getThumbnail(OC\Preview\PDF {}, OC\Files\Node\File {}, 2048, 2048)
 4. /var/www/html/lib/private/Preview/Generator.php line 159
    OC\Preview\Generator->getMaxPreview(OC\Files\SimpleFS\SimpleFolder {}, OC\Files\Node\File {}, "application/pdf", "")
 5. /var/www/html/lib/private/PreviewManager.php line 227
    OC\Preview\Generator->generatePreviews(OC\Files\Node\File {}, [[32,32,true],[6 ... ]], "application/pdf")
 6. /var/www/html/custom_apps/previewgenerator/lib/Command/Generate.php line 234
    OC\PreviewManager->generatePreviews(OC\Files\Node\File {}, [[32,32,true],[6 ... ]])
 7. /var/www/html/custom_apps/previewgenerator/lib/Command/Generate.php line 216
    OCA\PreviewGenerator\Command\Generate->parseFile(OC\Files\Node\File {})
 8. /var/www/html/custom_apps/previewgenerator/lib/Command/Generate.php line 214
    OCA\PreviewGenerator\Command\Generate->parseFolder(OC\Files\Node\Folder {}, [])
 9. /var/www/html/custom_apps/previewgenerator/lib/Command/Generate.php line 214
    OCA\PreviewGenerator\Command\Generate->parseFolder(OC\Files\Node\Folder {}, [])
10. /var/www/html/custom_apps/previewgenerator/lib/Command/Generate.php line 214
    OCA\PreviewGenerator\Command\Generate->parseFolder(OC\Files\Node\Folder {}, [])
11. /var/www/html/custom_apps/previewgenerator/lib/Command/Generate.php line 214
    OCA\PreviewGenerator\Command\Generate->parseFolder(OC\Files\Node\Folder {}, [])
12. /var/www/html/custom_apps/previewgenerator/lib/Command/Generate.php line 194
    OCA\PreviewGenerator\Command\Generate->parseFolder(OC\Files\Node\Folder {}, [])
13. /var/www/html/custom_apps/previewgenerator/lib/Command/Generate.php line 140
    OCA\PreviewGenerator\Command\Generate->generateUserPreviews("*** sensitive parameters replaced ***")
14. /var/www/html/lib/private/User/Manager.php line 651
    OCA\PreviewGenerator\Command\Generate->OCA\PreviewGenerator\Command\{closure}("*** sensitive parameters replaced ***")
15. /var/www/html/custom_apps/previewgenerator/lib/Command/Generate.php line 141
    OC\User\Manager->callForSeenUsers(Closure {})
16. /var/www/html/3rdparty/symfony/console/Command/Command.php line 255
    OCA\PreviewGenerator\Command\Generate->execute(Symfony\Componen ... {}, Symfony\Componen ... {})
17. /var/www/html/3rdparty/symfony/console/Application.php line 1009
    Symfony\Component\Console\Command\Command->run(Symfony\Componen ... {}, Symfony\Componen ... {})
18. /var/www/html/3rdparty/symfony/console/Application.php line 273
    Symfony\Component\Console\Application->doRunCommand(OCA\PreviewGenerator\Command\Generate {}, Symfony\Componen ... {}, Symfony\Componen ... {})
19. /var/www/html/3rdparty/symfony/console/Application.php line 149
    Symfony\Component\Console\Application->doRun(Symfony\Componen ... {}, Symfony\Componen ... {})
20. /var/www/html/lib/private/Console/Application.php line 211
    Symfony\Component\Console\Application->run(Symfony\Componen ... {}, Symfony\Componen ... {})
21. /var/www/html/console.php line 100
    OC\Console\Application->run()
22. /var/www/html/occ line 11
    require_once("/var/www/html/console.php")

at 2022-11-23T17:02:22+00:00
st3iny commented 1 year ago

I'll see if there is a way to handle this case gracefully.

major-mayer commented 1 year ago

Thank you, this would be great

st3iny commented 1 year ago

I tried to reproduce it but it worked as expected on my instance. The generation failed for the encrypted PDFs but continued with other previews.

Are you sure that the generation stops on the first error?

major-mayer commented 1 year ago

Hmm interesting, I've just tried it out once again with another password protected PDF and this time the preview generation process was not stopped.

 docker exec -u www-data nextcloudfpm ./occ preview:pre-generate -vvv
2022-12-07T21:55:13+00:00 Generating previews for /laurenz/files/Ablage/3.pdf
   **** This file requires a password for access.
Error: /invalidfileaccess in pdf_process_Encrypt
Operand stack:

Execution stack:
   %interp_exit   .runexec2   --nostringval--   runpdf   --nostringval--   2   %stopped_push   --nostringval--   runpdf   runpdf   false   1   %stopped_push   1990   1   3   %oparray_pop   1989   1   3   %oparray_pop   1977   1   3   %oparray_pop   1978   1   3   %oparray_pop   runpdf   runpdf   runpdf   runpdf   false   1   %stopped_push
Dictionary stack:
   --dict:739/1123(ro)(G)--   --dict:1/20(G)--   --dict:80/200(L)--   --dict:80/200(L)--   --dict:133/256(ro)(G)--   --dict:320/325(ro)(G)--   --dict:29/32(L)--
Current allocation mode is local
Last OS error: No such file or directory
GPL Ghostscript 9.53.3: Unrecoverable error, exit code 1
2022-12-07T21:55:16+00:00 Generating previews for /laurenz/files/Ablage/IMG_20220913_224425289 (1).jpg

I will close this then as not reproducible.