Error downloading attached files with private method - patch proposal

francoud - August 28, 2006 - 15:07

Recently I had some problem with Drupal 4.7 (4.7.3... but maybe 4.7.2 also) downloading files attached to a page, when using the private download method. Shortly: I.E. downloaded files as.. test, showing http headers (content-type, content-disposition, etc.) followed by file content; Firefox asked to save the file - but the result was the same (a sort of text file including http headers in top of it!).

I had this problem with the same provider (aruba.it) but in two different environments (Linux/apache and Windows hosting). I know other people had similar problem:

http://drupal.org/node/71434
http://drupal.org/node/65593
...

So I started looking around the code, and I found that the "updload_file_download" procedure, in the upload.module, seem returning an empty line before the 3 legal headers. I (still) don't really know why. Then I looked into includes/file.inc and I found that the "file_transfer" function, where is code to remove lines not followed by space or tab. So I added one single line of code, to also avoid outputting of empty lines - I suppose that this empty line cause injection of http headers!

So I modified the file_transter function in file.inc, adding if ($header != '') before outputting headers:

-------------
foreach ($headers as $header) {
// To prevent HTTP header injection, we delete new lines that are
// not followed by a space or a tab.
// See http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2
$header = preg_replace('/\r?\n(?!\t| )/', '', $header);
if ($header != '') /* PATCH FB 28.8.06 */
header($header);
}
-------------

This solved my problem! I suppose that other people can have the same problem. I suggest to include the patch in the next releases... removing empty headers could be a good idea?

Thanks to all...

Errata corrige:

francoud - August 28, 2006 - 15:09

I.E. downloaded files as.. TEXT, of course :)

Thanks!

nevan - September 2, 2006 - 15:42

This also solved a problem I had with the image module during an upgrade from drupal 4.6.6 to 4.7.3. Without your patch I couldn't see any new uploaded image. I also use aruba.it as hosting provider.
Bye, Elio

Good!

francoud - September 4, 2006 - 09:48

Ottimo ;-)

Now IE open associated application but ...

derieppe - October 9, 2006 - 18:21

BUT - for example with PDF files - Acrobat Reader can't open file and say "Error during file oppening. Files not found" [This is a translation from of error message in the french version of Adobe Arobat Reader].

Some Ideas ?

Right, I am having the same problem

francoud - October 13, 2006 - 07:41

But only with Internet Explorer... firefox works well!

In this case, the issue is not in the file.inc but in the upload.module itself.

It's discussed here:

http://drupal.org/node/30525

I added this patch: http://drupal.org/files/issues/upload-ie-fix.patch and it works. Better you could try some patched version of upload.module from cvs.drupal.org (I didn't try - I just added the patch and worked ;-)

Let me know if you solved!

The attached files PDF d'ont work

capitanZ - March 19, 2007 - 16:17

I have installed the patch, but the attached files pdf does not display. In Internet Explorer work fine but in Firefox d'ont work.

You can see this here:

http://www.ieszaframagon.com/boletin-empleo-18enero07

any ideas?

Thanks

 
 

Drupal is a registered trademark of Dries Buytaert.