Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

[PHP error] fopen(): Filename cannot be empty in /lib/classes/Swift/ByteStream/FileByteStream.php on line 135 #274

Closed
Cimmo opened this Issue · 17 comments

3 participants

@Cimmo

The issue is reproducible using WooCommerce WordPress plug-in, that sends an email like the one that follows.
Error thrown is:
fopen(): Filename cannot be empty in /lib/classes/Swift/ByteStream/FileByteStream.php on line 135
Swift mailer used: v4.2.2 & v4.3.0-DEV @ 20130106

I believe the offensive part is this one in the css:

            body {
                background: #eeeeee url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJCAYAAADgkQYQAAAAOklEQVQYGWP8//8/AyHAREgBIyOjMQPIJFwYaIAxSI6RbOvAViC7A90qmBXI4qRZh2EFunXYrEC2DgDc+VH0jS2AGAAAAABJRU5ErkJggg==);
            }

And this one in the body:

    <body leftmargin="0" marginwidth="0" 
topmargin="0" marginheight="0" offset="0" style="background: #eeeeee url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJCAYAAADgkQYQAAAAOklEQVQYGWP8//8/AyHAREgBIyOjMQPIJFwYaIAxSI6RbOvAViC7A90qmBXI4qRZh2EFunXYrEC2DgDc+VH0jS2AGAAAAABJRU5ErkJggg==);">

That Swift mailer doesn't handle correctly, mail of course is not sent.

Thanks
Marco Cimmino

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

        <title>WordPress 3.5</title>
        <style type="text/css">
            /* Client-specific/Reset Styles */
            #outlook a{padding:0;} /* Force Outlook to provide a "view in browser" button. */
            body{
                width:100% !important; /* Force Hotmail to display emails at full width */
                -webkit-text-size-adjust:none; /* Prevent Webkit platforms from changing default text sizes. */
                margin:0;
                padding:0;
            }
            img{border:none; font-size:14px; font-weight:bold; height:auto; line-height:100%; outline:none; text-decoration:none; text-transform:capitalize;}
            #backgroundTable{height:100% !important; margin:0; padding:0; width:100% !important;}
            mark { background: transparent none; color: inherit; }
            /* Template Styles */

            body {
                background: #eeeeee url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJCAYAAADgkQYQAAAAOklEQVQYGWP8//8/AyHAREgBIyOjMQPIJFwYaIAxSI6RbOvAViC7A90qmBXI4qRZh2EFunXYrEC2DgDc+VH0jS2AGAAAAABJRU5ErkJggg==);
            }

            #templateContainer{
                border: 1px solid #bebebe;
                -webkit-box-shadow:0 0 0 3px rgba(0,0,0,0.1);
                -webkit-border-radius:6px;
            }

            h1, .h1,
            h2, .h2,
            h3, .h3,
            h4, .h4 {
                color:#282828;
                display:block;
                font-family:Arial;
                font-size:34px;
                font-weight:bold;
                line-height:150%;
                margin-top:0;
                margin-right:0;
                margin-bottom:10px;
                margin-left:0;
                text-align:left;
                line-height: 1.5;
            }

            h2, .h2{
                font-size:30px;
            }

            h3, .h3{
                font-size:26px;
            }

            h4, .h4{
                font-size:22px;
            }

            /* /\\/\\/\\/\\/\\/\\/\\/\\/\\/\\ STANDARD STYLING: HEADER /\\/\\/\\/\\/\\/\\/\\/\\/\\/\\ */

            #templateHeader{
                background-color: #557da1;
                background: -webkit-linear-gradient(#7797b4, #557da1);
                border-bottom:0;
                -webkit-border-top-left-radius:6px;
                -webkit-border-top-right-radius:6px;
            }

            .headerContent{
                padding:24px;
                vertical-align:middle;
            }

            .headerContent a:link, .headerContent a:visited{
                color:#ffffff;
                font-weight:normal;
                text-decoration:underline;
            }

            /* /\\/\\/\\/\\/\\/\\/\\/\\/\\/\\ STANDARD STYLING: MAIN BODY /\\/\\/\\/\\/\\/\\/\\/\\/\\/\\ */

            #templateContainer, .bodyContent{
                background-color:#fdfdfd;
                -webkit-border-radius:6px;
            }

            .bodyContent div{
                color: #737373;
                font-family:Arial;
                font-size:14px;
                line-height:150%;
                text-align:left;
            }

            .bodyContent div a:link, .bodyContent div a:visited{
                color: #505050;
                font-weight:normal;
                text-decoration:underline;
            }

            .bodyContent img{
                display:inline;
                height:auto;
            }

            /* /\\/\\/\\/\\/\\/\\/\\/\\/\\/\\ STANDARD STYLING: FOOTER /\\/\\/\\/\\/\\/\\/\\/\\/\\/\\ */

            #templateFooter{
                border-top:0;
                -webkit-border-radius:6px;
            }

            .footerContent div{
                color:#969696;
                font-family:Arial;
                font-size:12px;
                line-height:125%;
                text-align:left;
            }

            .footerContent div a:link, .footerContent div a:visited{
                color:#969696;
                font-weight:normal;
                text-decoration:underline;
            }

            .footerContent img{
                display:inline;
            }

            #credit {
                border:0;
                color:#969696;
                font-family:Arial;
                font-size:12px;
                line-height:125%;
                text-align:center;
            }

        </style>
    </head>
    <body leftmargin="0" marginwidth="0" 
