You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by md...@apache.org on 2019/04/09 17:13:23 UTC
[incubator-openwhisk-package-kafka] branch master updated: Prevent
parsing floats as Infinity and -Infinity (#332)
This is an automated email from the ASF dual-hosted git repository.
mdeuser pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-package-kafka.git
The following commit(s) were added to refs/heads/master by this push:
new c07976b Prevent parsing floats as Infinity and -Infinity (#332)
c07976b is described below
commit c07976b5201c36f718e5f784ab17b6bb2912fb49
Author: James Dubee <jw...@us.ibm.com>
AuthorDate: Tue Apr 9 13:13:19 2019 -0400
Prevent parsing floats as Infinity and -Infinity (#332)
* Prevent parsing floats as Infinity and -Infinity
* Improve error logging
---
provider/consumer.py | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/provider/consumer.py b/provider/consumer.py
index d4863ce..f5088aa 100644
--- a/provider/consumer.py
+++ b/provider/consumer.py
@@ -485,12 +485,12 @@ class ConsumerProcess (Process):
if self.encodeValueAsJSON:
try:
- parsed = json.loads(value, parse_constant=self.__errorOnJSONConstant)
+ parsed = json.loads(value, parse_constant=self.__errorOnJSONConstant, parse_float=self.__parseFloat)
logging.debug('[{}] Successfully encoded a message as JSON.'.format(self.trigger))
return parsed
- except ValueError:
+ except ValueError as e:
# no big deal, just return the original value
- logging.warn('[{}] I was asked to encode a message as JSON, but I failed.'.format(self.trigger))
+ logging.warn('[{}] I was asked to encode a message as JSON, but I failed with "{}".'.format(self.trigger, e))
value = "\"{}\"".format(value)
pass
elif self.encodeValueAsBase64:
@@ -525,4 +525,15 @@ class ConsumerProcess (Process):
logging.info('[{}] Partition assignment has been revoked. Disconnected from broker(s)'.format(self.trigger))
def __errorOnJSONConstant(self, data):
- raise(ValueError('Invalid JSON detected.'))
+ raise(ValueError('Constant "{}" detected in JSON.'.format(data)))
+
+ def __parseFloat(self, data):
+ res = float(data)
+
+ if res == float('inf'):
+ raise(ValueError('Parsing float value "{}" would result in "Infinity".'.format(data)))
+
+ if res == float('-inf'):
+ raise(ValueError('Parsing float value "{}" would result in "-Infinity".'.format(data)))
+
+ return res