When the Private upload module makes files private and moves them from /files to /files/private it replaces any existing files with the same filenames thus potentially deleting someone else's files and giving them access to your files instead. This is not ideal and it is also contradictory to the default behavior of the Upload module - which renames new files with duplicate filenames - causing extra confusion for the developer as to what is going on. It would be good if there was a setting where admin could choose if private files with duplicate filenames should replace the original files or be renamed.

Petter

CommentFileSizeAuthor
#4 private_upload.patch5.36 KBAnonymous (not verified)
#1 private_upload.module.patch3.86 KBacrollet
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

acrollet’s picture

Version: 5.x-1.0-beta6 » 5.x-1.0-rc2
Category: feature » bug
Priority: Normal » Critical
Status: Active » Needs review
FileSize
3.86 KB

I'm attaching a patch to fix this issue - it uses the default drupal behavior of appending an incremented digit to duplicate filenames. It would be easy to make a preference for this behavior, but my contention is that this patch produces the the correct behavior, as it avoids database inconsistency. (producing messages like this: There are '29' files in the private folder, and the DB thinks there are '116' private files.)

acrollet’s picture

I'm attaching a patch to fix this issue - it uses the default drupal behavior of appending an incremented digit to duplicate filenames. It would be easy to make a preference for this behavior, but my contention is that this patch produces the the correct behavior, as it avoids database inconsistency. (producing messages like this: There are '29' files in the private folder, and the DB thinks there are '116' private files.)

Jody Lynn’s picture

See also #371492: Upload a file with the same name doesn't remove the old upload. Same bug exists in D6. It can cause loss of files, incorrect file served, and corrupt (truncated by wrong filesize) files served.

Anonymous’s picture

Version: 5.x-1.0-rc2 » 6.x-1.x-dev
Assigned: Unassigned »
FileSize
5.36 KB

attached is a patch for the 6 branch.

Jody Lynn’s picture

Status: Needs review » Reviewed & tested by the community

Reviewed and tested Justin's patch.

As well as patching the module you may need to do some manual cleanup of your files if they were affected by this. A few of the things I did to generate lists of files needing cleanup:

The bug could result in having missing files or files that were overwritten with a different file. This will print out files that do not match their filesize in the database, either because they are missing or because they were overwritten with a different file:

$result = db_query("SELECT * FROM {files}");
while ($file = db_fetch_object($result)) {
  if( filesize(realpath($file->filepath)) != $file->filesize) {
    print $file->filepath .' '. $file->filesize .' '. filesize(realpath($file->filepath)) .' ';
  }
}

Sql query to list filepaths that are in the files and upload table more than once.

SELECT f.filename, u.nid, u2.nid FROM files f INNER JOIN files f2 ON f.filepath = f2.filepath INNER JOIN upload u ON u.fid = f.fid INNER JOIN upload u2 ON u2.fid = f2.fid WHERE f.fid <> f2.fid AND u.fid <> u2.fid AND f.timestamp > f2.timestamp ORDER BY f.timestamp ASC;
Jody Lynn’s picture

Version: 6.x-1.x-dev » 5.x-1.x-dev
Assigned: » Unassigned
Status: Reviewed & tested by the community » Patch (to be ported)

Fixed in the D6 dev branch. Still an issue for D5. The patch in comment 1 needs review and testing or the patch in #4 needs porting.