ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/CBOR-XS/XS.xs
(Generate patch)

Comparing CBOR-XS/XS.xs (file contents):
Revision 1.56 by root, Fri Nov 25 11:33:03 2016 UTC vs.
Revision 1.58 by root, Fri Nov 25 13:27:29 2016 UTC

665 SV *decode_tagged; 665 SV *decode_tagged;
666} dec_t; 666} dec_t;
667 667
668#define ERR(reason) SB if (!dec->err) dec->err = reason; goto fail; SE 668#define ERR(reason) SB if (!dec->err) dec->err = reason; goto fail; SE
669 669
670#define WANT(len) if (ecb_expect_false (dec->cur + len > dec->end)) ERR ("unexpected end of CBOR data") 670#define WANT(len) if (ecb_expect_false ((UV)(dec->end - dec->cur) < (UV)len)) ERR ("unexpected end of CBOR data")
671 671
672#define DEC_INC_DEPTH if (ecb_expect_false (++dec->depth > dec->cbor.max_depth)) ERR (ERR_NESTING_EXCEEDED) 672#define DEC_INC_DEPTH if (ecb_expect_false (++dec->depth > dec->cbor.max_depth)) ERR (ERR_NESTING_EXCEEDED)
673#define DEC_DEC_DEPTH --dec->depth 673#define DEC_DEC_DEPTH --dec->depth
674 674
675static UV 675static UV
754 av_push (av, decode_sv (dec)); 754 av_push (av, decode_sv (dec));
755 } 755 }
756 } 756 }
757 else 757 else
758 { 758 {
759 int i, len = decode_uint (dec); 759 UV i, len = decode_uint (dec);
760 760
761 WANT (len); // complexity check for av_fill - need at least one byte per value, do not allow supersize arrays 761 WANT (len); // complexity check for av_fill - need at least one byte per value, do not allow supersize arrays
762 av_fill (av, len - 1); 762 av_fill (av, len - 1);
763 763
764 for (i = 0; i < len; ++i) 764 for (i = 0; i < len; ++i)
844 decode_he (dec, hv); 844 decode_he (dec, hv);
845 } 845 }
846 } 846 }
847 else 847 else
848 { 848 {
849 int pairs = decode_uint (dec); 849 UV pairs = decode_uint (dec);
850
851 WANT (pairs); // complexity check - need at least one byte per value, do not allow supersize hashes
850 852
851 while (pairs--) 853 while (pairs--)
852 decode_he (dec, hv); 854 decode_he (dec, hv);
853 } 855 }
854 856
1064 } 1066 }
1065 break; 1067 break;
1066 1068
1067 default: 1069 default:
1068 { 1070 {
1071 SV *tag_sv = newSVuv (tag);
1072
1069 sv = decode_sv (dec); 1073 sv = decode_sv (dec);
1070 1074
1071 dSP; 1075 dSP;
1072 ENTER; SAVETMPS; 1076 ENTER; SAVETMPS;
1073 SAVESTACK_POS (); 1077 SAVESTACK_POS ();
1074 PUSHMARK (SP); 1078 PUSHMARK (SP);
1075 EXTEND (SP, 2); 1079 EXTEND (SP, 2);
1076 PUSHs (newSVuv (tag)); 1080 PUSHs (tag_sv);
1077 PUSHs (sv); 1081 PUSHs (sv);
1078 1082
1079 PUTBACK; 1083 PUTBACK;
1080 int count = call_sv (dec->cbor.filter ? dec->cbor.filter : default_filter, G_ARRAY | G_EVAL); 1084 int count = call_sv (dec->cbor.filter ? dec->cbor.filter : default_filter, G_ARRAY | G_EVAL);
1081 SPAGAIN; 1085 SPAGAIN;
1082 1086
1083 if (SvTRUE (ERRSV)) 1087 if (SvTRUE (ERRSV))
1084 { 1088 {
1089 SvREFCNT_dec (tag_sv);
1085 FREETMPS; LEAVE; 1090 FREETMPS; LEAVE;
1086 ERR (SvPVutf8_nolen (sv_2mortal (SvREFCNT_inc (ERRSV)))); 1091 ERR (SvPVutf8_nolen (sv_2mortal (SvREFCNT_inc (ERRSV))));
1087 } 1092 }
1088 1093
1089 if (count) 1094 if (count)
1090 { 1095 {
1096 SvREFCNT_dec (tag_sv);
1091 SvREFCNT_dec (sv); 1097 SvREFCNT_dec (sv);
1092 sv = SvREFCNT_inc (POPs); 1098 sv = SvREFCNT_inc (POPs);
1093 } 1099 }
1094 else 1100 else
1095 { 1101 {
1096 AV *av = newAV (); 1102 AV *av = newAV ();
1097 av_push (av, newSVuv (tag)); 1103 av_push (av, tag_sv);
1098 av_push (av, sv); 1104 av_push (av, sv);
1099 1105
1100 HV *tagged_stash = !CBOR_SLOW || cbor_tagged_stash 1106 HV *tagged_stash = !CBOR_SLOW || cbor_tagged_stash
1101 ? cbor_tagged_stash 1107 ? cbor_tagged_stash
1102 : gv_stashpv ("CBOR::XS::Tagged" , 1); 1108 : gv_stashpv ("CBOR::XS::Tagged" , 1);
1231 1237
1232 if (dec.err) 1238 if (dec.err)
1233 { 1239 {
1234 if (dec.shareable) 1240 if (dec.shareable)
1235 { 1241 {
1236 // need to break cyclic links, which whould all be in shareable 1242 // need to break cyclic links, which would all be in shareable
1237 int i; 1243 int i;
1238 SV **svp; 1244 SV **svp;
1239 1245
1240 for (i = av_len (dec.shareable) + 1; i--; ) 1246 for (i = av_len (dec.shareable) + 1; i--; )
1241 if ((svp = av_fetch (dec.shareable, i, 0))) 1247 if ((svp = av_fetch (dec.shareable, i, 0)))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines