THRIFT-3827 Fix CompactProtocol readI64 function
This closes #1008 and closes #1052
diff --git a/lib/php/lib/Thrift/Protocol/TCompactProtocol.php b/lib/php/lib/Thrift/Protocol/TCompactProtocol.php
index 2870351..124f6ec 100644
--- a/lib/php/lib/Thrift/Protocol/TCompactProtocol.php
+++ b/lib/php/lib/Thrift/Protocol/TCompactProtocol.php
@@ -615,7 +615,7 @@
if ($shift >= 32) {
$hi |= (($byte & 0x7f) << ($shift - 32));
} elseif ($shift > 25) {
- $hi |= (($byte & 0x7f) >> ($shift - 25));
+ $hi |= (($byte & 0x7f) >> ($shift - 24));
}
if (($byte >> 7) === 0) {
break;
@@ -635,7 +635,7 @@
// Now put $hi and $lo back together
if (true) {
- $isNeg = $hi < 0;
+ $isNeg = $hi < 0 || $hi & 0x80000000;
// Check for a negative
if ($isNeg) {