Description
Description
Struct zend_string
is defined as a flexible array
Lines 373 to 378 in c2fddac
and used in the middle of another struct
zend_accel_globals
php-src/ext/opcache/ZendAccelerator.h
Lines 227 to 228 in c2fddac
The offset of array header zend_string::val
and the following wrapped array zend_accel_globals::_key
are not aligned.
According to the output of pahole
on x86_64,
struct _zend_string {
zend_refcounted_h gc; /* 0 8 */
zend_ulong h; /* 8 8 */
size_t len; /* 16 8 */
char val[1]; /* 24 1 */
/* size: 32, cachelines: 1, members: 4 */
/* padding: 7 */
/* last cacheline: 32 bytes */
};
struct _zend_accel_globals {
/* omitted for simplicity */
zend_string key; /* 400 32 */
char _key[32768]; /* 432 32768 */
/* size: 33200, cachelines: 519, members: 25 */
/* sum members: 33187, holes: 4, sum holes: 13 */
/* last cacheline: 48 bytes */
};
the offset of key
is 400, so its val
starts from 424; whereas the offset of _key
is 432.
There is a padding of 7 bytes between them.
This means that for a pointer p
of type zend_accel_globals
, p->key.val[1]
is not p->_key[0]
.
When these two fields are used together, it will lead to unexpected behaviors.
Although, with a brief search with clang-query
, I did not find any usages of these two fields.
I think this problem is still worth notification.
report-id: 250106-1639:7
PHP Version
latest version
Operating System
Debian 11