Forums / General Questions / Upload file extension being stripped from .jpeg files

Upload file extension being stripped from .jpeg files

Started by badarac on 8 Jun 2021, 4:45 PM · Views: 2,598

Results 1 to 18 of 18
8 Jun 2021, 4:45 PM
#1
badarac avatar

badarac

Totally Zenned

Join Date:
Aug 2009
Location:
Longs, SC
Posts:
635
Plugin Contributions:
0

Upload file extension being stripped from .jpeg files

Site is running 1.5.7b and some products have text/file attributes for customers to upload images. On the product page, the files is selected from the desktop and when the product is added to the cart it displays the full file name and extension. On checkout success, the order is written to the orders.products_attributes table, the products_options_values field is written as file-id. (313. instead of 313.jpeg for example) when the uploaded file extension is .jpeg. The file is uploaded in the images/upload folder with the correct name. If the file extension is .jpg it works as expected. I'm struggling to find the cause of this. Can anybody point me in the right direction?

8 Jun 2021, 5:01 PM
#2
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,751
Plugin Contributions:
56

Re: Upload file extension being stripped from .jpeg files

Compare your copy of includes/classes/upload.php to a fresh download from 1.5.7b (your version).

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

8 Jun 2021, 5:16 PM
#3
badarac avatar

badarac

Totally Zenned

Join Date:
Aug 2009
Location:
Longs, SC
Posts:
635
Plugin Contributions:
0

Re: Upload file extension being stripped from .jpeg files

swguy:

Compare your copy of includes/classes/upload.php to a fresh download from 1.5.7b (your version).

They compared fine

8 Jun 2021, 5:25 PM
#4
badarac avatar

badarac

Totally Zenned

Join Date:
Aug 2009
Location:
Longs, SC
Posts:
635
Plugin Contributions:
0

Re: Upload file extension being stripped from .jpeg files

I should also add that this code appears to relate to the actual upload and not writing the uploaded file name to the database. No errors are received that it is an invalid file type and the file is written with the correct extension.

8 Jun 2021, 5:44 PM
#5
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,751
Plugin Contributions:
56

Re: Upload file extension being stripped from .jpeg files

OK, how about includes/classes/order.php - any changes?

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

8 Jun 2021, 5:58 PM
#6
badarac avatar

badarac

Totally Zenned

Join Date:
Aug 2009
Location:
Longs, SC
Posts:
635
Plugin Contributions:
0

Re: Upload file extension being stripped from .jpeg files

