Uploaded image for project: 'phpBB3'
  1. phpBB3
  2. PHPBB3-11148

Fix uploading attachments from Android 4 powered devices

    Details

    • Type: Bug
    • Status: Unverified Fix
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.0.11
    • Fix Version/s: 3.1.0-RC3
    • Component/s: Posting
    • Labels:
      None

      Description

      Trying to upload an attachment to phpBB from some mobile devices running Android 4.x results in the following error:

      The image file you tried to attach is invalid.

      This is caused by an invalid mimetype, returned by the default Android browser. The incorrect mimetype is: application/octet-stream
      phpBB looks if it contains image/ and is therefore failing the check and rejecting the attachment.

      I've come to this conclusion by upload tests from people on different mobile devices, operating systems and browsers:

      [OK]   HTC Desire Android 2.3.5
      [OK]   HTC Sensation Android 2.3.4
      [FAIL] HTC Sensation Android 4.0.3
      [FAIL] HTC One S Android 4
      [OK]   HTC One S Android 4 (Firefox)
      [FAIL] HTC HD2 Android 4.1.2
      [FAIL] HTC EVO 4G LTE Android 4.0.4 
      [FAIL] Nexus S Android 4
      [OK]   Samsung Galaxy S2 Android 4.0.4 
      [OK]   Samsung Galaxy S2 Android 4.0.4 (Opera Mobile)
      [OK]   Samsung Galaxy S3 Android 4.0.4
      [OK]   Samsung Galaxy S3 Android 4.0.4 (Firefox) 
      [OK]   iPhone 4 iOS 6.0
      [OK]   iPad 2 iOS 6.0 (10A403)
      [OK]   Samsung Focus (SGH-i917) Windows Phone 7.5 
      

      (Thanks for testing everyone)

      Please note that disabling the ACP setting "Check attachment files, Some browsers can be tricked to assume an incorrect mimetype for uploaded files.." will not help because it's checked in includes/functions_posting.php, regardless of the setting. (the setting is only working in includes/functions_upload.php which is runned after functions_posting)

      includes/functions_posting.php

      // Make sure the image category only holds valid images...
      if ($cat_id == ATTACHMENT_CATEGORY_IMAGE && !$file->is_image())
      {
      	$file->remove();
       
      	// If this error occurs a user tried to exploit an IE Bug by renaming extensions
      	// Since the image category is displaying content inline we need to catch this.
      	trigger_error($user->lang['ATTACHED_IMAGE_NOT_IMAGE']);
      }
      

      includes/functions_upload.php

      /**
      * Check if file is an image (mimetype)
      *
      * @return true if it is an image, false if not
      */
      function is_image()
      {
      	return (strpos($this->mimetype, 'image/') !== false) ? true : false;
      }
      

        Issue Links

          Activity

          Hide
          Marc Marc added a comment -

          This seems to have been fixed in Chrome on Android 4.2.2. Uploading works without issues.
          Nonetheless, we should try to check the file itself.

          Show
          Marc Marc added a comment - This seems to have been fixed in Chrome on Android 4.2.2. Uploading works without issues. Nonetheless, we should try to check the file itself.
          Hide
          Derky Derky added a comment -

          It only occurs in the stock Android browser. Not Chrome, Firefox or any other mobile browser.
          Please try it with the stock browser.

          Show
          Derky Derky added a comment - It only occurs in the stock Android browser. Not Chrome, Firefox or any other mobile browser. Please try it with the stock browser.
          Hide
          Marc Marc added a comment -

          I think I was able to pinpoint the actual issue. Have you checked the MIME type of images made with an android device? I just tried uploading an image from my phone with firefox on my laptop. The mime type is actually empty. The filespec class then defaults to application/octetstream:

          		if (!$this->mimetype)
          		{
          			$this->mimetype = 'application/octetstream';
          		}

          P.S: I can't test the stock browser on my N4 as that one doesn't exist on nexus devices anymore. .

          Show
          Marc Marc added a comment - I think I was able to pinpoint the actual issue. Have you checked the MIME type of images made with an android device? I just tried uploading an image from my phone with firefox on my laptop. The mime type is actually empty. The filespec class then defaults to application/octetstream: if (!$this->mimetype) { $this->mimetype = 'application/octetstream'; } P.S: I can't test the stock browser on my N4 as that one doesn't exist on nexus devices anymore. .
          Hide
          Derky Derky added a comment - - edited

          The mimetype is not empty, it's specifically set to: application/octet-stream (note the dash between octet and stream).

          Since the mimetype guesser isn't going to be included for a while, I suggest to just overwrite the mimetype when a jpg-file is uploaded with an Android browser and the mimetype is set to application/octet-stream:

          Open: /includes/functions_upload.php
          Find:

          $this->extension = strtolower($this->get_extension($this->realname));

          After Add:

          // Android stock browser provides incorrect mimetype for images, overwrite it
          global $user;
          if ((strpos($user->browser, '; Android') !== false) && ($this->mimetype === 'application/octet-stream'))
          {
          	if ($this->extension === 'jpg') {
          		$this->mimetype = 'image/jpeg';
          	}
          	else if ($this->extension === 'png') {
          		$this->mimetype = 'image/png';
          	}
          }

          Show
          Derky Derky added a comment - - edited The mimetype is not empty, it's specifically set to: application/octet-stream (note the dash between octet and stream). Since the mimetype guesser isn't going to be included for a while, I suggest to just overwrite the mimetype when a jpg-file is uploaded with an Android browser and the mimetype is set to application/octet-stream: Open: /includes/functions_upload.php Find: $this->extension = strtolower($this->get_extension($this->realname)); After Add: // Android stock browser provides incorrect mimetype for images, overwrite it global $user; if ((strpos($user->browser, '; Android') !== false) && ($this->mimetype === 'application/octet-stream')) { if ($this->extension === 'jpg') { $this->mimetype = 'image/jpeg'; } else if ($this->extension === 'png') { $this->mimetype = 'image/png'; } }

            People

            • Assignee:
              Marc Marc
              Reporter:
              Derky Derky
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development