APIv3-php-library icon indicating copy to clipboard operation
APIv3-php-library copied to clipboard

RegEx in SendSmtpEmailAttachment::setContent fails

Open mirsch opened this issue 7 years ago • 7 comments

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

mirsch avatar Jul 13 '18 12:07 mirsch

Same problem ... :-(

pierre-H avatar Mar 04 '19 16:03 pierre-H

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)

Lreus avatar Feb 06 '20 13:02 Lreus

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

alexandrebrubeyonds avatar Mar 29 '22 08:03 alexandrebrubeyonds

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

vdlchris avatar Apr 21 '22 13:04 vdlchris

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

andreipop2005 avatar Jul 05 '22 10:07 andreipop2005

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.

orinoco avatar Jan 27 '23 23:01 orinoco

For work around see https://github.com/getbrevo/brevo-php/issues/11#issuecomment-2180956969

StevenRenaux avatar Jun 20 '24 15:06 StevenRenaux