Skip to content

Broken email sending with attachment due to malfucntioning base64 validation (catastrophic backtracking of regexp) #90

@pgolofit

Description

@pgolofit

This line:

if (!is_null($content) && (!preg_match("/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/", $content))) {

Was Added around 4 months ago and broke email sending with attachments in this commit: 563eef8

Pattern /^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/ works only for shorter strings up to 98288 characters. After that limit it fails and preg_match returns false. Which makes this setContent function to fail to recognise the correct base64 string.

This is due to catastrophic backtracking of regexp. More on this issue eg. here: https://medium.com/@catcatduatiga/when-regex-eats-the-cpu-a-postmortem-of-catastrophic-backtracking-in-php-and-how-tiny-patterns-can-64b2aa64a530

Because of this issue, only quite small attachments can be sent.

This can be fixed eg. with replacing the validation to base64_encode and base64_decode and comparison with oryginal string.

Temporary solution we found ist to switch off PRCE JIT temporaily ini_set("pcre.jit", "0"); but it is only temporary.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions