Skip Menu |

This queue is for tickets about the JSON CPAN distribution.

Report information
The Basics
Id: 29988
Status: resolved
Priority: 0/
Queue: JSON

People
Owner: Nobody in particular
Requestors: ted [...] zigzagworld.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



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
fixxed by JSON 1.15 (JSON::PP 0.97). Show quoted text
>(A side point: $max_depth defaults to 32, but the default in JSON::XS
is Show quoted text
>512. Should they not be the >same if JSON::PP is supposed to be compatible with JSON::XS?)
It is for avoiding to raise a warning 'Deep recursion on subroutin'. But the default was changed into 512 in this version. Thanks!