This is the edgiest of edge cases possible, but figured I'd document it.

Error message
Notice: getimagesize(): Read error! in image_gd_get_info() (line 339 of /Users/webchick/Sites/core/modules/system/image.gd.inc).
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

webchick’s picture

Title: Notice when view an uploaded image of 0 bytes » Notice when viewing an uploaded image of 0 bytes
adooo’s picture

Status: Active » Needs review
FileSize
522 bytes

This was lots of code :)

wouters_f’s picture

Status: Needs work » Needs review
FileSize
603 bytes

I altered the code to test the filesize first.
Suggestion from php.net.

  if(filesize($image->source)>0){
    $data = getimagesize($image->source);
  }

Error will not show up anymore, only drupal message "The specified file emptyimage.jpg could not be uploaded" Will appear.
Please review.

Status: Needs review » Needs work

The last submitted patch, notice-viewing-image-0bytes-681042.patch, failed testing.

wouters_f’s picture

Status: Needs review » Needs work
FileSize
561 bytes

Oops wrong patch file.

wouters_f’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, notice-viewing-image-0bytes-681042-2.patch, failed testing.

13rac1’s picture

Status: Needs work » Needs review
FileSize
567 bytes

Manually applied drupal_sensei's suggestion and fixed formatting.

wouters_f’s picture

thank you.

droplet’s picture

Version: 7.x-dev » 8.x-dev
Status: Needs review » Needs work
+++ b/modules/system/image.gd.incundefined
@@ -346,7 +346,9 @@ function image_gd_create_tmp(stdClass $image, $width, $height) {
+  if (filesize($image->source) > 0) {
+    $data = getimagesize($image->source);

Isn't it enough ?

if (filesize($image->source)) {

5 days to next Drupal core point release.

AaronBauman’s picture

Version: 8.x-dev » 7.x-dev
Status: Needs work » Needs review
FileSize
563 bytes

why did you change this to 8.x?

Dave Reid’s picture

Version: 7.x-dev » 8.x-dev
Status: Needs review » Needs work
Issue tags: +Needs backport to D7

I presume like all bugs we need to fix this in 8.x first, then backport to 7.x. Aaron if you'll re-roll, I'll review this!

node9’s picture

Status: Needs work » Needs review
Issue tags: -Needs backport to D7

#11: notice_viewing_img-681042-8.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +Needs backport to D7

The last submitted patch, notice_viewing_img-681042-8.patch, failed testing.

krishworks’s picture

Status: Needs work » Needs review
FileSize
666 bytes

patch ported to 8.x

claudiu.cristea’s picture

@krishworks, can you rework the patch based on latest code from HEAD? Thanks!

alansaviolobo’s picture

Issue summary: View changes
FileSize
28.89 KB

I just tried uploading a 0 length image. got a very unfriendly error.

cilefen’s picture

Status: Needs review » Needs work

It looks like this code now lives in Drupal\system\Plugin\ImageToolkit\GDToolkit::parseFile()

cilefen’s picture

I have confirmed this error with a 0-byte "image". The watchdog error is: Unable to generate the derived image located at public://styles/thumbnail/public/field/image/zero.png..

filijonka’s picture

hmm I can not generate this error unless I go straight to the image url. if a 0 byte image is included in a content it doesn't give any error messages.

mondrake’s picture

Priority: Minor » Normal
Status: Needs work » Needs review
Issue tags: +Needs tests
FileSize
1.51 KB

The problem is not with the toolkit, the GD one correctly returns an Image object whose isValid() method returns false when trying to parse a '0 bytes' image file. Instead, there is not an explicit validator in the ImageWidget to check that the uploaded image is valid, even though such validator is available in file.module.

The patch attached will resolve in the sense that the upload attempt fails.

Needs tests.

filijonka’s picture

hmm but uploading an image of size 0 wasn't possible before either, see #17

mondrake’s picture

Re #22: fair point ... :)

General comments at this stage then:

1 - the error message in #17 is really obscure. By the way it also occurs if you try to upload a file that, despite its extension, has no image contained within (try to rename a file.txt to file.jpg and upload). The patch in #21 make at least the message more explicit and aborts the upload (instead of aborting at form submission as currently in HEAD). However the error message is displayed twice :(

2- the error described in the OP was fixed in #1522348: Notice: getimagesize read error in image_gd_get_info() line 349 (D7) and #2211227: Refactor image and imagetoolkit: isExisting, isSupported, supportedTypes, getMimeType (D8) by prefixing the getimagesize() function with the @ error suppression operator.

3 - if 0 size files cannot be uploaded first thing... why this issue's current title then? What are we trying to chase?

filijonka’s picture

ok was going to create a new issue for that errormessage.

chick wrote this: "this is the edgiest of edge cases possible, but figured I'd document it."

Simply, even if this shouldn't really be possible to happend we need to deal with it if it does..

lets hear what other people might say about this

cilefen’s picture

I uploaded a 0-byte file.

filijonka’s picture

@cilefen ok can you give us the steps for this cause I wasn't able to do that.

cilefen’s picture

  1. $ touch zero.png
  2. Create a new node of type article and upload zero.png as the image.
  3. Save the node.
  4. The errors in #17 and #19 are seen.
cilefen’s picture

The comment in #27 is without this patch applied.

filijonka’s picture

@cilefen ok thanks.

very strange though that the file is not erased after the errormessage, when I test the file is erased, I do the same steps. hmm I didn't do it on article though..let me try that.
So when the node is saved the file isn't.

filijonka’s picture

nope can't reproduce this.

and you're on head @cilefen?

cilefen’s picture

Status: Needs review » Needs work

The incorrect form validation error described in comment #17 prevents even the attachment of a zero-byte image to a field, so the original issue cannot be recreated at the moment.

cilefen’s picture

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

pameeela’s picture

Status: Postponed » Closed (duplicate)
Issue tags: +Bug Smash Initiative
Related issues: +#2345695: Users are able to upload 0-byte images

Thanks for reporting this issue and thanks to everyone who contributed to it. We rely on issue reports like this one to resolve bugs and improve Drupal core.

As part of the Bug Smash Initiative, we are triaging issues that are marked "Postponed".

I'm closing this as a duplicate because this was fixed in D8 (you cannot upload a 0 byte image) in #2377747: Incorrect node create validation error when an invalid image is attached to a field and there is #2345695: Users are able to upload 0-byte images to do the same for D7.