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
I noticed a segfault in our Phalcon application which occurs after a call to Phalcon\Mvc\Model::toArray() on a model that doesn't have getters for all of its properties.
class MyModel extends Model
{
protected$col1;
protected$col2;
protected$col3;
protected$col4;
publicfunctioninitialize(): void
{
$this->setSource('my_model');
}
publicfunctiongetCol1()
{
return$this->col1;
}
}
$item = newMyModel([
'col1' => 'test',
'col2' => 'test',
'col3' => 'test',
'col4' => 'test'
]);
$item->toArray(); // segfault happens at some point after this call// the actual code here is not important, we just need some// memory allocationsfor($i = 0; $i < 10; $i++) {
$item->toArray();
}
Expected behavior
The application doesn't segfault.
if method_exists(this, method) {
let data[attributeField] =this->{method}();
} elseiffetch value, this->{attributeField} {
let data[attributeField] = value;
} else {
let data[attributeField] =null;
}
Changing the above code to:
if method_exists(this, method) {
let data[attributeField] =this->{method}();
} elseiffetch value, this->{attributeField} {
let data[attributeField] = value;
} else {
let data[attributeField] =null;
}
let value =null;
Hello everyone,
I noticed a segfault in our Phalcon application which occurs after a call to Phalcon\Mvc\Model::toArray() on a model that doesn't have getters for all of its properties.
Steps to reproduce the behavior:
Expected behavior
The application doesn't segfault.
Details
Additional context
The problem seems to be located in this if statement (https://github.com/phalcon/cphalcon/blob/master/phalcon/Mvc/Model.zep#L3324C1-L3330C14):
Changing the above code to:
fixes the problem.
From looking at the produced C code my guess is that the call to ZEPHIR_OBS_NVAR(&value) introduced by the fetch is causing issues when used in a loop:
(https://github.com/phalcon/cphalcon/blob/master/ext/phalcon/mvc/model.zep.c#L5652C1)
Hope this helps.
The text was updated successfully, but these errors were encountered: