Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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).
Comment | File | Size | Author |
---|---|---|---|
#21 | 681042-21.patch | 1.51 KB | mondrake |
Comments
Comment #1
webchickComment #2
adooo CreditAttribution: adooo commentedThis was lots of code :)
Comment #3
wouters_f CreditAttribution: wouters_f commentedI altered the code to test the filesize first.
Suggestion from php.net.
Error will not show up anymore, only drupal message "The specified file emptyimage.jpg could not be uploaded" Will appear.
Please review.
Comment #5
wouters_f CreditAttribution: wouters_f commentedOops wrong patch file.
Comment #6
wouters_f CreditAttribution: wouters_f commentedComment #8
13rac1 CreditAttribution: 13rac1 commentedManually applied drupal_sensei's suggestion and fixed formatting.
Comment #9
wouters_f CreditAttribution: wouters_f commentedthank you.
Comment #10
droplet CreditAttribution: droplet commentedIsn't it enough ?
5 days to next Drupal core point release.
Comment #11
AaronBaumanwhy did you change this to 8.x?
Comment #12
Dave ReidI 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!
Comment #13
node9 CreditAttribution: node9 commented#11: notice_viewing_img-681042-8.patch queued for re-testing.
Comment #15
krishworks CreditAttribution: krishworks commentedpatch ported to 8.x
Comment #16
claudiu.cristea@krishworks, can you rework the patch based on latest code from HEAD? Thanks!
Comment #17
alansaviolobo CreditAttribution: alansaviolobo commentedI just tried uploading a 0 length image. got a very unfriendly error.
Comment #18
cilefen CreditAttribution: cilefen commentedIt looks like this code now lives in Drupal\system\Plugin\ImageToolkit\GDToolkit::parseFile()
Comment #19
cilefen CreditAttribution: cilefen commentedI 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..
Comment #20
filijonka CreditAttribution: filijonka commentedhmm 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.
Comment #21
mondrakeThe 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.
Comment #22
filijonka CreditAttribution: filijonka commentedhmm but uploading an image of size 0 wasn't possible before either, see #17
Comment #23
mondrakeRe #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?
Comment #24
filijonka CreditAttribution: filijonka commentedok 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
Comment #25
cilefen CreditAttribution: cilefen commentedI uploaded a 0-byte file.
Comment #26
filijonka CreditAttribution: filijonka commented@cilefen ok can you give us the steps for this cause I wasn't able to do that.
Comment #27
cilefen CreditAttribution: cilefen commented$ touch zero.png
Comment #28
cilefen CreditAttribution: cilefen commentedThe comment in #27 is without this patch applied.
Comment #29
filijonka CreditAttribution: filijonka commented@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.
Comment #30
filijonka CreditAttribution: filijonka commentednope can't reproduce this.
and you're on head @cilefen?
Comment #31
cilefen CreditAttribution: cilefen commentedThe 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.
Comment #32
cilefen CreditAttribution: cilefen commentedComment #40
pameeela CreditAttribution: pameeela commentedThanks 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.