Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getPreview on a broken image shouldn't crash #7276

Open
leo-b opened this issue Nov 24, 2017 · 9 comments
Open

getPreview on a broken image shouldn't crash #7276

leo-b opened this issue Nov 24, 2017 · 9 comments
Labels

Comments

@leo-b
Copy link
Contributor

leo-b commented Nov 24, 2017

When trying to obtain a preview from a broken image file, nextcloud 12 currently crashes:

An unhandled exception has been thrown:
Error: Call to a member function file_get_contents() on null in /usr/local/nextcloud/nextcloud-12.0.2/lib/private/Files/Filesystem.php:717
Stack trace:
#0 /usr/local/nextcloud/nextcloud-12.0.2/lib/private/legacy/image.php(628): OC\Files\Filesystem::file_get_contents('/srv/nextcloud/...')
#1 /usr/local/nextcloud/nextcloud-12.0.2/lib/private/Preview/Image.php(57): OC_Image->loadFromFile('/srv/nextcloud/...')
#2 /usr/local/nextcloud/nextcloud-12.0.2/lib/private/Preview/GeneratorHelper.php(54): OC\Preview\Image->getThumbnail('/files/MALE/alb...', 2048, 2048, false, Object(OC\Files\View))
#3 /usr/local/nextcloud/nextcloud-12.0.2/lib/private/Preview/Generator.php(162): OC\Preview\GeneratorHelper->getThumbnail(Object(OC\Preview\JPEG), Object(OC\Files\Node\File), 2048, 2048)
#4 /usr/local/nextcloud/nextcloud-12.0.2/lib/private/Preview/Generator.php(110): OC\Preview\Generator->getMaxPreview(Object(OC\Files\SimpleFS\SimpleFolder), Object(OC\Files\Node\File), 'image/jpeg')
#5 /usr/local/nextcloud/nextcloud-12.0.2/lib/private/PreviewManager.php(201): OC\Preview\Generator->getPreview(Object(OC\Files\Node\File), 32, 32, true, 'fill', 'image/jpeg')
#6 /usr/local/nextcloud/nextcloud-12.0.2/apps/previewgenerator/lib/Command/PreGenerate.php(213): OC\PreviewManager->getPreview(Object(OC\Files\Node\File), 32, 32, true)
#7 /usr/local/nextcloud/nextcloud-12.0.2/apps/previewgenerator/lib/Command/PreGenerate.php(245): OCA\PreviewGenerator\Command\PreGenerate->processFile(Object(OC\Files\Node\File))
#8 /usr/local/nextcloud/nextcloud-12.0.2/apps/previewgenerator/lib/Command/PreGenerate.php(247): OCA\PreviewGenerator\Command\PreGenerate->processFolder(Object(OC\Files\Node\Folder))
#9 /usr/local/nextcloud/nextcloud-12.0.2/apps/previewgenerator/lib/Command/PreGenerate.php(247): OCA\PreviewGenerator\Command\PreGenerate->processFolder(Object(OC\Files\Node\Folder))
#10 /usr/local/nextcloud/nextcloud-12.0.2/apps/previewgenerator/lib/Command/PreGenerate.php(247): OCA\PreviewGenerator\Command\PreGenerate->processFolder(Object(OC\Files\Node\Folder))
#11 /usr/local/nextcloud/nextcloud-12.0.2/apps/previewgenerator/lib/Command/PreGenerate.php(201): OCA\PreviewGenerator\Command\PreGenerate->processFolder(Object(OC\Files\Node\Folder))
#12 /usr/local/nextcloud/nextcloud-12.0.2/apps/previewgenerator/lib/Command/PreGenerate.php(170): OCA\PreviewGenerator\Command\PreGenerate->processRow(Array)
#13 /usr/local/nextcloud/nextcloud-12.0.2/apps/previewgenerator/lib/Command/PreGenerate.php(137): OCA\PreviewGenerator\Command\PreGenerate->startProcessing()
#14 /usr/local/nextcloud/nextcloud-12.0.2/3rdparty/symfony/console/Command/Command.php(256): OCA\PreviewGenerator\Command\PreGenerate->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 /usr/local/nextcloud/nextcloud-12.0.2/3rdparty/symfony/console/Application.php(818): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#16 /usr/local/nextcloud/nextcloud-12.0.2/3rdparty/symfony/console/Application.php(186): Symfony\Component\Console\Application->doRunCommand(Object(OCA\PreviewGenerator\Command\PreGenerate), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#17 /usr/local/nextcloud/nextcloud-12.0.2/3rdparty/symfony/console/Application.php(117): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#18 /usr/local/nextcloud/nextcloud-12.0.2/lib/private/Console/Application.php(170): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#19 /usr/local/nextcloud/nextcloud-12.0.2/console.php(100): OC\Console\Application->run()
#20 /usr/local/nextcloud/nextcloud-12.0.2/occ(11): require_once('/usr/local/next...')
#21 {main}

(Tested with a .jpg file containing only null characters. Preview generation was triggered by the preview generator app.)

exif_imagetype($imagePath) fails determining the image type. The following file-type switch statement falls back to the default case and fails because Filesystem isn't configured:

			default:

				// this is mostly file created from encrypted file
				$this->resource = imagecreatefromstring(\OC\Files\Filesystem::file_get_contents(\OC\Files\Filesystem::getLocalPath($imagePath)));
				$iType = IMAGETYPE_PNG;
				$this->logger->debug('OC_Image->loadFromFile, Default', array('app' => 'core'));
				break;

