Skip to content

Commit

Permalink
version 4.5.3 (#1447)
Browse files Browse the repository at this point in the history
* version 4.5.3
* upgrade composer
* Apply fixes from PHP-CS-Fixer (#1449)
* Added sample file with undefined EXIF tag
* Fixed usage of `exif_read_data` in GdHandler

Co-authored-by: Matthias Nagel <[email protected]>
  • Loading branch information
ildyria and nagmat84 authored Aug 7, 2022
1 parent 9b44a8b commit fe173e4
Show file tree
Hide file tree
Showing 16 changed files with 370 additions and 271 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
coverage: none
- name: Install PHP-CS-Fixer
run: |
curl -L https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v3.3.2/php-cs-fixer.phar -o .github/build/php-cs-fixer
curl -L https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v3.9.5/php-cs-fixer.phar -o .github/build/php-cs-fixer
chmod a+x .github/build/php-cs-fixer
- name: Prepare Git User
run: |
Expand Down
8 changes: 8 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ function (PhpCsFixer\Finder $finder, $dir) {
'concat_space' => ['spacing' => 'one'],
'no_superfluous_phpdoc_tags' => false,
'phpdoc_to_comment' => false, // required until https://github.com/phpstan/phpstan/issues/7486 got fixed
'blank_line_between_import_groups' => false, // not PSR-12 compatible, but preserves old behaviour
'ordered_imports' => [
'sort_algorithm' => 'alpha',
'imports_order' => null, // for PSR-12 compatability, this need to be `['class', 'function', 'const']`, but no grouping preserves old behaviour
],
'no_unneeded_control_parentheses' => [
'statements' => ['break', 'clone', 'continue', 'echo_print', 'switch_case', 'yield'],
],
];
$config = new PhpCsFixer\Config();

Expand Down
2 changes: 1 addition & 1 deletion app/Actions/Install/RequirementsChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function check(array $requirements): array
$results['errors'] = false;
foreach ($requirements as $type => $requirement_) {
switch ($type) {
// check php requirements
// check php requirements
case 'php':
foreach ($requirement_ as $requirement) {
$hasExtension = extension_loaded($requirement);
Expand Down
20 changes: 10 additions & 10 deletions app/Actions/Photo/Strategies/RotateStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ public function do(): Photo

// Re-create original size variant of photo
$newOriginalSizeVariant = $this->photo->size_variants->create(
SizeVariant::ORIGINAL,
$targetFile->getRelativePath(),
$image->getDimensions(),
$streamStat->bytes
);
SizeVariant::ORIGINAL,
$targetFile->getRelativePath(),
$image->getDimensions(),
$streamStat->bytes
);

// Re-create remaining size variants
try {
Expand Down Expand Up @@ -163,11 +163,11 @@ public function do(): Photo
/** @var SizeVariant $newSizeVariant */
foreach ($newSizeVariants as $newSizeVariant) {
$duplicate->size_variants->create(
$newSizeVariant->type,
$newSizeVariant->short_path,
new ImageDimension($newSizeVariant->width, $newSizeVariant->height),
$newSizeVariant->filesize
);
$newSizeVariant->type,
$newSizeVariant->short_path,
new ImageDimension($newSizeVariant->width, $newSizeVariant->height),
$newSizeVariant->filesize
);
}
$duplicate->save();
}
Expand Down
16 changes: 8 additions & 8 deletions app/Assets/SizeVariantGroupedWithRandomSuffixNamingStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ public function setPhoto(?Photo $photo): void
// reported, we must be prepared for an optional `/` or `./`
// at the beginning.
if (\Safe\preg_match(
'#^\.?[/\\\\]?' .
self::VARIANT_2_PATH_PREFIX[SizeVariant::ORIGINAL] . '[/\\\\]' .
'([0-9a-f]{2})[/\\\\]' .
'([0-9a-f]{2})[/\\\\]' .
'([0-9a-f]{' . (self::NAME_LENGTH - 4) . '})\.#i',
$existingRelPath,
$matches
) === 1) {
'#^\.?[/\\\\]?' .
self::VARIANT_2_PATH_PREFIX[SizeVariant::ORIGINAL] . '[/\\\\]' .
'([0-9a-f]{2})[/\\\\]' .
'([0-9a-f]{2})[/\\\\]' .
'([0-9a-f]{' . (self::NAME_LENGTH - 4) . '})\.#i',
$existingRelPath,
$matches
) === 1) {
// If we have a match, we use the middle path of the original
// size variant
$this->cachedRndMiddlePath = $matches[1] . DIRECTORY_SEPARATOR . $matches[2] . DIRECTORY_SEPARATOR . $matches[3];
Expand Down
29 changes: 26 additions & 3 deletions app/Image/GdHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Image;

use App\DTO\ImageDimension;
use App\Exceptions\Handler;
use App\Exceptions\ImageProcessingException;
use App\Exceptions\Internal\LycheeDomainException;
use App\Exceptions\MediaFileOperationException;
Expand Down Expand Up @@ -176,10 +177,32 @@ public function load(MediaFile $file): void
// `exif_read_data` only supports JPEGs
if (in_array($this->gdImageType, [IMAGETYPE_JPEG, IMAGETYPE_JPEG2000], true)) {
error_clear_last();
// `exif_read_data` raises E_WARNING/E_NOTICE errors for unsupported
// tags, which could result in exceptions being thrown, even though
// the function would otherwise succeed to return valid tags.
// We explicitly disable this undesirable behavior and use
// the silence operator to suck out as much EXIF data as
// possible even if some EXIF tags are unsupported.
// As this way, `exif_read_data` does not throw any exception
// at all (even for catastrophic errors), we need to check
// manually, if we need to throw an exception.
// TODO: Replace `exif_read_data` by `\Safe\exif_read_data` after https://github.com/thecodingmachine/safe/issues/215 has been resolved
$exifData = exif_read_data($inputStream);
if ($exifData === false) {
throw ImageException::createFromPhpError();
// @phpstan-ignore-next-line
$exifData = @exif_read_data($inputStream);
$phpError = error_get_last();
if ($exifData === false || $phpError !== null) {
$exception = ImageException::createFromPhpError();
if ($exifData === false) {
// something went wrong catastrophically, throw the
// exception as `exif_read_data` would have done without @
throw $exception;
} else {
// exif_read_data() returned an array and has been able
// to extract some useful data, but still reported a
// warning; don't throw the exception, but log it and
// proceed
Handler::reportSafely($exception);
}
}

// Auto-rotate image
Expand Down
16 changes: 8 additions & 8 deletions app/Metadata/Extractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,15 @@ public static function createFromFile(NativeLocalFile $file): self
// that timezone.
$taken_at->setTimezone(new \DateTimeZone(date_default_timezone_get()));
}
// In the remaining cases the timezone information was
// extracted and the recording time is assumed exhibit
// to original timezone of the location where the video
// has been recorded.
// So we don't need to do anything.
// In the remaining cases the timezone information was
// extracted and the recording time is assumed exhibit
// to original timezone of the location where the video
// has been recorded.
// So we don't need to do anything.
//
// The only known example are the mov files from Apple
// devices; the time zone will be formatted as "+01:00"
// so neither of the two conditions above should trigger.
// The only known example are the mov files from Apple
// devices; the time zone will be formatted as "+01:00"
// so neither of the two conditions above should trigger.
} elseif ($taken_at->getTimezone()->getName() === 'Z') {
// This is a video format where we expect the takestamp
// to be provided in local time but the timezone is
Expand Down
3 changes: 1 addition & 2 deletions app/Metadata/GitHubFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,7 @@ public function checkUpdates(): array
return [
'update_json' => intval($json->lychee->version),
'update_available' => (
(Configs::getValueAsInt('version')) <
$json->lychee->version
Configs::getValueAsInt('version') < $json->lychee->version
),
];
} catch (\Throwable $e) {
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"laravel/framework": "^8.83.14",
"livewire/livewire": "^2.7",
"lychee-org/nestedset": "^6",
"lychee-org/php-exif": "^0.7.10",
"lychee-org/php-exif": "^0.7.11",
"maennchen/zipstream-php": "^2.1",
"php-ffmpeg/php-ffmpeg": "^1.0",
"php-http/guzzle7-adapter": "^1.0",
Expand Down
Loading

0 comments on commit fe173e4

Please sign in to comment.