0

Our products are eBooks, delivered in both .epub and .mobi formats via the http://www.tipsandtricks-hq.com/ eStore Plug-in for WordPress which generates encrypted download links.

  • Problem began suddenly about 5 days ago and had previously worked fine for about three months

  • all .epub files get corrupted when customers download their purchase via the download links and Adobe Digital Editions gives an error when trying to import the ePub to the Library

  • all .mobi files get corrupted when downloaded and then loaded onto Kindle, Kindle gives similar error

  • we tried turning off the Google URL shortener, error

  • we have tested the links with IE, Chrome and Firefox, error

  • we tested without the encrypted links, by downloading the files via a direct link in the browser and they work fine, no error

What we have learned:

  • we have tested using FTP to download in both ASCII and Binary modes ... with ASCII we get the same error as with using the encrypted download links

  • files transfered with FTP are the same size after using ASCII and Binary, but running a hash check shows that the contents are different

  • we are using FileZilla to test via FTP on both PC and Mac, however the error only occurs on the PC

  • SO, we are assuming that this problem has to do with the file transfer type and PCs

  • in /home/foo/bar/wp-content/plugins/wp-cart-for-digital-products/download.php we see header("Content-Transfer-Encoding: binary"); so we assume that Binary is being forced when using the encrypted links

Could there possibly be some characters in the encrypted link string that are forcing ASCII? Here is an example of the encrypted link:

https://fu.com/bar/download.php?file=LRtro6WQMN12ip%2BEcL0TYS8sMZmSKOlkRedVCZyfACsqSllzCAjDp%2FZJyfQ2oq0ZP6vg1EMrR%2FOFC4B3wGDHl3N0u0sulcBhIfkOJ0C0UQh6

And here is a look at the http header:

Status: HTTP/1.1 200 OK
Date: Wed, 27 Feb 2013 14:55:47 GMT 
Server: Apache 
X-Powered-By: PHP/5.3.17 
Set-Cookie: PHPSESSID=7d61c9dd6ecbd321bea8cffg4a25d5e8; path=/ 
Expires: 0 
Cache-Control: public 
Pragma: public 
X-CF-Powered-By: WP 1.3.9 
Content-Description: File Transfer 
Content-Disposition: attachment; filename="Some-File-Name-Which-Was-Replaced.epub" 
Content-Transfer-Encoding: binary 
Content-Length: 5088032 
Connection: close 
Content-Type: application/epub+zip

What else could possibly be causing this? Could our server be forcing ASCII in .htaccess or apache config settings?

Thank you very much

i_a
  • 2,735
  • 1
  • 22
  • 21
  • We just tried looking at the corrupt file vs the working file with a Binary Editor and found that there is junk data at the beginning of the corrupt file. (Per this tip here: http://stackoverflow.com/questions/4465135/php-file-download-is-always-corrupt-50-of-the-time) – i_a Feb 27 '13 at 21:20
  • We converted the binary to ascii and found that the junk data at the beginning of the file is: ï°¿ Which are HTML Codes for: ¿ = inverted question mark. ° = degree sign. ï = latin small letter i with diaeresis. Now we are trying to figure out where the heck this is coming from! :) From the eStore plug-in? From the server? From Windows (because it only happens on Windows)? – i_a Feb 27 '13 at 21:21

1 Answers1

1

One of our programmers was using the wrong character encoding in his editor. We need to treat PHP files with the UTF-8(BOM off) or blank spaces or newlines can interefere somehow in the file integrity:

UTF-8 BOM signature in PHP files

Offending line of code in WordPress' functions.php: if ($bom != b"\xEF\xBB\xBF")

Our culprit HTML Character codes ï°¿, which we decoded from the HEX values: EF BB BF That was the junk data appearing in the beggining of the corrupted .epub files.

functions.php was always outputting this junk data each time it ran in WordPress.

So glad we finally got to the root of the problem, was driving us mad! Ha haa!!!

Peace & Happy Coding to You

Community
  • 1
  • 1
i_a
  • 2,735
  • 1
  • 22
  • 21