You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit ca33650
Browse filesBrowse the repository at this point in the historyBrowse files
Reject non-object members when constructing the native compound types
The twins' IntersectionType and UnionType constructors store their
members unchecked, and a member that is not a Type fails at its first
use (an Error, or a TypeError from a Type-typed closure). The native
code dereferenced such a member as an object in nearly every method of
IntersectionType, in several of UnionType and BenevolentUnionType, and
in every port iterating getTypes(), crashing the process. Instead of
checking each of those sites, the native constructors now reject a
non-object member with a TypeError — the invariant the native code
already relies on — which UnionType's constructor gets for free in the
loop it already runs over the members. BenevolentUnionType's
getOffsetValueType() additionally checks the members it gets from a
possibly overridden getTypes() and raises the twin's Error.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Fdg8n3eEi4ZoXa4dA2k4A
for (zv::ArrayEntry entry : zv::ArrRef(typesArg)) {
370
+
zval *type = entry.value().deref().raw();
371
+
if (UNEXPECTED(Z_TYPE_P(type) != IS_OBJECT)) {
372
+
zend_type_error("phpstan_turbo: %s::__construct(): every member must be a %s, %s given", ZSTR_VAL(pt_ce_intersection_type->name), ptcls::type, zend_zval_value_name(type));
Copy file name to clipboardExpand all lines: turbo-ext/src/UnionType.cpp
+9-1Lines changed: 9 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -341,7 +341,15 @@ class UnionType
341
341
}
342
342
for (zv::ArrayEntry entry : zv::ArrRef(typesArg)) {
343
343
zval *type = entry.value().deref().raw();
344
-
if (Z_TYPE_P(type) != IS_OBJECT || !instanceof_function(Z_OBJCE_P(type), pt_ce_union_type)) continue;
344
+
/* a member that is not an object is rejected here: the twin
345
+
* stores it unchecked and fails at its first use, but the
346
+
* native code reading the members — in this family and in
347
+
* every port iterating getTypes() — relies on objects */
348
+
if (UNEXPECTED(Z_TYPE_P(type) != IS_OBJECT)) {
349
+
zend_type_error("phpstan_turbo: %s::__construct(): every member must be a %s, %s given", ZSTR_VAL(pt_ce_union_type->name), ptcls::type, zend_zval_value_name(type));
350
+
returnfalse;
351
+
}
352
+
if (!instanceof_function(Z_OBJCE_P(type), pt_ce_union_type)) continue;
345
353
bool isTemplate;
346
354
if (UNEXPECTED(!isInstance(type, PT_CLASS_TEMPLATE_TYPE, isTemplate))) returnfalse;
0 commit comments