Skip to content

Null pointer dereference in php_mb_check_encoding() via mb_ereg_search_init()

Low
iluuu1994 published GHSA-wm6j-2649-pv75 May 7, 2026

Package

ext-mbstring (PHP)

Affected versions

< 8.5.6
< 8.4.21
< 8.3.31
< 8.2.31

Patched versions

8.5.6
8.4.21
8.3.31
8.2.31

Description

The following PHP code triggers a segmentation fault due to a NULL pointer dereference:

<?php
mb_regex_encoding('iso-8859-11');
$test_str = 'x';

if (mb_ereg_search_init($test_str)) {
    $val = mb_ereg_search_pos("x");
    var_dump($val);
} else {
    var_dump(false);
}

The crash occurs due to a mismatch between Oniguruma and mbfl encoding support:

  1. Oniguruma (the regex library) supports iso-8859-11 (Thai encoding)
  2. mbfl (mbstring's internal encoding library) does NOT support iso-8859-11

int php_mb_regex_set_mbctype(const char *encname)
{
OnigEncoding mbctype = _php_mb_regex_name2mbctype(encname);
if (mbctype == ONIG_ENCODING_UNDEF) {
return FAILURE;
}
MBREX(current_mbctype) = mbctype;
MBREX(current_mbctype_mbfl_encoding) = mbfl_name2encoding(encname);
return SUCCESS;
}

When mb_regex_encoding('iso-8859-11') is called:

  • php_mb_regex_set_mbctype() validates the encoding against Oniguruma → succeeds
  • mbfl_name2encoding('iso-8859-11') is called → returns NULL
  • MBREX(current_mbctype_mbfl_encoding) is set to NULL

Later, when mb_ereg_search_init() calls php_mb_check_encoding():

  • php_mb_regex_get_mbctype_encoding() returns NULL
  • php_mb_check_encoding() dereferences the NULL pointer → SEGV

This vulnerability allows a denial of service (DoS). An attacker can reliably crash a PHP process when user-controlled input influences the encoding passed to mb_regex_encoding() and the application subsequently uses mbregex search APIs.

Enumeration of all Oniguruma-supported encodings vs mbfl support:

Encoding / aliases Oniguruma mbfl Status
iso-8859-1 … iso-8859-10 Safe
iso-8859-11, ISO8859-11 CRASH
iso-8859-13 … iso-8859-16 Safe
EUC-JP aliases: UJIS CRASH
EUC-CN aliases: GB-2312 CRASH
KOI8 aliases: KOI-8R CRASH
ASCII aliases: US_ASCII, ISO646 CRASH
KOI8 (no suffix) Safe (rejected by mb_regex_encoding())
All other encodings Safe

Credits

Viet Hoang Luu - The University of Melbourne
Amirmohammad Pasdar - The University of Melbourne
Wachiraphan Charoenwet - The University of Melbourne
Shaanan Cohney - The University of Melbourne
Toby Murray - The University of Melbourne
Van-Thuan Pham - The University of Melbourne

Severity

Low

CVE ID

CVE-2026-7259

Weaknesses

NULL Pointer Dereference

The product dereferences a pointer that it expects to be valid but is NULL. Learn more on MITRE.

Credits