File tree Expand file tree Collapse file tree
bundle/Controller/Resource Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1919use Symfony \Contracts \Translation \TranslatorInterface ;
2020
2121use function fclose ;
22+ use function filesize ;
2223use function fopen ;
2324use function fread ;
2425use function fseek ;
2728use function is_array ;
2829use function is_file ;
2930use function is_readable ;
30- use function filesize ;
3131use function preg_match ;
32- use function strrpos ;
3332use function strpos ;
33+ use function strrpos ;
3434use function strtolower ;
3535use function substr ;
3636
@@ -148,9 +148,6 @@ private function isEncryptedPdf(UploadedFile $file): bool
148148
149149 $ fileSize = filesize ($ path );
150150
151- // For small PDFs, `head` and `tail` reads can overlap and even fully duplicate the file contents.
152- // This can re-introduce false positives (e.g. `/Encrypt` in a trailing comment after `%%EOF`).
153- // In that case, scan the full content once.
154151 if ($ fileSize !== false && $ fileSize <= 20480 ) {
155152 $ content = (string ) fread ($ fp , $ fileSize );
156153 } else {
@@ -168,14 +165,11 @@ private function isEncryptedPdf(UploadedFile $file): bool
168165 return false ;
169166 }
170167
171- // Ignore anything after the last EOF marker (some tools append non-PDF comments/metadata).
172168 $ eofPos = strrpos ($ content , '%%EOF ' );
173169 if ($ eofPos !== false ) {
174170 $ content = substr ($ content , 0 , $ eofPos + 5 );
175171 }
176172
177- // Detect presence of encryption dictionary reference in PDF object context.
178- // This avoids false positives where `/Encrypt` appears in metadata or trailing comments.
179173 return (bool ) preg_match ('/\/(?:Encrypt)\s+(\d+|<<)/m ' , $ content );
180174 }
181175}
You can’t perform that action at this time.
0 commit comments