barbushin / php-imap

Manage mailboxes, filter/get/delete emails in PHP (supports IMAP/POP3/NNTP)
MIT License
1.66k stars 456 forks source link

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

Open Polkurier opened 3 years ago

Polkurier commented 3 years ago

Environment (please complete the following information):

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: <xxxx@xxxx.com.pl>
Delivered-To: xxxx@xxxx.pl
Received: from xxxx.xxxx.pl
        by xxxx.xxxx.pl with LMTP
        id 8AR5N0v0aV9FlgAAKkeIPA
        (envelope-from <xxxx@xxxx.pl>)
        for <xxxx@xxxx.pl>; Tue, 22 Sep 2020 14:55:39 +0200
Return-Path: <xxxx@xxxx.pl>
Envelope-To: xxxx@xxxx.pl
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 <xxxx@xxxx.pl>)
        id 1kKhpZ-000A4Q-UF
        for xxxx@xxxx.pl; 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 <xxxx@xxxx.pl>)
        id 1kKho2-0002dn-AK
        for xxxx@xxxx.pl; Tue, 22 Sep 2020 14:55:37 +0200
From: xxxxx <xxxx@xxxx.pl>
To: 'xxxx.pl' <xxxx@xxxx.pl>
References: <1i3TjhRnc5VPeW4HZcQU5pd6MqWRHNtJ14KJ20PB2I@xxxx.pl>
In-Reply-To: <1i3TjhRnc5VPeW4HZcQU5pd6MqWRHNtJ14KJ20PB2I@xxxx.pl>
Subject: RE: xxxx
Date: Tue, 22 Sep 2020 14:54:02 +0200
Message-Id: <00af01d690df$727ab740$577025c0$@com.pl>
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: xxxx@xxxx.pl
X-Authenticated-Sender: n1.dyalcom.pl: xxxx@xxxx.pl
X-Source:
X-Source-Args:
X-Source-Dir:
X-Antivirus-Scanner: Clean mail though you should still use an Antivirus
X-Evolution-Source: aa0ecefb2703030a913a071ee66d7973016f41ec
bapcltd-marv commented 3 years ago

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

Polkurier commented 3 years ago

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.

Remi81 commented 3 years ago

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

sabas commented 3 years ago

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;
    }
Sebbo94BY commented 2 years ago

Does this issue still exist with the latest release?

Alderi-Tokori commented 2 years ago

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
Sebbo94BY commented 2 years ago

Thanks for the info!

tito10047 commented 2 years ago

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

Synergie-RL commented 2 years ago

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

sdespont commented 2 years ago

@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"

Sebbo94BY commented 2 years ago

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