Compressed and Corrupted image issue

While downloading the uploaded image in the Document/Notes module, the image was compressed and sometimes distorted.


Steps to reproduce-

1- Create a document record, fill in the required field
2- Upload JPG image
3- Save the record
4- Downalod the uploaded image

Expected results:
Upload the Image with the original size image

Actual result:

The image was compressed and sometimes distorted


Same issue with the Inbound Email attachment

Thanks

  • We upgraded an on-premise SugarCRM v6 to v12 (and then to v13) last year (I think).

    v6 stored documents in the "/upload" folder. It stored them all using the sugarid of the revsion as the filename. It stored the original file data, but without extension.

    v12.0.2 (I think, but NOT v12.0) changed this to

    (a) add sub-folders whose names are 3 hex digits (0-F) and move files where the last three characters before the first dash match those digits (e.g. a file "83929000-38a5-a125-4412-5720bca4ace6" is moved from /upload/ to /upload/000/) and

    (b) modify the file contents (basically to change the byte sequence "<?php" to a sequence of a different length when uploading a document, and then changing the sequence back when accessing the file; presumably so the files in the upload folder never have the sequence "<?php" so can never be executed as a php file)

    In v13, the upload process CORRUPTED uploaded images: I think the code was supposed to bypass changing the contents for images, but was NOT. I think this got fixed in v13.0.2.

    It sounds like you have a similar issue.

    What version of Sugar are you using? Do you have on-premise or in the cloud?

  • And the other change v12 made was that image files are always processed and the processed version is stored. NOT the original image file which is NOT KEPT. 

    So JPG images are stored MUCH smaller file sizes for photo which can be several megabytes originally.

    The difference is probably not noticable for most people, and presumably no-one has complained to Sugar that uploaded images are blurry etc?

  • Hi  ,

    Thanks for the response.

    The issue is within 12.0.4 version. The problem was due to include/upload_file.php having a PHP version check greater than 7.4.16 doing 

    stream_filter_register('encodeFilter', EncodeFilter::class);
    stream_filter_register('decodeFilter', DecodeFilter::class);

    in the register function. This was causing the distortion in uploaded iamges in SugarCRM.
  • Yes that rings a bell when I was trying to work out what the problem was on v12 image documents.

    We were about to upgrade to v13 anyway, and Sugar Support were sure that the issue was fixed in v13,

    It turns out they were correct.

    I tried to compare what the v12 code was doing and what the v13 code was doing, but couldn't work out that the problem was or what they did to fix it, and since it works in v13 we didn't need to worry about it.