[issue21213] Memory bomb by incorrect custom serializer to json.dumps

2014-04-14 Thread saaj

New submission from saaj:

I was chaning an implementation of the function that is passed to json.dumps to 
extend serializable types. By a mistake (**return** instead of **raise**) it 
turned into, which at its minum can be expressed as::

  def d(obj):
return TypeError(repr(obj))

  json.dumps(1j, default = d) 

After a few moments by laptop froze, though after a minute I could open shell 
in separate session, and top command showed that python interpretter is 
consuming about 4GiB of memory and 50% of 4 logical cores. 

Worst about it it doesn't end with any exception, it just keeps running. 
Without ``repr`` it ends up with somewhat expected ``RuntimeError: maximum 
recursion depth exceeded while getting the str of an object``.

The same behaviour is on python3, where it just consumes memory with less speed.

OS:
Linux Mint 15 Olivia
Linux 3.8.0-31-generic #46-Ubuntu SMP Tue Sep 10 20:03:44 UTC 2013 x86_64

Packages are last available:
python  2.7.4-0ubuntu1
python3 3.3.1-0ubuntu1

P.S. Sorry for confirming on console at python.org.

--
components: Library (Lib)
messages: 216071
nosy: saaj
priority: normal
severity: normal
status: open
title: Memory bomb by incorrect custom serializer to json.dumps
versions: Python 2.7, Python 3.3

___
Python tracker 
<http://bugs.python.org/issue21213>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21213] Memory bomb by incorrect custom serializer to json.dumps

2014-04-26 Thread saaj

saaj added the comment:

Well, as far as I see the question here is whether it makes sense to allow the 
default function to return JSON-incompatible objects.

--

___
Python tracker 
<http://bugs.python.org/issue21213>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21213] Memory bomb by incorrect custom serializer to json.dumps

2014-04-26 Thread saaj

saaj added the comment:

I'll try to be more specific at my point. There're two cases:

  1. Scalar: NoneType, int, bool, float, str. Ended immediately.
  2. Non-scalar: list/tuple, dict. Recursively traversed, which may result in 
subsequent calls to the custom function.

If the return value is restricted to given types (what the encoder is capable 
on its own), it is harder to shoot oneself in the foot. 

In other words what's the point of returning arbitrary Python object from the 
function?

--

___
Python tracker 
<http://bugs.python.org/issue21213>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com