The only change is to the section building the confirmation email at around line 1018 ```php
$this->products_ordered_html .=
'<tr>' . "\n" .
//RB mod - Product Image
'<td class="product-details" align="left" valign="top" width="30">' . zen_get_products_image($this->products[$i]['id']) . '</td>' . "\n" .
//RB mod - Product Image

9 Jun 2021, 8:08 AM
#7
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Upload file extension being stripped from .jpeg files

Out of curiosity, does the same issue occur with the image file extension of tiff as compared to tif? Both of these file extensions are recognized in a default install for upload extensions. May help identify a factor contributing to stripping jpeg from the information as compared to tiff.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

9 Jun 2021, 12:37 PM
#8
badarac avatar

badarac

Totally Zenned

Join Date:
Aug 2009
Location:
Longs, SC
Posts:
635
Plugin Contributions:
0

Re: Upload file extension being stripped from .jpeg files

mc12345678:

Out of curiosity, does the same issue occur with the image file extension of tiff as compared to tif? Both of these file extensions are recognized in a default install for upload extensions. May help identify a factor contributing to stripping jpeg from the information as compared to tiff.

I didn't want to do this on the live site since it requires putting completed orders in. I happened to have a clone of the site that is being used to build a new site. It has a fresh database but the files are identical with the exception of the config files. I added a product to the database with a single attribute type file. Interestingly I found that it works correctly. I'm going to do a full comparison of the files from both sites. Hopefully, I'll find some files that are different. If not that kind of points to a database issue. I don't see any structure differences in the orders_products_attributes table though.

9 Jun 2021, 2:33 PM
#9
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,751
Plugin Contributions:
56

Re: Upload file extension being stripped from .jpeg files

Tested in unmodified 1.5.7c with test product 34; used a file with extension "jpeg" as the front image, completed the order, orders_products_attributes.products_options_values field looks correct.

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

9 Jun 2021, 2:41 PM
#10
badarac avatar

badarac

Totally Zenned

Join Date:
Aug 2009
Location:
Longs, SC
Posts:
635
Plugin Contributions:
0

Re: Upload file extension being stripped from .jpeg files

swguy:

Tested in unmodified 1.5.7c with test product 34; used a file with extension "jpeg" as the front image, completed the order, orders_products_attributes.products_options_value field looks correct.

That's similar to what I'm seeing on the clone. The files from both compared as expected. I exported the table, dropped the table on the clone, and imported and emptied to the clone db. Still worked fine. I'm going to import the entire database and see if that causes the problem. Narrowing things down.

9 Jun 2021, 2:49 PM
#11
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,751
Plugin Contributions:
56

Re: Upload file extension being stripped from .jpeg files

The field orders_products_attributes.products_options_values should be TEXT - is it? If not is it possible the value is just getting truncated?

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

9 Jun 2021, 3:00 PM
#12
badarac avatar

badarac

Totally Zenned

Join Date:
Aug 2009
Location:
Longs, SC
Posts:
635
Plugin Contributions:
0

Re: Upload file extension being stripped from .jpeg files

swguy:

The field orders_products_attributes.products_options_values should be TEXT - is it? If not is it possible the value is just getting truncated?

Yes it is text

13 Jun 2021, 3:30 AM
#13
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,511
Plugin Contributions:
176

Re: Upload file extension being stripped from .jpeg files

Is the .jpeg file's filename equally wrong in the "files_uploaded" table?

I suspect the issue may be occurring in this part of the code, in the shopping_cart.php class:

                if ($products_options_file->parse(TEXT_PREFIX . $_POST[UPLOAD_PREFIX . $i])) {
                  $products_image_extension = substr($products_options_file->filename, strrpos($products_options_file->filename, '.'));
                  if (zen_is_logged_in()) {
                    $db->Execute("INSERT INTO " . TABLE_FILES_UPLOADED . " (sesskey, customers_id, files_uploaded_name) VALUES ('" . zen_session_id() . "', " . (int)$_SESSION['customer_id'] . ", '" . zen_db_input($products_options_file->filename) . "')");
                  } else {
                    $db->Execute("INSERT INTO " . TABLE_FILES_UPLOADED . " (sesskey, files_uploaded_name) VALUES ('" . zen_session_id() . "', '" . zen_db_input($products_options_file->filename) . "')");
                  }
                  $insert_id = $db->Insert_ID();
                  $real_ids[TEXT_PREFIX . $_POST[UPLOAD_PREFIX . $i]] = $insert_id . ". " . $products_options_file->filename;
                  $products_options_file->set_filename("$insert_id" . $products_image_extension);
                  if (!($products_options_file->save())) {
                    break;
                  }
                } else {

The green lines are related to the files_uploaded table, hence my question above. If that table's entry is fine, then perhaps the issue is happening afterward.
The red line is (I think) where the filename is "set" for the orders_products_attributes entry. But it's still puzzling about the symptom you're reporting.

Do you have any attribute-related customizations/plugins installed?

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

14 Jun 2021, 12:10 PM
#14
badarac avatar

badarac

Totally Zenned

Join Date:
Aug 2009
Location:
Longs, SC
Posts:
635
Plugin Contributions:
0

Re: Upload file extension being stripped from .jpeg files

DrByte:

Is the .jpeg file's filename equally wrong in the "files_uploaded" table?

The filename in that table is VERY incorrect. This is one of the entries 3E8A14F3-629D-4A6A-ADCA-E0B795AABCFB.jpeg. All the others for this file extension are similar.

There are no attribute related customiaztions or plugins.

14 Jun 2021, 12:26 PM
#15
badarac avatar

badarac

Totally Zenned

Join Date:
Aug 2009
Location:
Longs, SC
Posts:
635
Plugin Contributions:
0

Re: Upload file extension being stripped from .jpeg files

I did a compare of shopping_cart.php to 1.5.7b. I did find one change

// appears to confuse products priced by attributes
     if ($product->fields['product_is_always_free_shipping'] == '1' or $product->fields['products_virtual'] == '1') {
        $shipping_attributes_price = zen_get_discount_calc($product->fields['products_id'], $attribute_price->fields['products_attributes_id'], 
       $attribute_price->fields['options_values_price'], $qty);
       //Set these variable to a numeric to eliminate warning debug logs - rb
       $freeShippingTotal = intval($freeShippingTotal);
       $shipping_attributes_price = intval($shipping_attributes_price);
       $freeShippingTotal += $shipping_attributes_price;
     }
 
14 Jun 2021, 3:28 PM
#16
badarac avatar

badarac

Totally Zenned

Join Date:
Aug 2009
Location:
Longs, SC
Posts:
635
Plugin Contributions:
0

Re: Upload file extension being stripped from .jpeg files

It seems I may have figured this out. The old database had not been converted from utf8 to utf8mb4. The config file was set to the utf8mb4 charset. I modified the config file to utf8 and tested with the .jpeg extension. It loaded the file and added to the tables correctly. I'll continue to monitor this and will update again if it breaks.

14 Jun 2021, 10:01 PM
#17
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Upload file extension being stripped from .jpeg files

badarac:

It seems I may have figured this out. The old database had not been converted from utf8 to utf8mb4. The config file was set to the utf8mb4 charset. I modified the config file to utf8 and tested with the .jpeg extension. It loaded the file and added to the tables correctly. I'll continue to monitor this and will update again if it breaks.
Is this to also mean that haven't run the convert to utf8mb4 plugin to... well update/convert the database to utf8mb4?

I mean will be interesting to see/know that the craziness no longer happens at all, but... :)

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

15 Jun 2021, 1:08 PM
#18
badarac avatar

badarac

Totally Zenned

Join Date:
Aug 2009
Location:
Longs, SC
Posts:
635
Plugin Contributions:
0

Re: Upload file extension being stripped from .jpeg files

You would be 100% correct in saying that the conversion plugin was not run. OOPS! :cool: