[thrift] [PATCH] Thrift PHP Library bug on PHP version 5
Kazuki Ohta
kazuki.ohta at gmail.com
Sun Mar 16 00:43:49 PDT 2008
Hi, Thrift Developers.
I found a bug of Thrift php library on PHP version 5.
Please look at the different behavior of the following program on PHP4
and PHP5.
pficore% cat hoge.php
<?php
$v1 = 132;
$d = pack("N", $v1);
$v2 = unpack("N", $d);
print_r($v2);
$unpacked = unpack('nhigh/nlow', $d);
$v2 = ($unpacked['high'] << 16) + $unpacked['low'];
print_r($v2)
?>
* PHP v5.2.1
pficore% php --version
PHP 5.2.1 (cli) (built: Nov 28 2007 23:22:01)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
pficore% php hoge.php
Array
(
[1] => -2147483516
)
132
* PHP v4.3.9
[web at pfiweb1 ~]$ php --version
PHP 4.3.9 (cgi) (built: May 10 2007 05:09:26)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies
[web at pfiweb1 ~]$ php hoge.php
Array
(
[1] => 132
)
132
Due to this problem, TBinaryProtocol::readI32() doesn't work well
on PHP5. This is a crutial problem!
Following patch fixes this problem.
I hope that this patch is merged and new version is released :-)
pficore% diff -ur thrift-20070917-orig thrift-20070917
diff -ur thrift-20070917-orig/lib/php/src/protocol/TBinaryProtocol.php
thrift-20070917/lib/php/src/protocol/TBinaryProtocol.php
--- thrift-20070917-orig/lib/php/src/protocol/TBinaryProtocol.php
2007-09-20 06:23:02.000000000 +0900
+++ thrift-20070917/lib/php/src/protocol/TBinaryProtocol.php
2008-03-16 16:31:44.000000000 +0900
@@ -289,8 +289,8 @@
public function readI32(&$value) {
$data = $this->trans_->readAll(4);
- $arr = unpack('N', $data);
- $value = $arr[1];
+ $unpacked = unpack('nhigh/nlow', $data);
+ $value = ($unpacked['high'] << 16) + $unpacked['low'];
if ($value > 0x7fffffff) {
$value = 0 - (($value - 1) ^ 0xffffffff);
}
--
=============================================
Kazuki Ohta <kzk at il.is.s.u-tokyo.ac.jp>
Ishikawa Laboratory, Department of Information Science,
The University of Tokyo.
http://kzk9.net/
=============================================
More information about the thrift
mailing list