fix #77298 segfault occurs when add property to unserialized empty ArrayObject#3711
fix #77298 segfault occurs when add property to unserialized empty ArrayObject#3711jhdxr wants to merge 3 commits intophp:PHP-7.3from
Conversation
|
As you said, it would be better to handle this during unserialize. I would use the following pattern: This will take ownership of the unserialized array, and prevent anyone else from acquiring a reference to it through malicious unserialize input using r/R. |
|
@nikic why |
|
@jhdxr Using ZVAL_COPY + SEPARATE_ARRAY would work, but would always lead to an array copy, because the refcount will always be > 1 after the COPY. Using COPY_VALUE + NULLing the original value transfers ownership to you, so if nobody else was using it, no copy will have to be performed. |
|
@nikic my point is the original value in this case is is it a good idea to do |
|
@jhdxr ZVAL_NULL will not modify the array, it will only modify the place storing the array (a slot in the serialization backreference table). |
|
@nikic got it. thanks! |
|
Thanks! Applied as b15189f. |
9cf87aa brings
zend_empty_array, whose gc.refcount is 2, when unserialize a string representing empty array ("a:0:{}"), and leads toHT_ASSERT_RC1failure.to be honest I don't think it's a good fix, since
spl_array_get_hash_tableis very common used inArrayObject, andSEPARATE_ARRAYwill check gc_refcount everytime, the overhead may defeat the benfit of usingzend_empty_array. Another possible solution is we can doSEPARATE_ARRAYinArrayObject::unserialize, which defeats the purpose ofzend_empty_arrayas well.