Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RegEx in SendSmtpEmailAttachment::setContent fails #56

Open
mirsch opened this issue Jul 13, 2018 · 6 comments
Open

RegEx in SendSmtpEmailAttachment::setContent fails #56

mirsch opened this issue Jul 13, 2018 · 6 comments

Comments

@mirsch
Copy link

mirsch commented Jul 13, 2018

the RegEx in SendSmtpEmailAttachment::setContent does not evaluate to true
I tried $content = base64_encode(file_get_contents($filepath));
which evaluates to false and
$content = chunk_split(base64_encode(file_get_contents($filepath)));
returns 0
So InvalidArgumentException is thrown all the time.
Attachment is an PDF File ca. 50-60kb

@pierre-H
Copy link

pierre-H commented Mar 4, 2019

Same problem ... :-(

@Lreus
Copy link

Lreus commented Feb 6, 2020

Hello everyone,

As we encountered the same bug with a 480Kb jpg attachment, it appears that the validation process in class SendSmtpEmailAttachment is the source of the error.

Indeed the statement !preg_match("/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/", $this->container['content']) used several times in the code raises the PREG_JIT_STACKLIMIT_ERROR (code 6 returned from preg_last_error()) documented in php manual.

Disabling PCRE JIT wiht statement ini_set('pcre.jit', '0'); for debugging purpose showed that preg_match raised the PREG_RECURSION_LIMIT_ERROR (code 3) that we could pass by raising the limit with ini_set('pcre.recursion_limit', '1000000000');

A solution would be to validate attachment content with false !== base_64_decode($content, $strict = true)

@alexandrebrubeyonds
Copy link

Up, problem still here, I can't join a pdf

@chris-cara
Copy link

Up, same problem for me with a 75Ko pdf attachment.

When i tried to convert the base64 to pdf document with an online converter, the pdf is ok

@andreipop2005
Copy link

Is this API dead?? Nobody from Sendinblue to handle it?

@orinoco
Copy link

orinoco commented Jan 27, 2023

You can work around this by including the base64 content in the constructor, which doesn't run it through the regex check (which causes the PREG_JIT_STACKLIMIT_ERROR).

    $content = base64_encode(...);
    $attachment = new SendSmtpEmailAttachment(["name" => $terms->getName(), "content" => $content]);

Not sure why they would run large attachments through a regex in the first place, tbh.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants