Problems with file revisions, downloading as corrupted.

Project:ProjectPier
Version:0.8.0.3
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:new
Description

I was referenced here by Ryan who said I should file a bug report regarding corrupted downloads of revisions from projectpier's interface.

Let me begin by saying I have temporarily solved this problem locally by simply commenting out the Content-Length header which is added in the content_downloads function found in environment/functions/files.php.

I have discovered a bit more on the issue since I first e-mailed about it, but here is my original e-mail:

We use ProjectPier fairly extensively as of 1 - 2 months ago, and are using it very heavily for a number of projects. We started noticing some files were corrupted and I did some investigating.

Here's what I found:

matts@MATTSLIN:~$ ls -tla *download*
-rw-r--r-- 1 matts matts 1603827 2009-03-10 11:40 3-download-via-projectdev.ai
-rw-r--r-- 1 matts matts 1603827 2009-03-10 10:03 4-download-via-uploads.ai
-rw-r--r-- 1 matts matts 1607227 2009-03-02 17:24 3-download-via-uploads.ai

Note that the size of revision 3 downloaded via the projectpier interface is the same size as revision 4 downloaded via the upload directory (unique file ID was found in the database). The content, however for the first 1603827 bytes of this file matches the proper content for revision 3 as downloaded directly from the upload directory, but because the filesize is matching revision 4, it gets cut off at the bottom, since the file was smaller.

I was able to totally test this theory by uploading bunk revisions and checking the filesizes as downloaded. Sure enough, the filesize of the separate revision, despite having the proper content, matched the filesize of the latest revision and would cut off the last X bytes of the file in the event it was X bytes smaller.

What seems to be occurring is that GetFileSize is always reporting the filesize of the latest revision:

From application/models/project_files/ProjectFile.class.php

function getFileSize() {
$revision = $this->getLastRevision();
return $revision instanceof ProjectFileRevision ? $revision->getFileSize() : null;
} // getFileSize

This is my first time looking at the source for this thing, so if I'm sadly mistaken at what this is doing, then I apologize. What seems strange is that there are other functions, such as getFileContent() within the same file that uses the same methodology of setting $revision = $this->getLastRevision(); -- However, I did note that in application/models/project_file_revisions/ProjectFileREvision.class.php there are alternative functions for methods such as getFileContent, but there does not appear to be one for getFileSize -- if this has anything to do with anything.

Regardless, the problem persists that it always returns the latest revisions filesize, and thus, removing the Content-Length header has left it up to the browser to determine the end of the contents (not something I'm too worried about on an intranet install).

#1

We are using 0.8.5.0 and have the same problem. The defect is in download_revision() in /projectpier/applications/contoller/FilesController.class.php. The fix is to change the 4th argument of download_contents() on line 357.

I haven't done heavy programming in a while and I'm brand new here, so forgive me this is already resolved or I'm putting this in the wrong place or my syntax below doesn't make sense.

>> //New
>> download_contents($revision->getFileContent(), $revision->getTypeString(), $file->getFilename(), $revision->getFileSize());

<< //Old
<< download_contents($revision->getFileContent(), $revision->getTypeString(), $file->getFilename(), $file->getFileSize());