summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDwayne Boone <dwayne@zeroc.com>2015-03-04 12:42:00 -0330
committerDwayne Boone <dwayne@zeroc.com>2015-03-04 12:42:00 -0330
commit17eecd44fddb363b81a404ea510eb58375a37a38 (patch)
treeacaf6d3a4fbb7e31a7ff93d926afc5e45e3823d1
parentFixed LD_LIBRARY_PATH settings in gradle plug-in (diff)
downloadice-17eecd44fddb363b81a404ea510eb58375a37a38.tar.bz2
ice-17eecd44fddb363b81a404ea510eb58375a37a38.tar.xz
ice-17eecd44fddb363b81a404ea510eb58375a37a38.zip
ICE-6306 Added float range checks to php/rb/py
-rw-r--r--php/src/IcePHP/Types.cpp5
-rw-r--r--php/test/Ice/operations/Client.php23
-rw-r--r--py/modules/IcePy/Types.cpp32
-rw-r--r--py/test/Ice/operations/Twoways.py19
-rw-r--r--rb/src/IceRuby/Types.cpp7
-rw-r--r--rb/test/Ice/operations/Twoways.rb19
6 files changed, 99 insertions, 6 deletions
diff --git a/php/src/IcePHP/Types.cpp b/php/src/IcePHP/Types.cpp
index af27c7d7c5c..080d00caddd 100644
--- a/php/src/IcePHP/Types.cpp
+++ b/php/src/IcePHP/Types.cpp
@@ -754,6 +754,11 @@ IcePHP::PrimitiveInfo::validate(zval* zv TSRMLS_DC)
invalidArgument("expected float value but received %s" TSRMLS_CC, s.c_str());
return false;
}
+ if(Z_TYPE_P(zv) == IS_DOUBLE)
+ {
+ double val = val = Z_DVAL_P(zv);
+ return val <= numeric_limits<float>::max() && val >= -numeric_limits<float>::max();
+ }
break;
}
case PrimitiveInfo::KindDouble:
diff --git a/php/test/Ice/operations/Client.php b/php/test/Ice/operations/Client.php
index 85e4fa5bf7f..f5579a24a37 100644
--- a/php/test/Ice/operations/Client.php
+++ b/php/test/Ice/operations/Client.php
@@ -182,6 +182,27 @@ function twoways($communicator, $p)
catch(InvalidArgumentException $ex)
{
}
+
+ $r = $p->opFloatDouble(3.402823466E38, 0.0, $f, $d);
+ $r = $p->opFloatDouble(-3.402823466E38, 0.0, $f, $d);
+
+ try
+ {
+ $r = $p->opFloatDouble(3.402823466E38*2, 0.0, $f, $d);
+ test(false);
+ }
+ catch(InvalidArgumentException $ex)
+ {
+ }
+
+ try
+ {
+ $r = $p->opFloatDouble(-3.402823466E38*2, 0.0, $f, $d);
+ test(false);
+ }
+ catch(InvalidArgumentException $ex)
+ {
+ }
}
{
@@ -898,7 +919,7 @@ function twoways($communicator, $p)
{
$p->opNonmutating();
}
-
+
test($p->opByte1(0xFF) == 0xFF);
test($p->opShort1(0x7FFF) == 0x7FFF);
test($p->opInt1(0x7FFFFFFF) == 0x7FFFFFFF);
diff --git a/py/modules/IcePy/Types.cpp b/py/modules/IcePy/Types.cpp
index 6042c9d1567..ed737247264 100644
--- a/py/modules/IcePy/Types.cpp
+++ b/py/modules/IcePy/Types.cpp
@@ -21,6 +21,7 @@
#include <Ice/SlicedData.h>
#include <list>
+#include <limits>
using namespace std;
using namespace IcePy;
@@ -689,6 +690,37 @@ IcePy::PrimitiveInfo::validate(PyObject* p)
break;
}
case PrimitiveInfo::KindFloat:
+ {
+ if(!PyFloat_Check(p))
+ {
+ if(PyLong_Check(p))
+ {
+ PyLong_AsDouble(p); // Just to see if it raises an error.
+ if(PyErr_Occurred())
+ {
+ return false;
+ }
+ }
+#if PY_VERSION_HEX < 0x03000000
+ else if(PyInt_Check(p))
+ {
+ return true;
+ }
+#endif
+ else
+ {
+ return false;
+ }
+ }
+ else
+ {
+ // Ensure double does not exceed maximum float value before casting
+ double val = PyFloat_AsDouble(p);
+ return val <= numeric_limits<float>::max() && val >= -numeric_limits<float>::max();
+ }
+
+ break;
+ }
case PrimitiveInfo::KindDouble:
{
if(!PyFloat_Check(p))
diff --git a/py/test/Ice/operations/Twoways.py b/py/test/Ice/operations/Twoways.py
index c91376a2f6f..1299a375d7a 100644
--- a/py/test/Ice/operations/Twoways.py
+++ b/py/test/Ice/operations/Twoways.py
@@ -138,6 +138,21 @@ def twoways(communicator, p):
except ValueError:
pass
+ r, f, d = p.opFloatDouble(3.402823466E38, 0.0)
+ r, f, d = p.opFloatDouble(-3.402823466E38, 0.0)
+
+ try:
+ r, f, d = p.opFloatDouble(3.402823466E38*2, 0.0)
+ test(False)
+ except ValueError:
+ pass
+
+ try:
+ r, f, d = p.opFloatDouble(-3.402823466E38*2, 0.0)
+ test(False)
+ except ValueError:
+ pass
+
#
# opString
#
@@ -1287,7 +1302,7 @@ def twoways(communicator, p):
# opNonmutating
#
p.opNonmutating()
-
+
test(p.opByte1(0xFF) == 0xFF)
test(p.opShort1(0x7FFF) == 0x7FFF)
test(p.opInt1(0x7FFFFFFF) == 0x7FFFFFFF)
@@ -1299,7 +1314,7 @@ def twoways(communicator, p):
test(len(p.opByteBoolD1(None)) == 0)
test(len(p.opStringS2(None)) == 0)
test(len(p.opByteBoolD2(None)) == 0)
-
+
d = Test.MyDerivedClassPrx.uncheckedCast(p)
s = Test.MyStruct1()
s.tesT = "Test.MyStruct1.s"
diff --git a/rb/src/IceRuby/Types.cpp b/rb/src/IceRuby/Types.cpp
index 6615bd5a9d4..d72410d14ff 100644
--- a/rb/src/IceRuby/Types.cpp
+++ b/rb/src/IceRuby/Types.cpp
@@ -594,7 +594,12 @@ IceRuby::PrimitiveInfo::marshal(VALUE p, const Ice::OutputStreamPtr& os, ObjectM
throw RubyException(rb_eTypeError, "unable to convert value to a float");
}
assert(TYPE(val) == T_FLOAT);
- os->write(static_cast<float>(RFLOAT_VALUE(val)));
+ double d = static_cast<double>(RFLOAT_VALUE(val));
+ if(d > numeric_limits<float>::max() || d < -numeric_limits<float>::max())
+ {
+ throw RubyException(rb_eTypeError, "value is out of range for a float");
+ }
+ os->write(static_cast<float>(d));
break;
}
case PrimitiveInfo::KindDouble:
diff --git a/rb/test/Ice/operations/Twoways.rb b/rb/test/Ice/operations/Twoways.rb
index f2120730d1d..c11a4955fd5 100644
--- a/rb/test/Ice/operations/Twoways.rb
+++ b/rb/test/Ice/operations/Twoways.rb
@@ -132,6 +132,21 @@ def twoways(communicator, p)
rescue TypeError
end
+ r, f, d = p.opFloatDouble(3.402823466E38, 0.0)
+ r, f, d = p.opFloatDouble(-3.402823466E38, 0.0)
+
+ begin
+ r, f, d = p.opFloatDouble(3.402823466E38*2, 0.0)
+ test(false)
+ rescue TypeError
+ end
+
+ begin
+ r, f, d = p.opFloatDouble(-3.402823466E38*2, 0.0)
+ test(false)
+ rescue TypeError
+ end
+
#
# opString
#
@@ -1067,7 +1082,7 @@ def twoways(communicator, p)
# opNonmutating
#
p.opNonmutating
-
+
test(p.opByte1(0xFF) == 0xFF)
test(p.opShort1(0x7FFF) == 0x7FFF)
test(p.opInt1(0x7FFFFFFF) == 0x7FFFFFFF)
@@ -1079,7 +1094,7 @@ def twoways(communicator, p)
test(p.opByteBoolD1(nil).length == 0)
test(p.opStringS2(nil).length == 0)
test(p.opByteBoolD2(nil).length == 0)
-
+
d = Test::MyDerivedClassPrx::uncheckedCast(p)
s = Test::MyStruct1.new
s.tesT = "Test.MyStruct1.s"