topmargin="0" marginheight="0" offset="0" style="background: #eeeeee url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJCAYAAADgkQYQAAAAOklEQVQYGWP8//8/AyHAREgBIyOjMQPIJFwYaIAxSI6RbOvAViC7A90qmBXI4qRZh2EFunXYrEC2DgDc+VH0jS2AGAAAAABJRU5ErkJggg==);">
        <center style="padding: 70px 0 0 0;">
            <table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%" id="backgroundTable">
                <tr>
                    <td align="center" valign="top">

                        <p style="margin-top:0;"><img src="http://localhost/wp-content/uploads/2013/01/Eddie_Irvine_1999_Canada-150x112.jpg" alt="WordPress 3.5" /></p>
                        <!-- // End Template Preheader \\\\ -->
                        <table border="0" cellpadding="0" cellspacing="0" width="600" id="templateContainer" style="-webkit-box-shadow:0 0 0 3px rgba(0,0,0,0.025); -webkit-border-radius:6px;background-color:#fdfdfd;">
                            <tr>
                                <td align="center" valign="top">
                                    <!-- // Begin Template Header \\\\ -->
                                    <table border="0" cellpadding="0" cellspacing="0" width="600" id="templateHeader" style="background-color:#557da1; -webkit-border-top-left-radius:6px; -webkit-border-top-right-radius:6px; color:#ffffff; font-family:Arial; font-weight:bold; line-height:100%; vertical-align:middle;">

                                        <tr>
                                            <td class="headerContent" style="padding:24px; ">

                                                <!-- // Begin Module: Standard Header Image \\\\ -->
                                                <h1 class="h1" style="color:#ffffff !important; margin:0; text-shadow:0 1px 0 #7797b4;">New Customer Order</h1>
                                                <!-- // End Module: Standard Header Image \\\\ -->

                                            </td>
                                        </tr>

               </table>
                                    <!-- // End Template Header \\\\ -->
                                </td>
                            </tr>
                            <tr>
                                <td align="center" valign="top">
                                    <!-- // Begin Template Body \\\\ -->
                                    <table border="0" cellpadding="0" cellspacing="0" width="600" id="templateBody">
                                        <tr>
                                            <td valign="top" class="bodyContent" style="background-color:#fdfdfd;">

                                                <!-- // Begin Module: Standard Content \\\\ -->
                                                <table border="0" cellpadding="20" cellspacing="0" width="100%">
                                                    <tr>
                                                        <td valign="top">

  <div>
<p>Hai ricevuto un ordine da Marco Cimmino. Il loro ordine \xc3\xa8 il seguente:</p>


<h2>Ordine: #36 (<time datetime="2013-01-06T20:18:26+00:00">6th gennaio 2013</time>)</h2>

