php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63738 unpack: back result with Z format
Submitted: 2012-12-11 13:51 UTC Modified: 2012-12-11 15:28 UTC
From: remi@php.net Assigned: remi
Status: Closed Package: Strings related
PHP Version: 5.5Git-2012-12-11 (snap) OS: GNU/Linux (Fedora 17)
Private report: No CVE-ID:
 [2012-12-11 13:51 UTC] remi@php.net
Description:
------------
Seems a regression between 5.4.9 and 5.5.0-dev

This breaks Archive_Tar


Test script:
---------------
<?php
$a="AB\x00\x00";
var_dump($a);
var_dump(unpack("a4foo", $a));


Expected result:
----------------
With php 5.4.9:

string(4) "AB^@^@"
array(1) {
  ["foo"]=>
  string(2) "AB"
}


Actual result:
--------------
With php 5.5.0-dev:

string(4) "AB^@^@"
array(1) {
  ["foo"]=>
  string(4) "AB^@^@"
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-12-11 13:57 UTC] remi@php.net
-Status: Open +Status: Not a bug
 [2012-12-11 13:57 UTC] remi@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Sorry, haven't read carefully UPGRADING

 - pack()/unpack() had the following changes, which bring it more in line
  with Perl's behavior:
  - Implemented format character "Z": NUL-padded string
  - "a" now does not remove trailing NUL characters on unpack() anymore
  - "A" will now strip all trailing ASCII whitespace on unpack() (it used to
    remove only trailing spaces).
 [2012-12-11 13:57 UTC] aharvey@php.net
-Package: Unknown/Other Function +Package: Strings related
 [2012-12-11 13:57 UTC] aharvey@php.net
This was intentional — specifically, it was to fix bug #61038. Copy-pasting from the migration guide (http://php.net/manual/en/migration55.changed-functions.php):

"unpack()'s a format no longer strips trailing null bytes, bringing it into line with Perl's behaviour."
 [2012-12-11 13:58 UTC] aharvey@php.net
Snap. :)
 [2012-12-11 14:15 UTC] remi@php.net
There still a problem with new 'z' format:

php -r '$a="\x00\x00\x00\x00"; var_dump($a); var_dump(unpack("Z4foo", $a));'

Actual result:
string(4) "^@^@^@^@"
array(1) {
  ["foo"]=>
  string(1) "^@"
}

When we expect:
string(4) "^@^@^@^@"
array(1) {
  ["foo"]=>
  string(0) ""
}
 [2012-12-11 14:15 UTC] remi@php.net
-Status: Not a bug +Status: Open
 [2012-12-11 15:28 UTC] remi@php.net
-Summary: unpack string behavior change +Summary: unpack: back result with Z format -Status: Open +Status: Assigned -Assigned To: +Assigned To: remi
 [2012-12-11 15:34 UTC] remi@php.net
Automatic comment on behalf of remi
Revision: http://git.php.net/?p=php-src.git;a=commit;h=4d8d5d83fce83c32a04cd8d8cf50d909ab101f38
Log: Fixed Bug #63738 unpack: back result with Z format
 [2012-12-11 15:34 UTC] remi@php.net
-Status: Assigned +Status: Closed
 [2012-12-11 15:34 UTC] remi@php.net
Automatic comment on behalf of remi
Revision: http://git.php.net/?p=php-src.git;a=commit;h=4d8d5d83fce83c32a04cd8d8cf50d909ab101f38
Log: Fixed Bug #63738 unpack: back result with Z format
 [2012-12-19 17:54 UTC] derick@php.net
Automatic comment on behalf of remi
Revision: http://git.php.net/?p=php-src.git;a=commit;h=4d8d5d83fce83c32a04cd8d8cf50d909ab101f38
Log: Fixed Bug #63738 unpack: back result with Z format
 [2013-11-17 09:32 UTC] laruence@php.net
Automatic comment on behalf of remi
Revision: http://git.php.net/?p=php-src.git;a=commit;h=4d8d5d83fce83c32a04cd8d8cf50d909ab101f38
Log: Fixed Bug #63738 unpack: back result with Z format
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Fri Apr 18 13:02:15 2014 UTC