Details
-
Bug
-
Status: Needs Feedback (View Workflow)
-
Critical
-
Resolution: Unresolved
-
13.3
-
None
-
None
-
None
-
MariaDB 13.3.0-MariaDB-asan-debug, self-built from commit 392818112 with -DWITH_ASAN=ON -DCMAKE_BUILD_TYPE=Debug; Linux x86_64; requires > 4 GB RAM for the intermediate buffer
Description
Nested string operations that produce an intermediate exceeding 2^32 bytes crash with an assertion in Binary_string::realloc_raw. On release builds the realloc is skipped (buffer appears big enough due to uint32 wrap) → heap buffer overflow write.
Reproduce (non-superuser)
SELECT REGEXP_REPLACE(REPEAT('a', 1073741823), '(.+)', '\\1\\1\\1\\1\\1'); |
Actual result
Assertion 'len > alloc_length' failed in Binary_string::realloc_raw
|
sql/sql_string.cc:89
|
Root cause
realloc_raw receives len as size_t but compares it with uint32 alloc_length; the wrapped len is smaller than alloc_length, so the assert fires. On release builds the realloc is skipped and subsequent writes overflow the existing buffer.
Expected result
The statement should return an error without crashing.
Severity assessment
HIGH — same class as the real_alloc overflow; potential heap OOB write on release builds.
Attachments
Issue Links
- relates to
-
MDEV-42546 Assertion `len > alloc_length' failed in Binary_string::realloc_raw on JSON_QUOTE of a 44739243 byte string, and NULL on optimized builds
-
- Open
-
-
MDEV-42550 CONCAT, CONCAT_WS, EXPORT_SET, HEX, LOWER, UPPER, SPACE and CAST AS CHAR compute the result length in 32 bits, and give a cut or wrong result past 4 GB, or assert on debug builds
-
- Open
-