Commit Graph

509 Commits

Author SHA1 Message Date
Dmitry Stogov
6c5942f835 serialize() optimization 2021-02-26 13:30:19 +03:00
Dmitry Stogov
0f6c00200b Speed up __sleep() and __wakeup() calls 2021-02-25 12:16:22 +03:00
Nikita Popov
3e01f5afb1 Replace zend_bool uses with bool
We're starting to see a mix between uses of zend_bool and bool.
Replace all usages with the standard bool type everywhere.

Of course, zend_bool is retained as an alias.
2021-01-15 12:33:06 +01:00
Nikita Popov
e2c8ab7c33 Print "interned" instead of fake refcount in debug_zval_dump()
debug_zval_dump() currently prints refcount 1 for interned strings
and arrays, which does not really reflect the truth. These values
are not refcounted, so the refcount is misleading. Instead print
an "interned" tag.

Closes GH-6598.
2021-01-15 12:21:24 +01:00
Nikita Popov
422d1665a2 Make convert_to_*_ex simple aliases of convert_to_*
Historically, the _ex variants separated the zval first, if a
conversion was necessary. This distinction no longer makes sense
since PHP 7.

The only difference that was still left is that _ex checked whether
the type is the same first, but the usage of these macros did not
actually distinguish on whether such an inlined check is valuable
or not in a given context.

Also drop the unused convert_to_explicit_type macros.
2021-01-14 12:11:11 +01:00
Nikita Popov
26fc4bea44 Remove some INDIRECT handling in standard library 2021-01-06 12:46:31 +01:00
Tyson Andre
0d99628ac1 Fix edge case serializing __PHP_Incomplete_Class properties.
This was using strcmp instead of zend_string_equals_literal.
As a result, the property count didn't match the number of properties
being serialized if properties started with
"__PHP_Incomplete_Class\0" (unlikely)

(before, `'O:8:"Missing_":1:{}'` would be serialized, which failed to
unserialize)

Everywhere else expects the MAGIC_MEMBER to match exactly,
and this should use zend_string_equals_literal as an example for other code.

This has used strcmp since 2004 in deb84befae

Closes GH-6555
2021-01-04 09:46:54 -05:00
Nikita Popov
217f247bb5 Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fixed bug #80411
2020-11-25 17:24:49 +01:00
Nikita Popov
2fb12be84c Fixed bug #80411
References to null-serializations are stored as null, and as such
are part of the reference count.

Reminds me that we really need to deprecate the mess that is
Serializable.
2020-11-25 17:23:42 +01:00
Máté Kocsis
c37a1cd650
Promote a few remaining errors in ext/standard
Closes GH-6110
2020-09-15 14:26:16 +02:00
Tyson Andre
0c238ede01 [RFC] Only unserialize Phar metadata when getMetadata() is called
In other words, don't automatically unserialize when the magic
phar:// stream wrappers are used.
RFC: https://wiki.php.net/rfc/phar_stop_autoloading_metadata

Also, change the signature from `getMetadata()`
to `getMetadata(array $unserialize_options = [])`.
Start throwing earlier if setMetadata() is called and serialization threw.

See https://externals.io/message/110856 and
https://bugs.php.net/bug.php?id=76774

This was refactored to add a phar_metadata_tracker for the following reasons:
- The way to properly copy a zval was previously implicit and undocumented
  (e.g. is it a pointer to a raw string or an actual value)
- Avoid unnecessary serialization and unserialization in the most common case
- If a metadata value is serialized once while saving a new/modified phar file,
  this allows reusing the same serialized string.
- Have as few ways to copy/clone/lazily parse metadata (etc.) as possible,
  so that code changes can be limited to only a few places in the future.
- Performance is hopefully not a concern - copying a string should be faster
  than unserializing a value, and metadata should be rare in most cases.

