nextcloud / nextcloud/previewgenerator

TypeError: OC_Image::getOrientation(): Return value must be of type int, array returned

Open
#452 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug dependencies needs info
Dominant language
PHP
Stars
520
Forks
55
PR merge metrics
No merged PRs in 30d

Description

Hello,

I'm running Nextcloud 26.0.11 and previewgenerator 5.4.0.

I am in the process of regenerating the image previews. Unfortunately I get this error:

TypeError: OC_Image::getOrientation(): Return value must be of type int, array returned in /var/www/html/lib/private/legacy/OC_Image.php:460
Stack trace:
#0 /var/www/html/lib/private/legacy/OC_Image.php(494): OC_Image->getOrientation()
#1 /var/www/html/lib/private/Preview/Image.php(52): OC_Image->fixOrientation()
#2 /var/www/html/lib/private/Preview/GeneratorHelper.php(64): OC\Preview\Image->getThumbnail(Object(OC\Files\Node\File), 800, 800)
#3 /var/www/html/lib/private/Preview/Generator.php(440): OC\Preview\GeneratorHelper->getThumbnail(Object(OC\Preview\JPEG), Object(OC\Files\Node\File), 800, 800)
#4 /var/www/html/lib/private/Preview/Generator.php(164): OC\Preview\Generator->getMaxPreview(Object(OC\Files\SimpleFS\SimpleFolder), Object(OC\Files\Node\File), 'image/jpeg', '')
#5 /var/www/html/lib/private/PreviewManager.php(212): OC\Preview\Generator->generatePreviews(Object(OC\Files\Node\File), Array, 'image/jpeg')
#6 /var/www/html/custom_apps/previewgenerator/lib/Command/Generate.php(230): OC\PreviewManager->generatePreviews(Object(OC\Files\Node\File), Array)
#7 /var/www/html/custom_apps/previewgenerator/lib/Command/Generate.php(212): OCA\PreviewGenerator\Command\Generate->parseFile(Object(OC\Files\Node\File))
#8 /var/www/html/custom_apps/previewgenerator/lib/Command/Generate.php(181): OCA\PreviewGenerator\Command\Generate->parseFolder(Object(OC\Files\Node\Folder), Array)
#9 /var/www/html/custom_apps/previewgenerator/lib/Command/Generate.php(129): OCA\PreviewGenerator\Command\Generate->generatePathPreviews(Object(OC\User\User), '/fmasotti/files...')
#10 /var/www/html/3rdparty/symfony/console/Command/Command.php(255): OCA\PreviewGenerator\Command\Generate->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#11 /var/www/html/3rdparty/symfony/console/Application.php(1009): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#12 /var/www/html/3rdparty/symfony/console/Application.php(273): Symfony\Component\Console\Application->doRunCommand(Object(OCA\PreviewGenerator\Command\Generate), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 /var/www/html/3rdparty/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 /var/www/html/lib/private/Console/Application.php(211): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 /var/www/html/console.php(100): OC\Console\Application->run()
#16 /var/www/html/occ(11): require_once('/var/www/html/c...')

As a temporary solution I modified the source code (/var/www/html/lib/private/legacy/OC_Image.php) like this:

public function getOrientation(): int {

    // rest of the function

    $this->exif = $exif;
+   if (gettype($exif['Orientation']) == 'array') {
+       return -1;
+   }
    return $exif['Orientation'];
}

By returning -1, when an array is detected, the program continues its job. I can't do many experiments since this is a production environment.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in lib/private/legacy/OC_Image.php at getOrientation(), then trace the call from lib/private/Preview/Image.php during preview generation. Investigate how an array-valued Orientation is handled and verify that regenerating previews no longer raises the reported TypeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.