|
|
|
@ -147,7 +147,6 @@ typedef union { |
|
|
|
|
|
|
|
|
|
static const char *decode_msg(upb_decstate *d, const char *ptr, upb_msg *msg, |
|
|
|
|
const upb_msglayout *layout); |
|
|
|
|
#include <stdlib.h> |
|
|
|
|
|
|
|
|
|
UPB_NORETURN static void decode_err(upb_decstate *d) { longjmp(d->err, 1); } |
|
|
|
|
|
|
|
|
@ -156,38 +155,22 @@ const char *fastdecode_err(upb_decstate *d) { |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void decode_verifyutf8(upb_decstate *d, const char *buf, int len) { |
|
|
|
|
static const uint8_t utf8_offset[] = { |
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|
|
|
|
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
|
|
|
|
2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, |
|
|
|
|
4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
int i, j; |
|
|
|
|
uint8_t offset; |
|
|
|
|
|
|
|
|
|
i = 0; |
|
|
|
|
while (i < len) { |
|
|
|
|
offset = utf8_offset[(uint8_t)buf[i]]; |
|
|
|
|
if (offset == 0 || i + offset > len) { |
|
|
|
|
decode_err(d); |
|
|
|
|
} |
|
|
|
|
for (j = i + 1; j < i + offset; j++) { |
|
|
|
|
if ((buf[j] & 0xc0) != 0x80) { |
|
|
|
|
decode_err(d); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
i += offset; |
|
|
|
|
} |
|
|
|
|
if (i != len) decode_err(d); |
|
|
|
|
const uint8_t upb_utf8_offsets[] = { |
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|
|
|
|
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
|
|
|
|
2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, |
|
|
|
|
4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
static void decode_verifyutf8(upb_decstate *d, const char *buf, int len) { |
|
|
|
|
if (!decode_verifyutf8_inl(buf, len)) decode_err(d); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static bool decode_reserve(upb_decstate *d, upb_array *arr, size_t elem) { |
|
|
|
@ -316,6 +299,7 @@ static const char *decode_readstr(upb_decstate *d, const char *ptr, int size, |
|
|
|
|
return ptr + size; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
UPB_FORCEINLINE |
|
|
|
|
static const char *decode_tosubmsg(upb_decstate *d, const char *ptr, |
|
|
|
|
upb_msg *submsg, const upb_msglayout *layout, |
|
|
|
|
const upb_msglayout_field *field, int size) { |
|
|
|
@ -331,6 +315,7 @@ static const char *decode_tosubmsg(upb_decstate *d, const char *ptr, |
|
|
|
|
return ptr; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
UPB_FORCEINLINE |
|
|
|
|
static const char *decode_group(upb_decstate *d, const char *ptr, |
|
|
|
|
upb_msg *submsg, const upb_msglayout *subl, |
|
|
|
|
uint32_t number) { |
|
|
|
@ -345,6 +330,7 @@ static const char *decode_group(upb_decstate *d, const char *ptr, |
|
|
|
|
return ptr; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
UPB_FORCEINLINE |
|
|
|
|
static const char *decode_togroup(upb_decstate *d, const char *ptr, |
|
|
|
|
upb_msg *submsg, const upb_msglayout *layout, |
|
|
|
|
const upb_msglayout_field *field) { |
|
|
|
|