With a clean D7 install (using standard install profile), I can upload certain .jpg images and drupal will throw the following error:

PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column 'field_image_width' at row 1: INSERT INTO {field_data_field_image} (entity_type, entity_id, revision_id, bundle, delta, language, field_image_fid, field_image_alt, field_image_title, field_image_width, field_image_height) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10); Array ( [:db_insert_placeholder_0] => node [:db_insert_placeholder_1] => 2 [:db_insert_placeholder_2] => 2 [:db_insert_placeholder_3] => article [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => und [:db_insert_placeholder_6] => 2 [:db_insert_placeholder_7] => [:db_insert_placeholder_8] => [:db_insert_placeholder_9] => [:db_insert_placeholder_10] => ) in field_sql_storage_field_storage_write() (line 448 of /my_directory/modules/field/modules/field_sql_storage/field_sql_storage.module).

Steps to reproduce the error:
1. Download the file "Problem.jpg" below (this is critical because only certain images generate this error)
2. Log in to your fresh install, click the "Add Content" link, and create a new Article
3. Enter a title and then browse for the image you just downloaded
4. Save the node (notice you don't see the image when you view the node)
5. Click the node's Edit tab (notice you see the file name/icon but again no image thumbnail)
6. Save the node and you'll see the error

Additionally in the watchdog I see this error:

Unable to generate the derived image located at public://styles/thumbnail/public/field/image/Problem.jpg.

I installed Devel and the uploaded "Problem.jpg" image has NULL width and height values whereas other images show these values correctly and work just fine (for example "NoProblem.jpg" which I've uploaded for reference). All images were output by Adobe Photoshop and I've had no problems with them in other image manipulation environments. I think there is something wrong with Drupal because it appears to be unable to determine the height and width of some images.

I am willing and able to provide more examples of images that provoke this error.

Comments

pingers’s picture

Version: 7.12 » 8.x-dev
Status: Active » Needs review
StatusFileSize
new904 bytes

The problem is null values being converted to empty strings. This is happening when you click the upload button, then hitting save. Clicking save directly does not trigger the bug.
So the problem is that when the form is submitted, the hidden elements have no values

Problem.jpg

<input type="hidden" name="field_page_image[und][0][width]">
<input type="hidden" name="field_page_image[und][0][height]">

NoProblem.jpg

<input type="hidden" value="129" name="field_page_image[und][0][width]">
<input type="hidden" value="300" name="field_page_image[und][0][height]">

This means that when drupal_build_form() collects post variables, we end up with empty strings.

$form_state['input'] = $form_state['method'] == 'get' ? $_GET : $_POST;

Of course, when we just save without using the widget to upload, this isn't an issue and NULL's are properly preserved.

I see in image_field_widget_process(), we initialize these to NULL, so I think we should just do that same for empty strings in the case that image size detection fails.

Please find the attached patch.

mlncn’s picture

Great fix, Pingers! This patch also fixes Drupal 7's oversensitivity to malformed images, applies with an offset using patch -p2 < drupal-image_get_info_failure-1546024-1.patch

k.skarlatos’s picture

I have the same bug, and patch #1 fixes it (i just needed to use the method in #2 to apply it to D7). Can this patch be included in a future update?

andymartha’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new97.31 KB

With patch drupal-image_get_info_failure-1546024-1.patch, everything uploads fine!

Drupal 8.x-dev without the patch:
I've tried this 4 times with problem.jpg on different content types in Drupal 8.x-dev, but all I get are error message:
"Exception: Serialization of 'Closure' is not allowed in serialize() (line 153 of/Applications/MAMP/htdocs/drupal8/core/modules/dblog/dblog.module).
The website has encountered an error. Please try again later."

http://drupal.org/node/1872690
http://drupal.org/node/1934738

Other images work fine.

tim.plunkett’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

This should have automated tests.

jcisio’s picture

jcisio’s picture

Status: Active » Closed (duplicate)

I mistakenly did not change the status.

j0rd2’s picture

Same problem on D7 . Needs fix.