When a zip file is downloaded through the module's chr_curl_http_request() function, the file gets corrupted because at line 183 the spaces from the response received are trimmed.

// Make request.
 $result->data = trim(curl_exec($ch));

We suggest that trim should be removed. We can send you a small patch for this.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ionut.stan created an issue. See original summary.

Cyberwolf’s picture

Attaching a patch. It replaces trim() with ltrim().

gboddin’s picture

This is true for all files ending with null characters, I would even raise the priority a bit.

Eg : 000bdf0 0000 0000 0054 0000 1000 0000 0000 0000 in our case was the end of an excel file ( and obviously the 3 last bytes got trim'd ).

Lots of software might use null termination as a delimiter, so this probably affects a few people, especially when doing migrations.

Seems to me ltrim is the right choice since the end of ->data will always be then end of the body.

gboddin’s picture

Title: zip archives are corrupted when downloaded because the module trims spaces from the response received » Files are corrupted when downloaded with chr_curl_http_request because the module trims spaces and null termination from the response
xrxphawxby’s picture

+1 to getting this merged and deployed, the patch is good.

I spent a day trying to figure out why my zip files were getting inexplicably corrupted.

amoebanath’s picture

Status: Active » Reviewed & tested by the community

What a crazy issue!
Patch works nicely :)

Pol’s picture

Same goes for us.

  • 78979e8 committed on 7.x-1.x
    Issue #2816399 by ionut.stan: Files are corrupted when downloaded with...
Vincenzo’s picture

Version: 7.x-1.8 » 7.x-1.9
Assigned: Unassigned » Vincenzo
Status: Reviewed & tested by the community » Fixed

Committed.

Pol’s picture

Thanks!

Status: Fixed » Closed (fixed)

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