View Issue Details

IDProjectCategoryView StatusLast Update
0017097mantisbtdb postgresqlpublic2014-10-16 07:53
Reporterpiffio Assigned Todregad  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionunable to reproduce 
Product Version1.2.17 
Summary0017097: Images get corrupted when attaching to a bug
Description

Running MantisBT 1.2.17 on CentOS 6.5 stock, using PostgreSQL 9.3.3 as backend.

This is an import of an older installation, previously running on CentOS 6.3 / PostgreSQL 9.2

All the attachments from the old import are working properly.

Any new file (images) that we're trying to attach to a bug report gets corrupted.

Steps To Reproduce

Attach an image (jpg,png) to a bug report.

Download the attachment from the bug page.

The attachment is corrupted

Additional Information

The bug appears regardless of the backend used for attachments.
I've tried both DISK and DATABASE, with the exact same result.

TagsNo tags attached.
Attached Files
2014-03-09 11.02.51.jpg (1,826,170 bytes)
post-upload.jpg (1,826,170 bytes)

Relationships

related to 0017778 assigneddregad Attachments get corrupted when attaching to a bug 

Activities

piffio

piffio

2014-03-17 12:48

reporter   ~0039688

Attached 2 files: the original one, and the same attachment downloaded from my local installation.

piffio

piffio

2014-03-17 12:51

reporter   ~0039689

When opening with ImageMagik the attachment, I get the following error:

display: Corrupt JPEG data: 25 extraneous bytes before marker 0xd9 post-upload.jpg' @ warning/jpeg.c/JPEGWarningHandler/349. display: JPEG datastream contains no imagepost-upload.jpg' @ error/jpeg.c/JPEGErrorHandler/319.

dregad

dregad

2014-03-17 13:33

developer   ~0039690

Last edited: 2014-03-17 13:34

If I understand correctly, you can successfully attach and retrieve attachments with the old system, whereas they get corrupted on the new.

Can you confirm that the old and new systems running the same version of Mantis ? I'm trying to assert whether this is caused by the version of Postgres or by Mantis itself. If not, what is the version on the old system ? Can you please try to upgrade Mantis on the old system and see if the issue can be reproduced ?

PS: would have been nice to produce smaller attachments to reproduce the problem ;)

piffio

piffio

2014-03-17 14:35

reporter   ~0039691

Hi,

Sorry for the size of the attachment :S

Just a quick clarification: after a test, I can confirm that file attachment works fine when using the DISK backend, meaning that this should be an issue caused by the postgres version we're using.

The old system is Mantis 1.2.12, and I'll try to upgrade it later on, to confirm or not that the bug seems related to PostgreSQL 9.3.X

piffio

piffio

2014-03-17 14:45

reporter   ~0039692

Last edited: 2014-03-17 15:57

Some additional details.

I was literally reading a diff between the same bytea stored in PostgreSQL 9.2.6 and in PostgreSQL 9.3.3 in the 2 different installations.
It turns out that in PostgreSQL 9.3.3 every occurrence of the character ' (quote) appears doubled in the bytea field.

E.g.

In PG 9.2.6
...\257'...

In PG 9.3.3

...\257''...

It looks like something is going wrong with the magic quote handling

piffio

piffio

2014-03-17 16:22

reporter   ~0039693

OK, using the following workaround fixes the issue.

Found it while reading around, especially here:

http://mx1.php.net/manual/en/function.pg-escape-bytea.php

What is unclear is the reason why this issue is showing up with Postgres 9.3 and not with the previous version.

diff --git a/drivers/adodb-postgres64.inc.php b/drivers/adodb-postgres64.inc.php
index 860cf8e..69d54f3 100644
--- a/drivers/adodb-postgres64.inc.php
+++ b/drivers/adodb-postgres64.inc.php
@@ -430,7 +430,7 @@ select viewname,'V' from pg_views where viewname like $mask";
*/
function BlobEncode($blob)
{

  • if (ADODB_PHPVER >= 0x5200) return pg_escape_bytea($this->_connectionID, $blob);
  • if (ADODB_PHPVER >= 0x5200) return str_replace(array("''"), array("'"), pg_escape_bytea($this->_connectionID, $blob));
    if (ADODB_PHPVER >= 0x4200) return pg_escape_bytea($blob);

            /*92=backslash, 0=null, 39=single-quote*/
dregad

dregad

2014-03-18 11:53

developer   ~0039697

Last edited: 2014-03-18 11:54

Thanks for the updates.

I tried without success to reproduce the problem locally using your file - by the way, nice pic ;)

On my dev box (Ubuntu 13.10), with both pgsql 9.1 and 9.3, the file was uploaded successfully and can be downloaded and viewed without issues. I also quickly setup a CentOS 6.5 VM, and again, everything worked fine out of the box.

For the record, output of pg_escape_bytea is as follows, and does not contain any quotes at all


$ php -a
php > pg_connect('dbname=bugtracker user=xxx password=yyy');
php > var_dump( pg_escape_bytea( file_get_contents( '/tmp/2014-03-09 11.02.51.jpg' ) ) );
string(3652342) "\xffd8ffe1310645786966000049492a00080000000c000001040001000000c00c00000101040001000000900900000f0102
00080000009e0000001001020009000000a60000001201030001000000010000001a01050001000000d20000001b010500010
00000da000000280103000100000002000000310102000d000000b00000003201020014000000be0000001302030001000000
010000006987040001000000e20000003e13000053414d53554e470047542d4e3731303000004e37313030554255454d4b340
000323031343a30333a30392031313a30323a353100480000000100000048000000010000001b009a820500010000002c0200
009d8205"...

EDIT: breaking long lines

dregad

dregad

2014-03-25 04:56

developer   ~0039732

piffio,

You did not provide any feedback; I am therefore resolving this issue as "no change required".

Feel free to reopen the issue at a later time and provide the requested information.

grangeway

grangeway

2014-05-16 15:02

reporter   ~0040505

MantisBT currently supports Mysql and has support for other database engines.

The support for other databases is known to be problematic.

Having implemented the current database layer into Mantis 10 years ago, I'm currently working on replacing the current layer.

If you are interested in using Mantis with non-mysql databases - for example, Oracle, PGSQL or MSSQL, and would be willing to help out testing the new database layer, please drop me an email at paul@mantisforge.org

In the meantime, I'd advise running Mantis with Mysql Only to avoid issues.

Thanks
Paul