PDF attachments corrupt after updating

Get help from other users here.

Moderators: Developer, Contributor

Post Reply
feesh
Posts: 14
Joined: 16 Feb 2015, 16:25

PDF attachments corrupt after updating

Post by feesh »

Hi

I recently updated from version 1.2.1 to 1.2.18 using mysql and everything seems to be ok except for PDF attachments that were previously uploaded (saved to disk). When I try and download and open one I get the message "There was an error opening this document. The file is damaged and could not be repaired". Other file types appear to be ok. New uploads also appear to be OK.

When I look at the database things seem OK. The path looks correct. The only difference I see between new and old uploads is the new ones have [BLOB - 2B] in the content field and can be clicked to download a bin file (altho I am not sure what to do with it) while the old ones say [BLOB - 0B] and are not clickable.

I've tried searching around and the only issues I can find about this revolve around problems with postgre DBs but I am using mysql.
feesh
Posts: 14
Joined: 16 Feb 2015, 16:25

Re: PDF attachments corrupt after updating

Post by feesh »

Small update: Upon further investigation it doesn't appear to be all PDFs. For some reason some of them open fine but others won't. At first it seemed to be certain users who had the problem but then I found a ticket with 2 PDFs uploaded by the same person and one would error while the other would not. I've tried to find some differences between ones that work and ones that don't but I can't find anything obvious.

Any suggestions?
atrol
Site Admin
Posts: 8366
Joined: 26 Mar 2008, 21:37
Location: Germany

Re: PDF attachments corrupt after updating

Post by atrol »

Maybe file size matters.
Please use Search before posting and read the Manual
feesh
Posts: 14
Joined: 16 Feb 2015, 16:25

Re: PDF attachments corrupt after updating

Post by feesh »

I had thought about the file size but it doesn't seem to be the case. I've hard both large and small files work and not work. It seems like 80-90% of the files won't work but I can't quite figure out why. I'm in the process of restoring my old version on the side to validate there was no problem there and try and determine what the differences are.

Can anyone pinpoint me to the php file and function that handles the calls for attachments?
atrol
Site Admin
Posts: 8366
Joined: 26 Mar 2008, 21:37
Location: Germany

Re: PDF attachments corrupt after updating

Post by atrol »

A good point to start are the functions print_bug_attachments_list in file core/print_api.php and file_get_visible_attachments in file core/file_api.php
Please use Search before posting and read the Manual
feesh
Posts: 14
Joined: 16 Feb 2015, 16:25

Re: PDF attachments corrupt after updating

Post by feesh »

Ok so I tried to recreate my original version 1.2.1 using the original set of php files and my database backup and I still have the same issue. The only thing I can think of is that by downloading the attachments directory locally and uploading it to back to the server somehow messed up the files. I'm trying to read through the code to see what happens to the files (I am not expert at this) because it saves the file as a hash and that just adds to my confusion. Some of the earlier uploads in the systems actually have the file name instead of a hash (example: myfile.pdf) but I think that is because we originally saved files in the DB and moved them to disk but all the new file use a hash name. Incidentally, it seems the attachments with a proper name (like myfile.pdf) open.

Looking at the code I get to this line:

$v_content = file_get_contents( $t_attachment['diskfile'] );

which I am still trying to figure out what that does exactly.

The good news is I tried repairing two of the PDFs I downloaded from mantis using an online trial repair tool and it seemed to work so its not as if the files are corrupt beyond repair but maybe just some extra characters thrown in that acrobat doesn't know how to handle?

Is there any way to scan and repair the hash files?
feesh
Posts: 14
Joined: 16 Feb 2015, 16:25

Re: PDF attachments corrupt after updating

Post by feesh »

Trying to find more info about this I came accross this post which you also updated:

viewtopic.php?f=2&t=12314&start=0

There was no resolution to it but the last post was you asking him if he put FTP in binary mode. I also did a similar thing by downloading and uploading the content. Could this have had an impact? I am not really familiar with what you meant by binary mode either.
feesh
Posts: 14
Joined: 16 Feb 2015, 16:25

Re: PDF attachments corrupt after updating

Post by feesh »

Another update:

I was able to reproduce the issue using an an old install on a staging site. Here were my steps:

1 - Download the attachments folder to my C drive
2 - Rename the attachments folder on the server to attachments2
3 - Upload the attachments folder from my C drive back to the server
4 - A PDF that use to work (now stored in attachments2) doesn't work when I open the copy in folder attachments

Like I said, doesn't happen to all PDFs but most of them. I tried uploading one of the problem PDFs in case it helps anyone get to the bottom of this but it blocks me from uploading a PDF. I am not certain yet why some work and some won't but I have confirmed this PDF was created from Word using the Save As PDF option.

In case it helps my site is hosted on a rackspace cloud site and my FTP client is filezilla
feesh
Posts: 14
Joined: 16 Feb 2015, 16:25

Re: PDF attachments corrupt after updating

Post by feesh »

Ok so I was able to fix my problem. Luckily enough I had forgot I had archived a copy within FTP prior to updating. I was able to merge my archive attachments with the current attachment folder (to account for any new uploads) and everything seems to work. If I hadn't done that I am still not certain if there would have been a way to modify the corrupt files to get them to work again.

So the recap the issue had nothing to do with upgrading mantis but because I downloaded and reuploaded the files using FTP in ascii mode and not binary mode.

Perhaps it is already documented and I cant find it (although you would think it would've come up in my hundreds of good searches trying while trying to diagnose this problem) but shouldn't information like this be added to some kind of documentation?
atrol
Site Admin
Posts: 8366
Joined: 26 Mar 2008, 21:37
Location: Germany

Re: PDF attachments corrupt after updating

Post by atrol »

Great to see you fixed it.
Thanks for coming back and telling the solution.
feesh wrote:but shouldn't information like this be added to some kind of documentation?
You will find some kind of information in documentation of Filezilla and FTP in general, e.g. https://wiki.filezilla-project.org/Data_Type

There are a lot of ways and tools with lot of options to copy files from A to B.
The MantisBT documentation is hardly the right place to document 3rd party tools that might be used by MantisBT users.
Please use Search before posting and read the Manual
feesh
Posts: 14
Joined: 16 Feb 2015, 16:25

Re: PDF attachments corrupt after updating

Post by feesh »

atrol wrote:Great to see you fixed it.

There are a lot of ways and tools with lot of options to copy files from A to B.
The MantisBT documentation is hardly the right place to document 3rd party tools that might be used by MantisBT users.
What I mean is it would be good idea to document that FTP mode must be set to binary when transferring attachments stored on disk.

Perhaps I am just not as experienced as the average mantis admin but I have never worked with hash files and never figured moving them around via FTP would cause an issue since it doesn't seem to be a problem for all other files. Given that mantis chose to use hash files I thought it would be a nice tip for admins in the documentation. I figured FTP would be a pretty common method used when setting up a server for mantis but perhaps I am in the minority.

Anyway it was just a suggestion to hope others didn't fall into the same problem. Hopefully this forum post will help someone in the future.
vinay
Posts: 3
Joined: 17 May 2018, 10:14

Re: PDF attachments corrupt after updating

Post by vinay »

Hi Guys,

Thanks!!.
You saved my time. The same issue I faced after I upgraded to 2.14 and uploaded using filezilla in "Auto" mode.
By looking at your solution, I changed transfer mode to "Binay" and uploaded.
Now I could download images, pdf which earlier was giving error.

Thanks Again,
Vinay
Post Reply