php-imap icon indicating copy to clipboard operation
php-imap copied to clipboard

[BUG] Return value of IncomingMailAttachment::getFileInfo() must be of the type string, bool returned

Open Polkurier opened this issue 4 years ago • 11 comments

Environment (please complete the following information):

  • PHP IMAP version: 4.1.0
  • PHP Version: 7.3
  • Type of execution: CLI

Describe the bug

While trying to get mime type of attached file we got warning:

PHP Warning:  finfo::buffer(): Failed identify data 0:JPEG image data, Exif standard: [TIFF image data, big-endian, direntries=15, height=2736, bps=0, manufacturer=HUAWEI, model=VOG-L29, orientation=[*0*], xresolution=210, yresolution=218, resolutionunit=2, software=VOG-L29 10.1.0.150(C431E19R2P5), datetime=2020:09:22 14:50:25, GPS-Data, width=3648]name use count (30) exceeded in /home/xxx/vendor/php-imap/php-imap/src/PhpImap/IncomingMailAttachment.php on line 140

This resulted in fatal error:

Return value of PhpImap\IncomingMailAttachment::getFileInfo() must be of the type string, bool returned

The used code:

$attachment->getFileInfo(FILEINFO_MIME_TYPE);

The headers of the parsed email, if required and possible (only, if it's NOT confidential):

Return-Path: <[email protected]>
Delivered-To: [email protected]
Received: from xxxx.xxxx.pl
        by xxxx.xxxx.pl with LMTP
        id 8AR5N0v0aV9FlgAAKkeIPA
        (envelope-from <[email protected]>)
        for <[email protected]>; Tue, 22 Sep 2020 14:55:39 +0200
Return-Path: <[email protected]>
Envelope-To: [email protected]
Delivery-Date: Tue, 22 Sep 2020 14:55:39 +0200
Received: from n1.ip4.dyalcom.pl ([xx.xx.xx.xx])
        by xxxx.xxxx.pl with esmtps  (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
        (Exim 4.94)
        (envelope-from <[email protected]>)
        id 1kKhpZ-000A4Q-UF
        for [email protected]; Tue, 22 Sep 2020 14:55:39 +0200
Dkim-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;
        d=xxxx.pl; s=default; h=Content-Type:MIME-Version:Message-ID:Date:
        Subject:In-Reply-To:References:To:From:Sender:Reply-To:Cc:
        Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:
        Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:
        List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive;
         bh=Zkg5k5xJGkbFTjrtGDEN9jg6Fez1EhIG64WN2ManFWY=; b=I+yfWwNL4NvJG1hlH28voCSof
        wRDRnaK3lFfqimZiocNDiAwwPKN7ouKleV/CDacQK65DhjQh8JdR+mMjy/F2cAaPyCZfG2RZwmJjR
        XOgrIciuDaUekiNdoZqYBLQSTbvXb65uZovjbSbG8qIXDyy1z4oVd9uFRX/lJZpS4z8YQQO9wRp1S
        ouYwCEd66h+1kS1GM0+KTHw/p8ZdU3VhmI71xy0s5efH1h316+uBhfhl9ivSCA518KcCt9J8vvR9E
        oOFWkSJYAskQ7pEtcQNB4a0SXwkYdLhfvzjcdBHmMLIbJNTmCUa2wdnhKyfeeEDdzc/E9pEMFBu22
        Mfc/PA8RA==;
Received: from eml63.neoplus.adsl.tpnet.pl ([xx.xx.xx.xx]:xxxxx helo=Sekretariat)
        by n1.dyalcom.pl with esmtpa (Exim 4.93)
        (envelope-from <[email protected]>)
        id 1kKho2-0002dn-AK
        for [email protected]; Tue, 22 Sep 2020 14:55:37 +0200
From: xxxxx <[email protected]>
To: 'xxxx.pl' <[email protected]>
References: <[email protected]>
In-Reply-To: <[email protected]>
Subject: RE: xxxx
Date: Tue, 22 Sep 2020 14:54:02 +0200
Message-Id: <[email protected]>
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="----=_NextPart_000_00B0_01D690F0.36038740"
X-Mailer: Microsoft Office Outlook 12.0
Thread-Index: AdaQs2h0UgQLWx1LThq2+cE8CDbQlgAKtDgA
Content-Language: pl
X-Antivirus: Avast (VPS 200922-0, 2020-09-22), Outbound message
X-Antivirus-Status: Clean
X-Antiabuse: This header was added to track abuse, please include it with any abuse report
X-Antiabuse: Primary Hostname - n1.dyalcom.pl
X-Antiabuse: Original Domain - xxxx.pl
X-Antiabuse: Originator/Caller UID/GID - [47 12] / [47 12]
X-Antiabuse: Sender Address Domain - xxxx.pl
X-Get-Message-Sender-Via: n1.dyalcom.pl: authenticated_id: [email protected]
X-Authenticated-Sender: n1.dyalcom.pl: [email protected]
X-Source:
X-Source-Args:
X-Source-Dir:
X-Antivirus-Scanner: Clean mail though you should still use an Antivirus
X-Evolution-Source: aa0ecefb2703030a913a071ee66d7973016f41ec

Polkurier avatar Sep 22 '20 13:09 Polkurier

I have some vague recollection of ext-exif issues with certain jpegs but can't recall the details at the moment.

bapcltd-marv avatar Sep 22 '20 14:09 bapcltd-marv

I dig a bit and it seems to be bug in https://github.com/file/file (as discussed here https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=928009). I don't think we can do anything here apart from not returning bool.

Polkurier avatar Sep 22 '20 14:09 Polkurier

i got the same problem, a null getFileinfo makes an error 500.

Remi81 avatar Dec 01 '20 10:12 Remi81

I changed the return type in this way, although It's not so clean..

    public function getFileInfo($fileinfo_const = FILEINFO_NONE): string
    {
        if ((FILEINFO_MIME == $fileinfo_const) and (false != $this->mimeType)) {
            return $this->mimeType;
        }

        $finfo = new finfo($fileinfo_const);

        if (!($ftype = $finfo->buffer($this->getContents()))) {
            $ftype = 'unknown';
        }
        return $ftype;
    }

sabas avatar Mar 01 '21 18:03 sabas

Does this issue still exist with the latest release?

Sebbo94BY avatar Jan 07 '22 01:01 Sebbo94BY

Just got this issue today in a prod environment with php-imap 4.5.1 and php 7.3:

[2022-03-24T14:16:14.962500+00:00] app.INFO: ErrorException: Warning: finfo::buffer(): Failed identify data 0:JPEG image data, JFIF standard 1.01, resolution (DPI), density 300x300, segment length 16, Exif Standard: [TIFF image data
, big-endian, direntries=7, orientation=upper-left, xresolution=98, yresolution=106, resolutionunit=2, software=Adobe Photoshop CS2 Macintosh, datetime=2012:02:10 11:36:42]name use count (30) exceeded

Alderi-Tokori avatar Mar 24 '22 14:03 Alderi-Tokori

Thanks for the info!

Sebbo94BY avatar Mar 24 '22 14:03 Sebbo94BY

Just got this issue today too in a prod environment with php-imap 4.5.3 and php 7.3:

tito10047 avatar Mar 25 '22 09:03 tito10047

Same issue here with php-imap 4.5.2 and php 7.3.

Synergie-RL avatar Apr 04 '22 07:04 Synergie-RL

@Sebi94nbg Same issue version 5.0.0, PHP 7.4.28

Warning: finfo::buffer(): Failed identify data 0:JPEG image data, JFIF standard 1.01, resolution (DPI), density 300x300, segment length 16, Exif Standard: [TIFF image data, big-endian, direntries=4]name use count (30) exceeded

In fact, the message above is a warning. The error in production is Uncaught PHP Exception TypeError: "Return value of PhpImap\IncomingMailAttachment::getFileInfo() must be of the type string, bool returned"

sdespont avatar Apr 06 '22 09:04 sdespont

Thanks for the feedback and information. I'll try to reproduce and fix it.

Sebbo94BY avatar Apr 06 '22 20:04 Sebbo94BY