]> granicus.if.org Git - php/commitdiff
Fixed bug #30045 (Cannot pass big integers (> 2147483647) in SOAP requests)
authorDmitry Stogov <dmitry@php.net>
Tue, 14 Sep 2004 12:13:39 +0000 (12:13 +0000)
committerDmitry Stogov <dmitry@php.net>
Tue, 14 Sep 2004 12:13:39 +0000 (12:13 +0000)
NEWS
ext/soap/php_encoding.c
ext/soap/tests/bugs/bug30045.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 7e83b05d5a2d5dca47b6c968667f8cfae5beec63..9acc9dfbd46922966d21235cdbc6bf6afd23baa3 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,8 @@ PHP                                                                        NEWS
 - Renamed SoapClient->__call() to SoapClinet->__soapCall(). (Dmitry)
 - Fixed bug with raw_post_data not getting set (Brian)
 - Fixed a file-descriptor leak with phpinfo() and other 'special' URLs (Zeev)
+- Fixed bug #30045 (Cannot pass big integers (> 2147483647) in SOAP requests).
+  (Dmitry)
 - Fixed bug #29985 (unserialize()/ __PHP_Incomplete_class does not report 
   correctly class name). (Marcus, Tony)
 - Fixed bug #29945 (simplexml_load_file URL limitation 255 char). (Rob)
index 72f6c73c8a0ea8bbf2fc7b0a03adba56a27f6568..5be092d660c228ceac7e553bf9317ea5e58bcdf8 100644 (file)
@@ -27,7 +27,6 @@
 /* zval type decode */
 static zval *to_zval_double(encodeTypePtr type, xmlNodePtr data);
 static zval *to_zval_long(encodeTypePtr type, xmlNodePtr data);
-static zval *to_zval_ulong(encodeTypePtr type, xmlNodePtr data);
 static zval *to_zval_bool(encodeTypePtr type, xmlNodePtr data);
 static zval *to_zval_string(encodeTypePtr type, xmlNodePtr data);
 static zval *to_zval_stringr(encodeTypePtr type, xmlNodePtr data);
@@ -37,7 +36,6 @@ static zval *to_zval_map(encodeTypePtr type, xmlNodePtr data);
 static zval *to_zval_null(encodeTypePtr type, xmlNodePtr data);
 
 static xmlNodePtr to_xml_long(encodeTypePtr type, zval *data, int style, xmlNodePtr parent);
-static xmlNodePtr to_xml_ulong(encodeTypePtr type, zval *data, int style, xmlNodePtr parent);
 static xmlNodePtr to_xml_double(encodeTypePtr type, zval *data, int style, xmlNodePtr parent);
 static xmlNodePtr to_xml_bool(encodeTypePtr type, zval *data, int style, xmlNodePtr parent);
 
