From f3590cce7da78c7713e46e2cf5c15c85cc64b1f0 Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Thu, 26 Jan 2006 15:47:31 +0000 Subject: [PATCH] MFH: Fixed bug #36148 (unpack("H*hex", $data) is adding an extra character to the end of the string). --- NEWS | 2 ++ ext/standard/pack.c | 4 +++- ext/standard/tests/strings/bug36148.phpt | 29 ++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 ext/standard/tests/strings/bug36148.phpt diff --git a/NEWS b/NEWS index fe5d34adf9..8f8c450e14 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,8 @@ PHP 4 NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? 2006, Version 4.4.3 - Added a check for special characters in the session name. (Ilia) +- Fixed bug #36148 (unpack("H*hex", $data) is adding an extra character to the + end of the string). (Ilia) - Fixed bug #36017 (fopen() crashes PHP when opening a URL). (Tony) 13 Jan 2006, Version 4.4.2 diff --git a/ext/standard/pack.c b/ext/standard/pack.c index fd9b1d23bc..33a8e82fd6 100644 --- a/ext/standard/pack.c +++ b/ext/standard/pack.c @@ -693,7 +693,9 @@ PHP_FUNCTION(unpack) len = size * 2; } - len -= argb % 2; + if (argb > 0) { + len -= argb % 2; + } buf = emalloc(len + 1); diff --git a/ext/standard/tests/strings/bug36148.phpt b/ext/standard/tests/strings/bug36148.phpt new file mode 100644 index 0000000000..06caac3334 --- /dev/null +++ b/ext/standard/tests/strings/bug36148.phpt @@ -0,0 +1,29 @@ +--TEST-- +Bug #36148 (unpack("H*hex", $data) is adding an extra character to the end of the string) +--FILE-- + +--EXPECT-- +a: array(1) { + [1]=> + string(2) "a0" +} +aa: array(1) { + [1]=> + string(2) "aa" +} +aaa: array(1) { + [1]=> + string(4) "aaa0" +} +aaaa: array(1) { + [1]=> + string(4) "aaaa" +} -- 2.50.1