Procházet zdrojové kódy

Throwing exception when overlong integer (> PHP_INT_MAX) is passed. ZF-3310

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@17753 44c647ce-9c0f-0410-b52a-842ac1e357ba
lars před 16 roky
rodič
revize
f674c2e699

+ 5 - 0
library/Zend/XmlRpc/Value/Integer.php

@@ -44,6 +44,11 @@ class Zend_XmlRpc_Value_Integer extends Zend_XmlRpc_Value_Scalar
      */
     public function __construct($value)
     {
+        if ($value > PHP_INT_MAX) {
+            require_once 'Zend/XmlRpc/Value/Exception.php';
+            throw new Zend_XmlRpc_Value_Exception('Overlong integer given');
+        }
+
         $this->_type = self::XMLRPC_TYPE_INTEGER;
         $this->_value = (int)$value;    // Make sure this value is integer
     }

+ 19 - 1
tests/Zend/XmlRpc/ValueTest.php

@@ -113,7 +113,7 @@ class Zend_XmlRpc_ValueTest extends PHPUnit_Framework_TestCase
         $native = 1;
         $types = array(Zend_XmlRpc_Value::XMLRPC_TYPE_I4,
                        Zend_XmlRpc_Value::XMLRPC_TYPE_INTEGER);
-        
+
         foreach ($types as $type) {
             $val = Zend_XmlRpc_Value::getXmlRpcValue($native, $type);
             $this->assertXmlRpcType('integer', $val);
@@ -139,6 +139,24 @@ class Zend_XmlRpc_ValueTest extends PHPUnit_Framework_TestCase
         }
     }
 
+    /**
+     * @group ZF-3310
+     */
+    public function testMarshalI4FromOverlongNativeThrowsException()
+    {
+        $this->setExpectedException('Zend_XmlRpc_Value_Exception', 'Overlong integer given');
+        Zend_XmlRpc_Value::getXmlRpcValue(PHP_INT_MAX + 1, Zend_XmlRpc_Value::XMLRPC_TYPE_I4);
+    }
+
+    /**
+     * @group ZF-3310
+     */
+    public function testMarshalIntegerFromOverlongNativeThrowsException()
+    {
+        $this->setExpectedException('Zend_XmlRpc_Value_Exception', 'Overlong integer given');
+        Zend_XmlRpc_Value::getXmlRpcValue(PHP_INT_MAX + 1, Zend_XmlRpc_Value::XMLRPC_TYPE_INTEGER);
+    }
+
     // Double
 
     public function testFactoryAutodetectsFloat()