--- JSON-XS/XS.xs 2008/05/27 05:31:39 1.86 +++ JSON-XS/XS.xs 2008/06/03 06:43:45 1.87 @@ -123,6 +123,7 @@ shrink (SV *sv) { sv_utf8_downgrade (sv, 1); + if (SvLEN (sv) > SvCUR (sv) + 1) { #ifdef SvPV_shrink_to_cur @@ -1415,6 +1416,13 @@ SvGETMAGIC (string); SvUPGRADE (string, SVt_PV); + /* work around a bug in perl 5.10, which causes SvCUR to fail an + * assertion with -DDEBUGGING, although SvCUR is documented to + * return the xpv_cur field which certainly exists after upgrading. + * according to nicholas clark, calling SvPOK fixes this. + */ + SvPOK (string); + if (SvCUR (string) > json->max_size && json->max_size) croak ("attempted decode of JSON text of %lu bytes size, but max_size is set to %lu", (unsigned long)SvCUR (string), (unsigned long)json->max_size);