… | |
… | |
27 | # define SvREFCNT_inc_NN(sv) SvREFCNT_inc (sv) |
27 | # define SvREFCNT_inc_NN(sv) SvREFCNT_inc (sv) |
28 | #endif |
28 | #endif |
29 | #ifndef SvREFCNT_dec_NN |
29 | #ifndef SvREFCNT_dec_NN |
30 | # define SvREFCNT_dec_NN(sv) SvREFCNT_dec (sv) |
30 | # define SvREFCNT_dec_NN(sv) SvREFCNT_dec (sv) |
31 | #endif |
31 | #endif |
|
|
32 | |
|
|
33 | // perl's is_utf8_string interprets len=0 as "calculate len", but we want it to mean 0 |
|
|
34 | #define cbor_is_utf8_string(str,len) (!(len) || is_utf8_string ((str), (len))) |
32 | |
35 | |
33 | // known major and minor types |
36 | // known major and minor types |
34 | enum cbor_type |
37 | enum cbor_type |
35 | { |
38 | { |
36 | MAJOR_SHIFT = 5, |
39 | MAJOR_SHIFT = 5, |
… | |
… | |
982 | } |
985 | } |
983 | else if (ecb_expect_true ((U8)(*dec->cur - MAJOR_TEXT) <= LENGTH_EXT8)) |
986 | else if (ecb_expect_true ((U8)(*dec->cur - MAJOR_TEXT) <= LENGTH_EXT8)) |
984 | { |
987 | { |
985 | STRLEN len = decode_uint (dec); |
988 | STRLEN len = decode_uint (dec); |
986 | char *key = (char *)dec->cur; |
989 | char *key = (char *)dec->cur; |
|
|
990 | printf ("len %d\n", len);//D |
987 | |
991 | |
988 | WANT (len); |
992 | WANT (len); |
989 | dec->cur += len; |
993 | dec->cur += len; |
990 | |
994 | |
991 | if (ecb_expect_false (dec->cbor.flags & F_VALIDATE_UTF8)) |
995 | if (ecb_expect_false (dec->cbor.flags & F_VALIDATE_UTF8)) |
992 | if (!is_utf8_string ((U8 *)key, len)) |
996 | if (!cbor_is_utf8_string ((U8 *)key, len)) |
993 | ERR ("corrupted CBOR data (invalid UTF-8 in map key)"); |
997 | ERR ("corrupted CBOR data (invalid UTF-8 in map key)"); |
994 | |
998 | |
995 | hv_store (hv, key, -len, decode_sv (dec), 0); |
999 | hv_store (hv, key, -len, decode_sv (dec), 0); |
996 | |
1000 | |
997 | return; |
1001 | return; |
… | |
… | |
1126 | } |
1130 | } |
1127 | |
1131 | |
1128 | if (utf8) |
1132 | if (utf8) |
1129 | { |
1133 | { |
1130 | if (ecb_expect_false (dec->cbor.flags & F_VALIDATE_UTF8)) |
1134 | if (ecb_expect_false (dec->cbor.flags & F_VALIDATE_UTF8)) |
1131 | if (!is_utf8_string (SvPVX (sv), SvCUR (sv))) |
1135 | if (!cbor_is_utf8_string (SvPVX (sv), SvCUR (sv))) |
1132 | ERR ("corrupted CBOR data (invalid UTF-8 in text string)"); |
1136 | ERR ("corrupted CBOR data (invalid UTF-8 in text string)"); |
1133 | |
1137 | |
1134 | SvUTF8_on (sv); |
1138 | SvUTF8_on (sv); |
1135 | } |
1139 | } |
1136 | |
1140 | |