Subject: | JSON::PP recursion depth bug |
Date: | Sun, 14 Oct 2007 14:11:48 -0400 |
To: | <bug-JSON [...] rt.cpan.org> |
From: | "Ted Hopp" <ted [...] zigzagworld.com> |
Distribution: JSON-1.14 (JSON::PP module version 0.96)
Perl version: 5.6.1 (but will happen in any version of Perl)
Operating system: Linux
The recursion depth limit is incremented at every call to hashToJson or
arrayToJson (while encoding)
and at every call to object or array (while decoding), but is never
decremented. The result is that
encoding or decoding a large number of arrays or objects (a long array of
them, for instance) will
trigger a recursion limit error ("json structure too deep (hit recursion
limit)") even if the depth of the
structure is very shallow. The solution appears to be to decrement $depth
just before returning a
value from any of the above routines. Here is a diff between the
distribution source and a modified
version that fixes the problem:
285a286
Show quoted text
> --$depth;
311a313
Show quoted text> --$depth;
712a715
Show quoted text> --$depth;
730a734
Show quoted text> --$depth;
879a884
Show quoted text> --$depth;
892a898
Show quoted text> --$depth;
(A side point: $max_depth defaults to 32, but the default in JSON::XS is
512. Should they not be the
same if JSON::PP is supposed to be compatible with JSON::XS?)
Ted Hopp