I received an illegal offset error from image.module at line 635.

I found that an array was being passed into image_display as the $label_parameter. The conditional at line 635 assumes that $label is not an array, so it causes the illegal offset error. e.g.

/**
 * Create an <img> tag for an image.
 */
function image_display(&$node, $label = IMAGE_PREVIEW, $attributes = array()) {

  if (empty($node->images[$label])){  // If $label is an array, I get an illegal offset error
      return;
  }

It could be argued that the bug is also in whichever module / function is passing an array into image_display, in the first place. Maybe, but none-the-less, if a function requires a parameter to be of a certain kind in order to run flawlessly, I think it should contain type checks.

I stopped the problem occuring by adding the following to the start of the image_display function:

/**
 * Create an <img> tag for an image.
 */
function image_display(&$node, $label = IMAGE_PREVIEW, $attributes = array()) {

  if (is_array($label)) {
    return;
  }

  if (empty($node->images[$label])){  // If $label is an array, I get an illegal offset error
      return;
  }

Perhaps this should be built into future versions?

CommentFileSizeAuthor
#7 view.txt1.95 KBhaggai_e
#3 slideshow.txt.bz283.82 KBhaggai_e

Comments

joachim’s picture

Status: Active » Postponed (maintainer needs more info)

Could you find which module made the bad call?

You can use print_r(debug_backtrace()) for that, though if there are lots of calls if may use up a lot of memory.
You could do:

  if (is_array($label)) {
    print_r(debug_backtrace());
  }

that would only produce debug output with the bad param.

The bad call needs to be fixed. It's not up to functions to check they've not been given bad parameters. Also, returning nothing when the caller expects an IMG tag might break the caller...

sun’s picture

Status: Postponed (maintainer needs more info) » Closed (won't fix)

Sorry, without further information this issue can only be marked as won't fix.

Feel free to re-open this issue if you want to provide further information. Thanks.

haggai_e’s picture

StatusFileSize
new83.82 KB

Hi,

I've encountered the same bug, when trying to use the slideshow view module. I'm attaching a trace as you requested.

I hope this helps finding this bug.

Haggai

joachim’s picture

Status: Closed (won't fix) » Postponed (maintainer needs more info)

Interesting....

This is the salient bit:

            [file] => /home/haggai/Sites/shacharut/public_html/sites/all/modules/image/views/image_handler_field_image_node_image.inc
            [line] => 114
            [function] => image_display
            [args] => Array
                (
                    [0] => stdClass Object
                        (
                            [nid] => 189
                            [title] => סמינר מעורבות תש"ע
                            [images] => Array
                                (
                                    [preview] => files/images/ מעורבות אורט אלון תשע (15).preview.JPG
                                    [thumbnail] => files/images/ מעורבות אורט אלון תשע (15).thumbnail.JPG
                                    [_original] => files/images/ מעורבות אורט אלון תשע (15).JPG
                                )

                            [rebuild_images] => 
                        )

                    [1] => Array
                        (
                            [0] => thumbnail
                        )
                )

The second parameter is an array containing 'thumbnail', whereas it should be just the string 'thumbnail'.

On a fresh setup, it all works fine for me.
What version of Views are you using?
If you're on 2.8, can you strip the view down as far as you can while still getting the error?

haggai_e’s picture

Hi,

I'm using views 2.8. I'm not sure how can I strip the view down? It only have two fields (image title, and the image), and a single filter (taxonomy term based). I tried limiting the results to a single image, but the trace remains very large (almost the same as the one I've sent).

Do you think this could be a result of my upgrade from drupal 5?

joachim’s picture

What about the slideshow view module you're using -- can you switch the view to List view and still get the error?

If so, can you export the view and attach it here?

haggai_e’s picture

StatusFileSize
new1.95 KB

Yes, I'm afraid I still get the error using List view. Here is the attached exported view.

joachim’s picture

Category: bug » support
Status: Postponed (maintainer needs more info) » Closed (fixed)

There's no data for the derivative size in that view!

Just go edit that field, set it to thumbnail or whatever, save.

haggai_e’s picture

Category: support » bug
Status: Closed (fixed) » Postponed (maintainer needs more info)

Thanks.

I still don't quite understand this. When I edited the field, I saw thumbnail already selected. Saving it did fix the problem though.

Haggai

haggai_e’s picture

Category: bug » support
Status: Postponed (maintainer needs more info) » Closed (fixed)

Sorry, I didn't mean to change the bug report fields.

joachim’s picture

Views is setting the radio buttons to show the default value if it has nothing there, as if this were a new view you were configuring.