boonebgorges / buddypress-docs

GNU General Public License v3.0
106 stars 44 forks source link

The .zip .png .jpg and .gif and xlsx files downloaded, in frontend are all corrupt and unreadable. #613

Open Feature676 opened 6 years ago

Feature676 commented 6 years ago

While PDF, docx, andhave noc problem .zip .png .jpg and .gif file downloaded, in frontend are all corrupt and unreadable.

Buddypress Version 2.9.2 Buddypress Docs Version 2.0. WP 4.8.3 the server runs under php 7.1

The files are available in mediathek and not corrupt. We think some white space is added (line /or two) bbuteven when we delete this the files stay corrupt Can you give us a hint wher ewe can find this

boonebgorges commented 6 years ago

Hi @Feature676 - Thanks for the ticket.

.zip, .png, .jpg, and .gif files are all working on my local installation, so it's not strictly a problem with Docs itself (at least not in the default configuration).

I have definitely seen the issue before that certain files fail to download correctly because of whitespace at the beginning. This can happen because some other script on the system is outputting a bit of whitespace just before the file is served. Docs does try to clear the output buffer several times before serving the file - see https://github.com/boonebgorges/buddypress-docs/blob/master/includes/attachments.php#L82 - but this could be failing for some reason. One way to test would be to drop some sort of die statement just before Docs calls readfile(), and see whether there's any whitespace in the output buffer. If so, start moving your die statements earlier in the script execution to see where it's being output.

Feature676 commented 6 years ago

Hi, I haven't took a deeper look in your code yet. Are all images and file treated the same way by the function you mentioned ("catch_attachment_request()") and the ob_clean is failing? If so the whitespaces come from everywhere and I would have to debug this step by step on my own. As you mentioned the ob_clean could fail (PHP manual: Note that ob_clean() and ob_end_clean() do not clean header sent with header()).

dcavins commented 6 years ago

An easy way to see if another plugin is part of the issue is deactivating all of the plugins leaving only BP Docs and BP active, switching to the twentythirteen theme, and seeing if the problem persists.

Feature676 commented 6 years ago

we are live ... i can do that only in a local copy. do have a hint how we can clean this or what function has to be variied. the suggestion above could be a solution for other (themes) too?

dcavins commented 6 years ago

I'd bet a dollar that there's a file in a plugin or theme somewhere that has a single white space before the opening <?php. It's such an easy mistake to make, hard to see, and causes exactly the trouble you're describing. Deactivating plugins is the easiest way to find which plugin has the problem, then it's much easier to find the particular file. I'd recommend you create a dev or local environment to do the testing, and also to use as a staging environment.

Another symptom of that problem is "headers already sent" errors in your WP debug.log.

boonebgorges commented 6 years ago

All images and files are treated the same way, yes. It's odd that you're only seeing broken downloads for some file types, but this suggests to me that some other plugin is detecting requests based on certain file extensions, and is mistakenly inserting the whitespace based on that. Think about things like file privacy plugins or other things that affect downloads, and it may help to narrow things down.

dcavins commented 6 years ago

@Feature676 Were you able to resolve this issue? Please let us know how it turned out.