@@ -161,7 +159,8 @@ encode defaultEncoding[] = {
        {{XSD_UNSIGNEDBYTE, XSD_UNSIGNEDBYTE_STRING, XSD_NAMESPACE, NULL}, to_zval_long, to_xml_long},
        {{XSD_UNSIGNEDSHORT, XSD_UNSIGNEDSHORT_STRING, XSD_NAMESPACE, NULL}, to_zval_long, to_xml_long},
        {{XSD_UNSIGNEDINT, XSD_UNSIGNEDINT_STRING, XSD_NAMESPACE, NULL}, to_zval_long, to_xml_long},
-       {{XSD_UNSIGNEDLONG, XSD_UNSIGNEDLONG_STRING, XSD_NAMESPACE, NULL}, to_zval_ulong, to_xml_ulong},
+       {{XSD_UNSIGNEDLONG, XSD_UNSIGNEDLONG_STRING, XSD_NAMESPACE, NULL}, to_zval_long, to_xml_long},
+       {{XSD_INTEGER, XSD_INTEGER_STRING, XSD_NAMESPACE, NULL}, to_zval_long, to_xml_long},
 
        {{XSD_ANYTYPE, XSD_ANYTYPE_STRING, XSD_NAMESPACE, NULL}, guess_zval_convert, guess_xml_convert},
        {{XSD_UR_TYPE, XSD_UR_TYPE_STRING, XSD_NAMESPACE, NULL}, guess_zval_convert, guess_xml_convert},
@@ -681,25 +680,6 @@ static zval *to_zval_long(encodeTypePtr type, xmlNodePtr data)
        MAKE_STD_ZVAL(ret);
        FIND_XML_NULL(data, ret);
 
-       if (data && data->children) {
-               if (data->children->type == XML_TEXT_NODE && data->children->next == NULL) {
-                       whiteSpace_collapse(data->children->content);
-                       ZVAL_LONG(ret, atol(data->children->content));
-               } else {
-                       soap_error0(E_ERROR, "Encoding: Violation of encoding rules");
-               }
-       } else {
-               ZVAL_NULL(ret);
-       }
-       return ret;
-}
-
-static zval *to_zval_ulong(encodeTypePtr type, xmlNodePtr data)
-{
-       zval *ret;
-       MAKE_STD_ZVAL(ret);
-       FIND_XML_NULL(data, ret);
-
        if (data && data->children) {
                if (data->children->type == XML_TEXT_NODE && data->children->next == NULL) {
                        whiteSpace_collapse(data->children->content);
@@ -721,30 +701,6 @@ static zval *to_zval_ulong(encodeTypePtr type, xmlNodePtr data)
 }
 
 static xmlNodePtr to_xml_long(encodeTypePtr type, zval *data, int style, xmlNodePtr parent)
-{
-       xmlNodePtr ret;
-       zval tmp;
-
-       ret = xmlNewNode(NULL,"BOGUS");
-       xmlAddChild(parent, ret);
-       FIND_ZVAL_NULL(data, ret, style);
-
-       tmp = *data;
-       zval_copy_ctor(&tmp);
-       if (Z_TYPE(tmp) != IS_LONG) {
-               convert_to_long(&tmp);
-       }
-       convert_to_string(&tmp);
-       xmlNodeSetContentLen(ret, Z_STRVAL(tmp), Z_STRLEN(tmp));
-       zval_dtor(&tmp);
-
-       if (style == SOAP_ENCODED) {
-               set_ns_and_type(ret, type);
-       }
-       return ret;
-}
-
-static xmlNodePtr to_xml_ulong(encodeTypePtr type, zval *data, int style, xmlNodePtr parent)
 {
        xmlNodePtr ret;
 
@@ -753,8 +709,9 @@ static xmlNodePtr to_xml_ulong(encodeTypePtr type, zval *data, int style, xmlNod
        FIND_ZVAL_NULL(data, ret, style);
 
        if (Z_TYPE_P(data) == IS_DOUBLE) {
-               char s[16];
-               sprintf(s, "%0.0f",Z_DVAL_P(data));
+               char s[256];
+
+               sprintf(s, "%0.0f",floor(Z_DVAL_P(data)));
                xmlNodeSetContent(ret, s);
        } else {
                zval tmp = *data;
diff --git a/ext/soap/tests/bugs/bug30045.phpt b/ext/soap/tests/bugs/bug30045.phpt
new file mode 100644 (file)
index 0000000..fa9c68c
--- /dev/null
@@ -0,0 +1,171 @@
+--TEST--
+Bug #29844 (SOAP doesn't return the result of a valid SOAP request)
+--SKIPIF--
+<?php 
+  if (!extension_loaded('soap')) die('skip soap extension not available');
+  if (!extension_loaded('simplexml')) die('skip simplexml extension not available');
+?>
+--FILE--
+<?php
+
+function foo($type, $num) {
+  return new SoapVar($num, $type);
+}
+
+class LocalSoapClient extends SoapClient {
+
+  function __construct($wsdl, $options) {
+    parent::__construct($wsdl, $options);
+    $this->server = new SoapServer($wsdl, $options);
+    $this->server->addFunction('foo');
+  }
+
+  function __doRequest($request, $location, $action, $version) {
+    $xml = simplexml_load_string($request);
+    echo $xml->children("http://schemas.xmlsoap.org/soap/envelope/")->Body->children("http://test-uri")->children()->param1->asXML(),"\n";
+    unset($xml);
+
+    ob_start();
+    $this->server->handle($request);
+    $response = ob_get_contents();
+    ob_end_clean();
+
+    return $response;
+  }
+
+}
+
+$soap = new LocalSoapClient(NULL, array("uri"=>"http://test-uri", "location"=>"test://"));
+
+function test($type, $num) {
+  global $soap;
+  try {
+         printf("  %0.0f\n    ", $num);        
+         $ret = $soap->foo($type, new SoapVar($num, $type));
+         printf("    %0.0f\n", $num, $ret);
+       } catch (SoapFault $ex) {
+         var_dump($ex);
+       }
+}
+/*
+echo "byte\n";
+//test(XSD_BYTE, -129);
+test(XSD_BYTE, -128);
+test(XSD_BYTE,  127);
+//test(XSD_BYTE,  128);
+
+echo "\nshort\n";
+//test(XSD_SHORT, -32769);
+test(XSD_SHORT, -32768);
+test(XSD_SHORT,  32767);
+//test(XSD_SHORT,  32768);
+
+echo "\nint\n";
+//test(XSD_INT, -2147483649);
+test(XSD_INT, -2147483648);
+test(XSD_INT,  2147483647);
+//test(XSD_INT,  2147483648);
+
+echo "\nlong\n";
+//test(XSD_LONG, -9223372036854775809);
+test(XSD_LONG, -9223372036854775808);
+test(XSD_LONG,  9223372036854775807);
+//test(XSD_LONG,  9223372036854775808);
+
+echo "\nunsignedByte\n";
+//test(XSD_UNSIGNEDBYTE, -1);
+test(XSD_UNSIGNEDBYTE,  0);
+test(XSD_UNSIGNEDBYTE,  255);
+//test(XSD_UNSIGNEDBYTE,  256);
+
+echo "\nunsignedShort\n";
+//test(XSD_UNSIGNEDSHORT, -1);
+test(XSD_UNSIGNEDSHORT,  0);
+test(XSD_UNSIGNEDSHORT,  65535);
+//test(XSD_UNSIGNEDSHORT,  65536);
+
+echo "\nunsignedInt\n";
+//test(XSD_UNSIGNEDINT, -1);
+test(XSD_UNSIGNEDINT,  0);
+test(XSD_UNSIGNEDINT,  4294967295);
+//test(XSD_UNSIGNEDINT,  4294967296);
+
+echo "\nunsignedLong\n";
+//test(XSD_UNSIGNEDLONG, -1);
+test(XSD_UNSIGNEDLONG,  0);
+test(XSD_UNSIGNEDLONG,  18446744073709551615);
+//test(XSD_UNSIGNEDLONG,  18446744073709551616);
+
+echo "\nnegativeInteger\n";
+test(XSD_NEGATIVEINTEGER, -18446744073709551616);
+test(XSD_NEGATIVEINTEGER, -1);
+//test(XSD_NEGATIVEINTEGER,  0);
+
+echo "\nnonPositiveInteger\n";
+test(XSD_NONPOSITIVEINTEGER, -18446744073709551616);
+test(XSD_NONPOSITIVEINTEGER,  0);
+//test(XSD_NONPOSITIVEINTEGER,  1);
+
+echo "\nnonNegativeInteger\n";
+//test(XSD_NONNEGATIVEINTEGER, -1);
+test(XSD_NONNEGATIVEINTEGER,  0);
+test(XSD_NONNEGATIVEINTEGER,  18446744073709551616);
+
+echo "\nPositiveInteger\n";
+//test(XSD_POSITIVEINTEGER,  0);
+test(XSD_POSITIVEINTEGER,  1);
+test(XSD_POSITIVEINTEGER,  18446744073709551616);
+
+echo "\ninteger\n";
+test(XSD_INTEGER, -18446744073709551616);
+test(XSD_INTEGER,  18446744073709551616);
+*/
+echo "long\n";
+test(XSD_LONG, 2147483647);
+test(XSD_LONG, 2147483648);
+test(XSD_LONG,  4294967296);
+test(XSD_LONG,  8589934592);
+test(XSD_LONG, 17179869184); 
+
+echo "\nunsignedLong\n";
+test(XSD_UNSIGNEDLONG,  2147483647);
+test(XSD_UNSIGNEDLONG,  2147483648);
+test(XSD_UNSIGNEDLONG,  4294967296);
+test(XSD_UNSIGNEDLONG,  8589934592);
+test(XSD_UNSIGNEDLONG, 17179869184);
+
+?>
+--EXPECT--
+long
+  2147483647
+    <param1 xsi:type="xsd:long">2147483647</param1>
+    2147483647
+  2147483648
+    <param1 xsi:type="xsd:long">2147483648</param1>
+    2147483648
+  4294967296
+    <param1 xsi:type="xsd:long">4294967296</param1>
+    4294967296
+  8589934592
+    <param1 xsi:type="xsd:long">8589934592</param1>
+    8589934592
+  17179869184
+    <param1 xsi:type="xsd:long">17179869184</param1>
+    17179869184
+
+unsignedLong
+  2147483647
+    <param1 xsi:type="xsd:unsignedLong">2147483647</param1>
+    2147483647
+  2147483648
+    <param1 xsi:type="xsd:unsignedLong">2147483648</param1>
+    2147483648
+  4294967296
+    <param1 xsi:type="xsd:unsignedLong">4294967296</param1>
+    4294967296
+  8589934592
+    <param1 xsi:type="xsd:unsignedLong">8589934592</param1>
+    8589934592
+  17179869184
+    <param1 xsi:type="xsd:unsignedLong">17179869184</param1>
+    17179869184