image module breaks anonymous access to uploaded files

tmus - October 27, 2007 - 05:10
Project:Image
Version:5.x-1.x-dev
Component:image.module
Category:bug report
Priority:critical
Assigned:Unassigned
Status:closed
Description

After updating the image module to version 5.x-1.6, I can no longer view non-image files uploaded to nodes via the upload module.
To view attached .pdf files for example, I need to add the "view original images" right to anonymous users, or I'll get an access denied page.

#1

jandd - October 29, 2007 - 17:14

I have the same problem on several PostgreSQL based sites. There's a warning message:

warning: in_array() [function.in-array]: Wrong datatype for second argument in /var/www/drupal-5.3/sites/all/modules/image/image.module on line 395.

The line is in function image_file_download($filename):

if (user_access('view original images') || in_array($filepath, $images))

$images doesn't seem to be an array.

#2

jandd - October 29, 2007 - 17:27

The problem was introduced in the latest patch for http://drupal.org/node/170659

#3

jandd - October 29, 2007 - 18:45
Status:active» patch (code needs review)

The attached patch fixes the problem. I don't know if $node->images is set at all in the function maybe someone with more knowledge of the image module should look at the function again.

AttachmentSize
image-5.x-1.6-patch-for-187054.patch807 bytes

#4

drewish - October 29, 2007 - 20:27

oh, maybe we should be checking node type...

#5

radj - November 15, 2007 - 13:05

Is there no final fix for this issue? Anonymous users still cannot view the thumbnail and preview. :(

#6

drewish - November 15, 2007 - 17:15

radj, rather thank complaining about a final fix please review the posted patch.

#7

starbow - December 3, 2007 - 23:42

I used the code in this patch and it fixed the problem for me.

#8

nterbogt - December 5, 2007 - 05:31

+1 for me too. The patch above works as expected and quick visual review didn't raise any issues.

#9

Roderik - December 10, 2007 - 16:47
Version:5.x-1.6» 5.x-1.x-dev

+1 again. Patch still applies cleanly to 1.x-dev, and works.

@drewish - #4: does checking node type work? I got the error while trying to download a non-image attachment, for a node whose type does support uploading images, but which has no images attached.

(I don't know enough Drupal/PHP 'coding standard' to set the patch to 'ready to be committed'... I don't know if $node->images should return an empty array in that case?)

#10

drewish - December 12, 2007 - 02:23

give this a try...

AttachmentSize
image_187054.patch1.22 KB

#11

drewish - December 12, 2007 - 02:25

whoops, ignore that last one... wrong variable name.

AttachmentSize
image_187054.patch1.23 KB

#12

Roderik - December 13, 2007 - 16:37

Patch works - and code reads like it's a better solution, yes.

#13

drewish - December 18, 2007 - 22:57
Status:patch (code needs review)» fixed

great, committed to HEAD.

#14

Anonymous - January 1, 2008 - 23:02
Status:fixed» closed

Automatically closed -- issue fixed for two weeks with no activity.

#15

Roderik - January 3, 2008 - 13:32
Status:closed» patch (code needs review)

*weeps*

The patch you rolled does not actually solve the problem - unlike jandd's patch which does.
And apparently I didn't test correctly. Sorry :-/

That is: if the node has no image attached, '-1' is still returned. No good.

This contains a patch to the latest (19 dec) 1.x-dev.
I'm still a PHP / Drupal Coding nitwit, so please check the first line I added ('if ($node) {') for sanity. Thanks.

AttachmentSize
image_187054_2.patch1.67 KB

#16

drewish - January 6, 2008 - 22:03
Status:patch (code needs review)» fixed

Looks good to me. Committed to DRUPAL-5 and DRUPAL-5--2.

#17

Anonymous (not verified) - January 20, 2008 - 22:11
Status:fixed» closed

Automatically closed -- issue fixed for two weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.