From 43ada3fcd44b35bdbf8771ec409146848bd158b7 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Mon, 3 Jun 2019 09:36:00 +0200 Subject: [PATCH] FIX better method to check if pdf is protected/encrypted --- htdocs/core/lib/pdf.lib.php | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index 14c0435b4ad..1932fca31a2 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -175,18 +175,29 @@ function pdf_getInstance($format = '', $metric = 'mm', $pagetype = 'P') /** * Return if pdf file is protected/encrypted * - * @param TCPDF $pdf PDF initialized object * @param string $pathoffile Path of file * @return boolean True or false */ -function pdf_getEncryption(&$pdf, $pathoffile) +function pdf_getEncryption($pathoffile) { + require_once TCPDF_PATH.'tcpdf_parser.php'; + $isencrypted = false; - $pdfparser = $pdf->_getPdfParser($pathoffile); - $data = $pdfparser->getParsedData(); - if (isset($data[0]['trailer'][1]['/Encrypt'])) { - $isencrypted = true; + $content = file_get_contents($pathoffile); + + ob_start(); + @($parser = new \TCPDF_PARSER(ltrim($content))); + list($xref, $data) = $parser->getParsedData(); + unset($parser); + ob_end_clean(); + + if (isset($xref['trailer']['encrypt'])) { + $isencrypted = true; // Secured pdf file are currently not supported + } + + if (empty($data)) { + $isencrypted = true; // Object list not found. Possible secured file } return $isencrypted;