If an user belongs into more than one role validation of uploading file doesn't work properly.
I think there is a problematic piece of code starting at line 307 in upload.module

if (count($error)) {
 unset($node->files[$fid], $_SESSION['file_previews'][$fid]);
  file_delete($file->filepath);
}

as for instance there could be a validation issue for one role but it could pass for a different role. But count($error) is set and hence uploaded file is deleted
I think a solution is to iterate over the $error array instead and check all items whether there are equal to number of user's roles, something like that:

foreach ($error as $name => $value) {
    if ($value == count($user->roles)) {
        unset($node->files[$fid], $_SESSION['file_previews'][$fid]);
        file_delete($file->filepath);
       break;
    }
}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dopry’s picture

FileSize
1.11 KB

Right you are sir, good catch.

Here's the patch.

dopry’s picture

Assigned: Unassigned » dopry
Status: Active » Needs review
FileSize
1.11 KB

Right you are sir, good catch.

Here's the patch.

nedjo’s picture

Looks good in theory (didn't test).

$name => in the patch is superfluous, since not used.

dopry’s picture

FileSize
1.1 KB

always has to be something small...
well here you go I dropped the $name =>...

I'd still prefer to see it testedthan just looked at.

dopry’s picture

FileSize
1.1 KB

What I meant was pretty please test this one...

  wget http://drupal.org/files/issues/54913_2.patch
  patch -p0 < 54913_2.patch
dopry’s picture

FileSize
2.01 KB

And if you're really adventurous try out this one which drops a loop and all those calls to count..
in favor of a boolean, and count variable.

dopry’s picture

FileSize
2.01 KB

Proof that I'm sleep deprived...
I initialized $valid = FALSE, instead of TRUE in that last patch.

rkerr’s picture

Well, the patch applies fine. But my upload aren't working with or without the patch, so unfortunately I can't test what sort of difference it makes. :(

Looks about right to me, though.

rkerr’s picture

Just tried again and it works!

(Don't seem to be able to upload anything over 2 megs on my test site, but that's another issue).

So, yeah ... good patch :)

killes@www.drop.org’s picture

Version: 4.7.0-beta6 » x.y.z
Status: Needs review » Needs work

The patch removes the special handlinbgof uid 1. While i agree that one could argue for this to be removed, I'd not want to change it this late in the release cycle.

bonobo’s picture

This patch worked for me -- I set up three roles, three users, and uploaded a series of files. The least restrictive permission worked --

Can't speak to the UID1 issue Killes raised, however.

Cheers,

Bill

rkerr’s picture

Status: Needs work » Needs review
FileSize
2.06 KB

Attaching updated patch, re-adding uid 1 special case handling.

dopry’s picture

The uid=1 check I added was redundant cruft...
this code block is already wrapped in a uid 1 check.

dopry’s picture

Status: Needs review » Reviewed & tested by the community

Just fyi... the primary uid =1 check is around line 259 of upload.module...
so I'm going to maintain my +1 for http://drupal.org/files/issues/54913_4.patch
in comment #7.

I'm setting it RTBC.

killes@www.drop.org’s picture

Status: Reviewed & tested by the community » Fixed

applied

Anonymous’s picture

Status: Fixed » Closed (fixed)