cvs: php-src /ext/standard pack.c /ext/standard/tests/strings bug35817.phpt
| From: | Ilia Alshanetsky | Date: | Wed, 28 Dec 2005 20:56:22 +0000 |
| Subject: | cvs: php-src /ext/standard pack.c /ext/standard/tests/strings bug35817.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-36280@lists.php.net to get a copy of this message | ||
iliaa Wed Dec 28 20:56:22 2005 EDT
Modified files:
/php-src/ext/standard pack.c
/php-src/ext/standard/tests/strings bug35817.phpt
Log:
MFB51: Fixed bug #35817 (unpack() does not decode odd number of hexadecimal
values)
http://cvs.php.net/viewcvs.cgi/php-src/ext/standard/pack.c?r1=1.58&r2=1.59&diff_format=u
Index: php-src/ext/standard/pack.c
diff -u php-src/ext/standard/pack.c:1.58 php-src/ext/standard/pack.c:1.59
--- php-src/ext/standard/pack.c:1.58 Thu Dec 15 22:14:25 2005
+++ php-src/ext/standard/pack.c Wed Dec 28 20:56:22 2005
@@ -15,7 +15,7 @@
| Author: Chris Schneider <cschneid@relog.ch> |
+----------------------------------------------------------------------+
*/
-/* $Id: pack.c,v 1.58 2005/12/15 22:14:25 tony2001 Exp $ */
+/* $Id: pack.c,v 1.59 2005/12/28 20:56:22 iliaa Exp $ */
#include "php.h"
@@ -245,7 +245,7 @@
switch ((int) code) {
case 'h':
case 'H':
- INC_OUTPUTPOS((arg + 1) / 2,1) /* 4 bit per arg */
+ INC_OUTPUTPOS((arg + (arg % 2)) / 2,1) /* 4 bit per arg */
break;
case 'a':
@@ -538,7 +538,7 @@
while (formatlen-- > 0) {
char type = *(format++);
char c;
- int arg = 1;
+ int arg = 1, argb;
char *name;
int namelen;
int size=0;
@@ -563,6 +563,7 @@
/* Get of new value in array */
name = format;
+ argb = arg;
while (formatlen > 0 && *format != '/') {
formatlen--;
@@ -592,7 +593,7 @@
case 'h':
case 'H':
- size = (arg > 0) ? arg / 2 : arg;
+ size = (arg > 0) ? (arg + (arg % 2)) / 2 : arg;
arg = 1;
break;
@@ -691,6 +692,8 @@
len = size * 2;
}
+ len -= argb % 2;
+
buf = emalloc(len + 1);
for (ipos = opos = 0; opos < len; opos++) {
http://cvs.php.net/viewcvs.cgi/php-src/ext/standard/tests/strings/bug35817.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/standard/tests/strings/bug35817.phpt
diff -u /dev/null php-src/ext/standard/tests/strings/bug35817.phpt:1.2
--- /dev/null Wed Dec 28 20:56:22 2005
+++ php-src/ext/standard/tests/strings/bug35817.phpt Wed Dec 28 20:56:22 2005
@@ -0,0 +1,29 @@
+--TEST--
+Bug #35817 (unpack() does not decode odd number of hexadecimal values)
+--FILE--
+<?php
+$a = pack("H3","181");
+$b = unpack("H3", $a);
+var_dump($b);
+
+$a = pack("H2","18");
+$b = unpack("H2", $a);
+var_dump($b);
+
+$a = pack("H","1");
+$b = unpack("H", $a);
+var_dump($b);
+?>
+--EXPECT--
+array(1) {
+ [1]=>
+ string(3) "181"
+}
+array(1) {
+ [1]=>
+ string(2) "18"
+}
+array(1) {
+ [1]=>
+ string(1) "1"
+}