My workaround for this is:

			default:

				// this is mostly file created from encrypted file
				if (\OC\Files\Filesystem::getView() === null) {
				    $this->logger->warning('LEO: Bad image: '.$imagePath);
				    $this->resource = file_get_contents($imagePath);
				    // return false;
				} else {
				    $this->resource = imagecreatefromstring(\OC\Files\Filesystem::file_get_contents(\OC\Files\Filesystem::getLocalPath($imagePath)));
				}
				$iType = IMAGETYPE_PNG;
				$this->logger->debug('OC_Image->loadFromFile, Default', array('app' => 'core'));
				break;

... which certainly isn't the optimal solution. (I don't know if the file contents are useful at all in this case.) But at least it doesn't crash.

@MorrisJobke
Copy link
Member

cc @rullzer

@nextcloud-bot nextcloud-bot added the stale Ticket or PR with no recent activity label Jun 20, 2018
@blizzz
Copy link
Member

blizzz commented Nov 5, 2018

Is this still a thing?

@nextcloud-bot nextcloud-bot removed the stale Ticket or PR with no recent activity label Nov 5, 2018
@rullzer
Copy link
Member

rullzer commented Nov 5, 2018

yeah it is.
I guess we can do better now with php7.

But I would need a broken jpg to test with

@skjnldsv skjnldsv added the 1. to develop Accepted and waiting to be taken care of label Jun 12, 2019
@matiasdelellis
Copy link

Hi @rullzer

The bug is still present. Come here for this report. matiasdelellis/facerecognition#295

But I would need a broken jpg to test with.

MMM.. The main problem is that Nexcloud trusts the extensions very much. if the file has .jpg extension, already returns mimetype 'image/jpeg'. I trust in this mimetype, and try to open it with OC_Image. and for example the file is an mp4 video, with jpeg extension (This is the case that started our bug report.), fails miserably as this report. 😓

So, here an example: https://delellis.com.ar/s/x7yw66odGqPCKwF

It is just an mp4 with jpg extension..

@cliffalbert
Copy link

I am experiencing the same issues. For example if a file with a .jpg extension is actually a html file it will generate this same problem.

@strugee
Copy link
Member

strugee commented Jul 27, 2020

You don't need an MP4 file or a corrupted picture to trigger this. Just create an empty file and stick .jpg onto the end of the filename. I've got a bunch of empty .jpg files lying around (legacy of a filesystem crash without proper backups...) and they consistently trigger this bug in the Face Recognition app.

@szaimen

This comment was marked as off-topic.

@szaimen szaimen added needs info 0. Needs triage Pending check for reproducibility or if it fits our roadmap and removed 1. to develop Accepted and waiting to be taken care of labels Jan 9, 2023
@skjnldsv skjnldsv added needs info 1. to develop Accepted and waiting to be taken care of and removed 0. Needs triage Pending check for reproducibility or if it fits our roadmap needs info labels Mar 1, 2023
@skjnldsv
Copy link
Member

skjnldsv commented Mar 1, 2023

Broken images as well as image with the wrong extension (ex webp image with a .jpg ext) are the issues here.

@AndyXheli
Copy link
Contributor

AndyXheli commented Apr 8, 2024

issue is back on NC 29 RC3. I never had this issue on NC28

{"reqId":"Y2cSu0jCTBYfp8BNu8sk","level":3,"time":"2024-04-08T10:40:33-05:00","remoteAddr":"","user":"--","app":"PHP","method":"","url":"--","message":"imagecreatefromstring(): Data is not in a recognized format at /var/www/nextcloud/lib/private/Blurhash/Listener/GenerateBlurhashMetadata.php#117","userAgent":"--","version":"29.0.0.16","data":{"app":"PHP"},"id":"661414a9ea7e7"}
{"reqId":"Y2cSu0jCTBYfp8BNu8sk","level":3,"time":"2024-04-08T10:40:34-05:00","remoteAddr":"","user":"--","app":"PHP","method":"","url":"--","message":"imagecreatefromstring(): Couldn't create GD Image Stream out of Data at /var/www/nextcloud/lib/private/Blurhash/Listener/GenerateBlurhashMetadata.php#117","userAgent":"--","version":"29.0.0.16","data":{"app":"PHP"},"id":"661414a9ea7d6"}

{"reqId":"Y2cSu0jCTBYfp8BNu8sk","level":3,"time":"2024-04-08T10:40:34-05:00","remoteAddr":"","user":"--","app":"PHP","method":"","url":"--","message":"imagecreatefromstring(): Passed data is not in \"WBMP\" format at /var/www/nextcloud/lib/private/Blurhash/Listener/GenerateBlurhashMetadata.php#117","userAgent":"--","version":"29.0.0.16","data":{"app":"PHP"},"id":"661414a9ea7df"}

{"reqId":"Y2cSu0jCTBYfp8BNu8sk","level":3,"time":"2024-04-08T10:40:34-05:00","remoteAddr":"","user":"--","app":"PHP","method":"","url":"--","message":"imagecreatefromstring(): one parameter to a memory allocation multiplication is negative or zero, failing operation gracefully\n at /var/www/nextcloud/lib/private/Blurhash/Listener/GenerateBlurhashMetadata.php#117","userAgent":"--","version":"29.0.0.16","data":{"app":"PHP"},"id":"661414a9ea7e3"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests