rtyler / py-yajl

py-yajl provides Python bindings for the Yajl JSON encoder/decoder library
http://rtyler.github.com/py-yajl
74 stars 18 forks source link

segfault on dumping recursive objects #18

Closed teepark closed 14 years ago

teepark commented 14 years ago

There is no protection against stack-overflowing infinite recursion from self-referential objects.

Simple repro:

l = []
l.append(l)
yajl.dumps(l)

I wrote a test and then realized that a segfaulting python probably won't behave nicely with a hudson setup or your other tests. On the vain hope that there was some crazy black magic in the signal module I tried catching SIGSEGV for the test, but no joy.

It may be too much to ask, passing an incrementing "depth" argument through every ProcessObject call, and that example code is pretty pathological, but I can imagine a recursive relationship legitimately coming up maybe in an instance-caching ORM like SQLAlchemy.

EDIT: oh never mind, yajl already does this, we just have to be looking for status yajl_max_depth_exceeded. expect a pull request soon.

rtyler commented 14 years ago

Interesting bug, I agree that this should not be causing a SIGSEGV. I suppose raising a yajl.RecursionError might be appropriate? simplejson raises:

ValueError: Circular reference detected

teepark commented 14 years ago

pull request is in - just adding the checks I get "TypeError: Object is not JSON serializable", which isn't bad

teepark commented 14 years ago

crap, just realized i have a bunch of other out-of-date stuff on my master branch. feel free to just cherry-pick 0af93f64e461185a09683794e24757bf14683e34

rtyler commented 14 years ago

SHA: e2504262a0f1d5a3bae07c74c637f7260832343b