Remove unnecessary skip in a test(Compression's unused)

Add additional assertions about usage of persistent phars

Improve robustness of `Phar*->setMetadata()`

- Add sanity checks for edge cases freeing metadata, when destructors
  or serializers modify the phar recursively.
- Typical use cases of php have phar.readonly=1 and would not be affected.

Closes GH-5855
2020-08-03 13:28:51 -04:00
twosee
6e92487f66 Fix warnings of strict-prototypes
Closes GH-5887.
2020-07-23 00:59:00 +08:00
twosee
c0172aa2bd debug_zval_dump(): Don't skip recursion detection on first level
A complement to ae6f45ad45

Closes GH-5843.
2020-07-12 03:08:42 +08:00
twosee
614b2191bd Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed BC break of php_debug_zval_dump
2020-07-11 18:32:18 +08:00
twosee
7a39e174aa Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fixed BC break of php_debug_zval_dump
2020-07-11 18:31:30 +08:00
twosee
f0b2c2cb98 Fixed BC break of php_debug_zval_dump
It introduced by fixing bug #79830
2020-07-11 18:30:28 +08:00
twosee
40efb7ad61 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #79830 introduced by fixing bug #79821

# Conflicts:
#	ext/standard/var.c
2020-07-11 14:40:17 +08:00
twosee
6ef08b1903 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fixed bug #79830 introduced by fixing bug #79821
2020-07-11 14:38:27 +08:00
twosee
56dec3cc73 Fixed bug #79830 introduced by fixing bug #79821
This also fixes memory error in debug_zval_dump and var_export.
2020-07-11 14:37:25 +08:00
twosee
342fe094b5 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #79821
2020-07-11 06:19:41 +08:00
twosee
8db2ae8ffb Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fixed bug #79821
2020-07-11 06:15:28 +08:00
twosee
150504e6b1 Fixed bug #79821
HashTable was reallocated (zend_hash_packed_grow) during php_var_dump, so we should call GC_ADDREF to make SEPARATE_ARRAY work.

Closes GH-5837.
2020-07-11 06:14:22 +08:00
Máté Kocsis
d30cd7d7e7
Review the usage of apostrophes in error messages
Closes GH-5590
2020-07-10 21:05:28 +02:00
Max Semenik
2b5de6f839
Remove proto comments from C files
Closes GH-5758
2020-07-06 21:13:34 +02:00
Nikita Popov
1314ccbf8c Cache __unserialize() instead of unserialize()
We should use these cache slots for the new object serialization
mechanism rather than the old one.
2020-06-26 10:54:40 +02:00
Nikita Popov
15846ff115 Add ZVAL_OBJ_COPY macro
For the common ZVAL_OBJ + GC_ADDREF pattern.
This mirrors the existing ZVAL_STR_COPY API.
2020-06-17 16:36:56 +02:00
Máté Kocsis
4a816584a4
Make float to string casts locale-independent
From now on, float to string casting will always behave locale-independently.
RFC: https://wiki.php.net/rfc/locale_independent_float_to_string
Closes GH-5224

Co-authored-by: George Peter Banyard <girgias@php.net>
2020-05-08 10:52:23 +02:00
Xinchen Hui
d906eb23f6 Fixed bug #79526 (__sleep error message doesn't include the name of the class) 2020-04-28 14:17:21 +08:00
Nikita Popov
baabb5398f Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix bug #79447
2020-04-23 10:31:07 +02:00
Nicolas Grekas
73d02c3b3e Fix bug #79447
Partially reverts 846b647953: instead of
throwing, this skips uninitialized typed properties when serializing objects.

This makes serialize with __sleep() behave the same as serialize()
without __sleep().

As in the non-__sleep() case, unserialize(serialize($x)) identity
may not be preserved due to replacement of uninitialized/unset
properties with default values. Fixing this will require changes to
the serialization format.

Closes GH-5396.
2020-04-23 10:30:33 +02:00
Nicolas Grekas
657f756ccd Skip non-existing properties returned by __sleep() 2020-04-22 16:41:04 +02:00
Máté Kocsis
1f48feebb9
Improve some TypeError and ValueError messages
Closes GH-5377
2020-04-14 14:38:45 +02:00
Nikita Popov
a939805641 Use serialize_precision for var_dump()
var_dump() is debugging functionality, so it should print
floating-point numbers accurately. We do this by switching
to serialize_precision, which (by default) will print with
as much precision as necessary to preserve the exact value
of the float.

This also affects debug_zval_dump().

Closes GH-5172.
2020-02-25 09:51:32 +01:00
Nikita Popov
ae6f45ad45 var_dump(): Don't skip recursion detection on first level
This is confusing. The current output doesn't make it clear that
we're in fact recursing to the top-level structure.

Closes GH-5171.
2020-02-12 11:25:50 +01:00
Nikita Popov
58b17906f5 Apply tidy formatting
Mostly reindent PHP scripts to spaces.
2020-02-03 13:41:31 +01:00
Nikita Popov
b22daa3a06 Merge branch 'PHP-7.4'
* PHP-7.4:
  Throw Error when referencing uninit typed prop in __sleep
2020-01-06 18:47:44 +01:00
Nikita Popov
846b647953 Throw Error when referencing uninit typed prop in __sleep
Previously this generated a notice, but would likely generate an
Error when unserializing.

Now we treat it with the same distinction as direct property
accesses, i.e. referencing an unset/undefined normal property
stays a notice, while a typed property becomes an Error exception.

This fixed bug #79002.

Closes GH-5050.
2020-01-06 18:47:27 +01:00
Máté Kocsis
aadd3aaed9
Use RETURN_THROWS() in various places 2020-01-03 21:10:24 +01:00
Nikita Popov
0d35f8e3f2 Merge branch 'PHP-7.4'
* PHP-7.4:
  Populate hashtable of __sleep() properties
  Deref names returned by __sleep()
  Extract php_var_serialize_nested_data() function
2020-01-02 11:14:16 +01:00
Nikita Popov
90fea67546 Populate hashtable of __sleep() properties
Instead of populating a hashtable of property names and then
directly serializing.

This has the advantage of a) detecting duplicate properties more
precisely and b) gives us the ability to discard values without
rewriting the serialization string after the fact for GH-5027.
2020-01-02 11:14:01 +01:00
Nikita Popov
de0ca4734e Deref names returned by __sleep() 2020-01-02 11:14:00 +01:00
Nikita Popov
701e8c66d1 Extract php_var_serialize_nested_data() function
And split code-paths for arrays and objects based on it.
2020-01-02 11:14:00 +01:00
George Peter Banyard
4782e8e28a Return empty string instead of NULL in serialize().
Modifiy its return type accordingly and arginfo.
2019-12-12 00:01:28 +01:00
Máté Kocsis
3b0a1905dd
Promote warning to exception in unserialize() 2019-12-11 18:47:59 +01:00
Christoph M. Becker
0e20220cfc Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix #77638: var_export'ing certain class instances segfaults
2019-11-25 15:58:45 +01:00
Christoph M. Becker
717730ddd1 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix #77638: var_export'ing certain class instances segfaults
2019-11-25 15:57:56 +01:00
Christoph M. Becker
23c65a8173 Fix #77638: var_export'ing certain class instances segfaults
If objects return immutable property hash tables (typically,
`zend_empty_array`), we must not try to apply recursion protection on
those.
2019-11-25 15:54:11 +01:00
Nikita Popov
647b1c7fcf Remove most uses of ZEND_PARSE_PARAMETERS_END_EX()
As ZPP now throws, it makes no sense to specify an explicit return
value.
2019-10-07 10:02:18 +02:00
Nikita Popov
1cde9e8528 Merge branch 'PHP-7.4' 2019-09-30 10:30:20 +02:00
Nikita Popov
1806ce9cb0 Add max_depth option to unserialize()
Add a max_depth option to unserialize and an unserialize_max_depth
ini setting, which can be used to control the depth limit. The
default value is 4096.

This option is intended to prevent stack overflows during the
unserialization of deeply nested structures.

This fixes bug #78549 and addresses oss-fuzz #17581, #17589, #17664,
and #17788.
2019-09-30 10:28:24 +02:00