<table cellspacing="0" cellpadding="6" style="width: 100%; border: 1px solid #eee;" border="1" bordercolor="#eee">
    <thead>
        <tr>
            <th scope="col" style="text-align:left; border: 1px solid #eee;">Product</th>
            <th scope="col" style="text-align:left; border: 1px solid #eee;">Quantit\xc3\xa0</th>
            <th scope="col" style="text-align:left; border: 1px solid #eee;">Prezzo</th>
        </tr>
    </thead>
    <tbody>
            <tr>
        <td style="text-align:left; vertical-align:middle; border: 1px solid #eee;"> Ferrari F399 (#A32)</td>
                <td style="text-align:left; vertical-align:middle; border: 1px solid #eee;">1</td>
                <td style="text-align:left; vertical-align:middle; border: 1px solid #eee;"><span class="amount">&euro;2,400</span></td>
            </tr>


            </tbody>
            <tfoot>
                <tr>
                                <th scope="row" colspan="2" style="text-align:left; border: 1px solid #eee; border-top-width: 4px;">Subtotale carrello:</th>
                                <td style="text-align:left; border: 1px solid #eee; border-top-width: 4px;"><span class="amount">&euro;2,400</span></td>
                            </tr><tr>
                                <th scope="row" colspan="2" style="text-align:left; border: 1px solid #eee; ">Spedizione:</th>
                                <td style="text-align:left; border: 1px solid #eee; ">Spedizione Gratuita</td>
                            </tr><tr>
                                <th scope="row" colspan="2" style="text-align:left; border: 1px solid #eee; ">Totale Ordine:</th>
                                <td style="text-align:left; border: 1px 
solid #eee; "><span class="amount">&euro;2,400</span></td>
                    </tr>    </tfoot>
</table>


<h2>Dettagli cliente</h2>

    <p><strong>Email:</strong> cimmino.marco@gmail.com</p>
    <p><strong>Tel:</strong> 4444444</p>

<table cellspacing="0" cellpadding="0" style="width: 100%; vertical-align: top;" border="0">

    <tr>

        <td valign="top" width="50%">

            <h3>Indirizzo fatturazione</h3>

            <p>Marco Cimmino<br />
Via C<br />
Bo<br />
Bo<br />
40100</p>

        </td>


        <td valign="top" width="50%">

            <h3>Indirizzo spedizione</h3>

            <p>Marco Cimmino<br />
Via C<br />
Bo<br />
Bo<br />
40100</p>

        </td>


    </tr>

</table>
                                                            </div>
                                                        </td>
</tr>
</table>
<!-- // End Module: Standard Content \\\\ -->

      </td>
      </tr>
      </table>
      <!-- // End Template Body \\\\ -->
      </td>
      </tr>
          <tr>
          <td align="center" valign="top">
      <!-- // Begin Template Footer \\\\ -->
          <table border="0" cellpadding="10" cellspacing="0" width="600" id="templateFooter">
          <tr>
          <td valign="top" class="footerContent">
      <table border="0" cellpadding="10" cellspacing="0" width="100%">
      <tr>
      <td colspan="2" valign="middle" id="credit" style="border:0; color:#969696; font-family:Arial; font-size:12px; line-height:
125%; text-align:center;">
    <p>WordPress 3.5 &#8211; Powered by WooCommerce</p>
</td>
</tr>

</table>
</td>
</tr>
</table>
<!-- // End Template Footer \\\\ -->
</td>
</tr>
</table>
<br />
</td>
</tr>
</table>
</center>
</body>
</html>
@Cimmo

Ok, an ugly workaround that works is this one:
edit the file: /lib/classes/Swift/ByteStream/FileByteStream.php
at line: 135
change the line from:

if (!$this->_reader = fopen($this->_path, 'rb')) {

to:

if (empty($this->_path))
    return null;
if (!$this->_reader = fopen($this->_path, 'rb')) {

At least PHP doesn't crash, but of course the background is still not handled correctly.

@Cimmo

Reproducible on v4.3.0 final version.

@xdecock
Collaborator
@Cimmo

First of all is not a warning, but an error.
Secondly I already pasted a full source of an example email on how to reproduce the issue. Did you try that?

@xdecock
Collaborator
@Cimmo

Ok man, apologies, the problem is totally unrelated to the above email, for some reason I have this code:

    if (!empty($attachments)) {
        foreach ($attachments as $attachment) {
            try {
                $message->attach(Swift_Attachment::fromPath($attachment));
            } catch (Swift_IoException $e) {
                continue;
            }
        }
    }

And for some other bug it got executed with empty $attachment causing the error in the title.
Now, I fixed my code, but still I don't get why Exception didn't kick in and also, is it by design that passing empty string is not handled in the library?

Again sorry for the initial ticket, I got high jacked by the css/html.

Marco

@xdecock
Collaborator
@xdecock xdecock referenced this issue from a commit in xdecock/swiftmailer
@xdecock xdecock Add a test for bug #274 a063002
@Cimmo

In a similar way it also fails to throw the exception if you have a filename that does not exist on the disk.
[Sun Jan 20 14:34:03 2013] [error] [client 127.0.0.1] PHP Warning: fopen(ciao): failed to open stream: No such file or directory in /var/www/wp-content/plugins/cimy-swift-smtp/Swift/lib/classes/Swift/ByteStream/FileByteStream.php on line 135, referer: http://localhost/wordpress35/cassa/

also if I can suggest, please update the documentation with such Exception, in the pdf I couldn't find it.

@xdecock
Collaborator
@Cimmo

Cool, thanks.

@fabpot
Owner

should be fixed now.

@fabpot fabpot closed this
@Cimmo

I don't see this fixed in the latest trunk, neither the CHANGES mention it. Can you please advise?

@xdecock
Collaborator

162971f ?

PS : the invalid open will still be opened when sending, it's another bug alltogether

@Cimmo

In a similar way it also fails to throw the exception if you have a filename that does not exist on the disk.
Yup the exception will be thrown when sending

That patch doesn't fix the issue described later, despite your comment suggests it was.

@xdecock
Collaborator
@Cimmo

I believe you should not prevent an email to be sent for an attachment error. This is my idea though, but not my project.

@xdecock
Collaborator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.