hi Sara!

Please add a note to UPGRADING as well.

Thanks!
--
Cheers,

On Fri, May 17, 2013 at 12:18 AM, Sara Golemon <poll...@php.net> wrote:
> Commit:    cfd104582220d578ab1b78a5991065d038e1f931
> Author:    Sara Golemon <poll...@php.net>         Thu, 16 May 2013 14:37:36 
> -0700
> Parents:   bc656cde0453aa6de50812ba9edfc6f74c61ce37
> Branches:  master
>
> Link:       
> http://git.php.net/?p=php-src.git;a=commitdiff;h=cfd104582220d578ab1b78a5991065d038e1f931
>
> Log:
> Add optional second arg to unserialize()
>
> Returns the number of bytes consumed by reference for
> streaming unserialization.
>
> Actual unserialization behavior is not modified at all.
>
> The need for this came up while trying to parse SplDoublyLinkedList's
> serialization format which uses a non-standard stream of serialized values.
>
> Changed paths:
>   M  ext/standard/basic_functions.c
>   M  ext/standard/tests/serialize/serialization_error_001.phpt
>   A  ext/standard/tests/serialize/unserialize_consumed.phpt
>   M  ext/standard/var.c
>
>
> Diff:
> diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c
> index 9c91404..1379117 100644
> --- a/ext/standard/basic_functions.c
> +++ b/ext/standard/basic_functions.c
> @@ -2679,6 +2679,7 @@ ZEND_END_ARG_INFO()
>
>  ZEND_BEGIN_ARG_INFO(arginfo_unserialize, 0)
>         ZEND_ARG_INFO(0, variable_representation)
> +       ZEND_ARG_INFO(1, consumed)
>  ZEND_END_ARG_INFO()
>
>  ZEND_BEGIN_ARG_INFO_EX(arginfo_memory_get_usage, 0, 0, 0)
> diff --git a/ext/standard/tests/serialize/serialization_error_001.phpt 
> b/ext/standard/tests/serialize/serialization_error_001.phpt
> index da6f50c..c6c1751 100644
> --- a/ext/standard/tests/serialize/serialization_error_001.phpt
> +++ b/ext/standard/tests/serialize/serialization_error_001.phpt
> @@ -21,7 +21,7 @@ var_dump( unserialize() );
>
>  //Test serialize with one more than the expected number of arguments
>  var_dump( serialize(1,2) );
> -var_dump( unserialize(1,2) );
> +var_dump( unserialize(1,$x,2) );
>
>  echo "Done";
>  ?>
> @@ -31,12 +31,12 @@ echo "Done";
>  Warning: serialize() expects exactly 1 parameter, 0 given in %s on line 16
>  NULL
>
> -Warning: unserialize() expects exactly 1 parameter, 0 given in %s on line 17
> +Warning: unserialize() expects at least 1 parameter, 0 given in %s on line 17
>  bool(false)
>
>  Warning: serialize() expects exactly 1 parameter, 2 given in %s on line 20
>  NULL
>
> -Warning: unserialize() expects exactly 1 parameter, 2 given in %s on line 21
> +Warning: unserialize() expects at most 2 parameters, 3 given in %s on line 21
>  bool(false)
>  Done
> diff --git a/ext/standard/tests/serialize/unserialize_consumed.phpt 
> b/ext/standard/tests/serialize/unserialize_consumed.phpt
> new file mode 100644
> index 0000000..6cc11e2
> --- /dev/null
> +++ b/ext/standard/tests/serialize/unserialize_consumed.phpt
> @@ -0,0 +1,27 @@
> +--TEST--
> +Unserialization of partial strings
> +--FILE--
> +<?php
> +$data = [123,4.56,true];
> +$ser = serialize($data);
> +$serlen = strlen($ser);
> +
> +$unser = unserialize($ser, $consumed);
> +echo "Consume full string: ";
> +var_dump($serlen == $consumed);
> +echo "Return original data: ";
> +var_dump($unser === $data);
> +
> +$ser .= "junk\x01data";
> +$unser = unserialize($ser, $consumed);
> +echo "Consume full string(junk): ";
> +var_dump($serlen == $consumed);
> +echo "Return original data(junk): ";
> +var_dump($unser === $data);
> +
> +--EXPECT--
> +Consume full string: bool(true)
> +Return original data: bool(true)
> +Consume full string(junk): bool(true)
> +Return original data(junk): bool(true)
> +
> diff --git a/ext/standard/var.c b/ext/standard/var.c
> index f76a14c..4acc6f5 100644
> --- a/ext/standard/var.c
> +++ b/ext/standard/var.c
> @@ -945,7 +945,7 @@ PHP_FUNCTION(serialize)
>  }
>  /* }}} */
>
> -/* {{{ proto mixed unserialize(string variable_representation)
> +/* {{{ proto mixed unserialize(string variable_representation[, int 
> &consumed])
>     Takes a string representation of variable and recreates it */
>  PHP_FUNCTION(unserialize)
>  {
> @@ -953,8 +953,9 @@ PHP_FUNCTION(unserialize)
>         int buf_len;
>         const unsigned char *p;
>         php_unserialize_data_t var_hash;
> +       zval *consumed = NULL;
>
> -       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &buf, 
> &buf_len) == FAILURE) {
> +       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|z", &buf, 
> &buf_len, &consumed) == FAILURE) {
>                 RETURN_FALSE;
>         }
>
> @@ -973,6 +974,11 @@ PHP_FUNCTION(unserialize)
>                 RETURN_FALSE;
>         }
>         PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
> +
> +       if (consumed) {
> +               zval_dtor(consumed);
> +               ZVAL_LONG(consumed, ((char*)p) - buf);
> +       }
>  }
>  /* }}} */
>
>
> --
> PHP CVS Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>



-- 
Pierre

@pierrejoye | http://blog.thepimp.net | http://www.libgd.org

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to