Unexpected Error downloading a ZIP file attachment

Submitted by mkager on 2012-10-25

I 'm getting an Unexpected Error upon downloading a ZIP file attachment.

WebIssues Server and WebClient running on the same machine. Operating System: Windows XP.
Apache/2.2.22, PHP/5.2.17, PostgreSQL 8.4 (database created with UTF-8 encoding).
Attachment Storage set to "Always" on Server Settings.
Webissues 1.0.3.
Internet Explorer 8 WebClient.

When you click on a ZIP file attachment it shows the message:

Unexpected Error
The following error(s) occured while processing the request:

PHP Warning: pg_unescape_bytea() expects exactly 1 parameter, 2 given in C:\Archivos de programa\Apache Software Foundation\Apache2.2\htdocs\system\db\pgsql\engine.inc.php on line 121 
Unhandled System_Core_Exception: Attachment file does not exist in C:\Archivos de programa\Apache Software Foundation\Apache2.2\htdocs\system\core\attachment.inc.php on line 121
Stack trace:
#0 C:\Archivos de programa\Apache Software Foundation\Apache2.2\htdocs\system\core\response.inc.php(112): System_Core_Attachment->validate()
#1 C:\Archivos de programa\Apache Software Foundation\Apache2.2\htdocs\client\issues\getattachment.php(61): System_Core_Response->setAttachment(Object(System_Core_Attachment))
#2 C:\Archivos de programa\Apache Software Foundation\Apache2.2\htdocs\system\core\application.inc.php(210): Client_Issues_GetAttachment->execute()
#3 C:\Archivos de programa\Apache Software Foundation\Apache2.2\htdocs\system\bootstrap.inc.php(124): System_Core_Application->run()
#4 C:\Archivos de programa\Apache Software Foundation\Apache2.2\htdocs\client\issues\getattachment.php(84): System_Bootstrap::run('Client_Issues_G...')
#5 {main}

Looking into code at engine.inc.php file, I've found that function call to pg_unescape_bytea has two parameters: $this->connection and $data

Removing the first parameter ($this->connection) apparently fix part of the problem:

Original code:

return new System_Core_Attachment( pg_unescape_bytea( $this->connection, $data ), $size, $fileName );

Fixed code:

return new System_Core_Attachment( pg_unescape_bytea( $data ), $size, $fileName );

Now I can download the file, but once the file has been downloaded, when I open it, is corrupted. Also, I realized that file size has decreased from 87.842 bytes to 5bytes.

By taking a look at the WebIssues DataBase Schema, I found a table named File where attachments are stored. The column named file_size of the corresponding row has the correct size (87.842 bytes), so I think may be it's something related to the download process.

It happens also using WebIssues DesktopClient.

Sorry I couldn't serve of more help, but I have a very limited knowledge on PHP (I work mostly on Java projects).

Thank In advance,
Miguel Angel