From d0f30b4c288e0c5c0157c6d90a98b63c96dc8d56 Mon Sep 17 00:00:00 2001 From: Dusheyko Vladimir Date: Wed, 2 Apr 2025 17:40:09 +0700 Subject: [PATCH] issues/354 guaranteed call to restore_error_handler --- src/Convert/Converters/AbstractConverter.php | 54 +++++++++++--------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/src/Convert/Converters/AbstractConverter.php b/src/Convert/Converters/AbstractConverter.php index 685785d..b96400d 100644 --- a/src/Convert/Converters/AbstractConverter.php +++ b/src/Convert/Converters/AbstractConverter.php @@ -233,36 +233,40 @@ private function doConvertImplementation() $this->activateWarningLogger(); - $this->checkOptions(); + try { + $this->checkOptions(); - // Prepare destination folder - $this->createWritableDestinationFolder(); - $this->removeExistingDestinationIfExists(); + // Prepare destination folder + $this->createWritableDestinationFolder(); + $this->removeExistingDestinationIfExists(); - if (!isset($this->options['_skip_input_check'])) { - // Check that a file can be written to destination - $this->checkDestinationWritable(); - } + if (!isset($this->options['_skip_input_check'])) { + // Check that a file can be written to destination + $this->checkDestinationWritable(); + } - $this->checkOperationality(); - $this->checkConvertability(); + $this->checkOperationality(); + $this->checkConvertability(); - if ($this->options['log-call-arguments']) { - $this->logOptions(); - $this->logLn(''); - } + if ($this->options['log-call-arguments']) { + $this->logOptions(); + $this->logLn(''); + } - $this->runActualConvert(); + $this->runActualConvert(); - $source = $this->source; - $destination = $this->destination; + $source = $this->source; + $destination = $this->destination; + + if (!@file_exists($destination)) { + throw new ConversionFailedException('Destination file is not there: ' . $destination); + } + + if (@filesize($destination) === 0) { + @unlink($destination); + throw new ConversionFailedException('Destination file was completely empty'); + } - if (!@file_exists($destination)) { - throw new ConversionFailedException('Destination file is not there: ' . $destination); - } elseif (@filesize($destination) === 0) { - @unlink($destination); - throw new ConversionFailedException('Destination file was completely empty'); - } else { if (!isset($this->options['_suppress_success_message'])) { $this->ln(); $this->log('Converted image in ' . round((microtime(true) - $beginTime) * 1000) . ' ms'); @@ -273,9 +277,9 @@ private function doConvertImplementation() $this->logReduction($source, $destination); } } + } finally { + $this->deactivateWarningLogger(); } - - $this->deactivateWarningLogger(); } //private function logEx