Skip to content

Commit 062d186

Browse files
committed
Change zend_ast_attr from uint16_t to uint32_t
The zend_ast_attr type was defined as uint16_t, limiting it to 16 bits, but it's used to store ZEND_ACC_* flags which can use bits up to 31: - ZEND_ACC_OVERRIDE = (1 << 28) - ZEND_ACC_ENUM = (1 << 28) - ZEND_ACC_STRICT_TYPES = (1U << 31) While current code doesn't appear to assign these high-bit flags to ast->attr fields, the type mismatch creates a potential bug where any future code attempting to store ZEND_ACC flags with bits 16-31 would have those bits silently truncated to zero. This change: 1. Changes zend_ast_attr typedef from uint16_t to uint32_t 2. Adds explicit uint16_t __pad field to all AST structures after the kind field to maintain the same memory layout (padding was already present implicitly due to alignment) The structure sizes remain unchanged: we're making existing implicit padding explicit and widening the attr field to properly accommodate all ZEND_ACC_* flag values.
1 parent 363dd91 commit 062d186

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Zend/zend_ast.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,11 @@ enum _zend_ast_kind {
183183
};
184184

185185
typedef uint16_t zend_ast_kind;
186-
typedef uint16_t zend_ast_attr;
186+
typedef uint32_t zend_ast_attr;
187187

188188
struct _zend_ast {
189189
zend_ast_kind kind; /* Type of the node (ZEND_AST_* enum constant) */
190+
uint16_t __pad; /* Padding for alignment */
190191
zend_ast_attr attr; /* Additional attribute, use depending on node type */
191192
uint32_t lineno; /* Line number */
192193
zend_ast *child[1]; /* Array of children (using struct hack) */
@@ -195,6 +196,7 @@ struct _zend_ast {
195196
/* Same as zend_ast, but with children count, which is updated dynamically */
196197
typedef struct _zend_ast_list {
197198
zend_ast_kind kind;
199+
uint16_t __pad; /* Padding for alignment */
198200
zend_ast_attr attr;
199201
uint32_t lineno;
200202
uint32_t children;
@@ -204,6 +206,7 @@ typedef struct _zend_ast_list {
204206
/* Lineno is stored in val.u2.lineno */
205207
typedef struct _zend_ast_zval {
206208
zend_ast_kind kind;
209+
uint16_t __pad; /* Padding for alignment */
207210
zend_ast_attr attr;
208211
zval val;
209212
} zend_ast_zval;
@@ -212,6 +215,7 @@ typedef struct _zend_op_array zend_op_array;
212215

213216
typedef struct _zend_ast_op_array {
214217
zend_ast_kind kind;
218+
uint16_t __pad; /* Padding for alignment */
215219
zend_ast_attr attr;
216220
uint32_t lineno;
217221
zend_op_array *op_array;
@@ -220,6 +224,7 @@ typedef struct _zend_ast_op_array {
220224
/* Separate structure for function and class declaration, as they need extra information. */
221225
typedef struct _zend_ast_decl {
222226
zend_ast_kind kind;
227+
uint16_t __pad; /* Padding for alignment */
223228
zend_ast_attr attr;
224229
uint32_t start_lineno;
225230
uint32_t end_lineno;
@@ -231,6 +236,7 @@ typedef struct _zend_ast_decl {
231236

232237
typedef struct _zend_ast_fcc {
233238
zend_ast_kind kind; /* Type of the node (ZEND_AST_* enum constant) */
239+
uint16_t __pad; /* Padding for alignment */
234240
zend_ast_attr attr; /* Additional attribute, use depending on node type */
235241
uint32_t lineno; /* Line number */
236242
ZEND_MAP_PTR_DEF(zend_function *, fptr);

0 commit comments

Comments
 (0)