Skip to content

Commit

Permalink
implemented decoding indefinite array
Browse files Browse the repository at this point in the history
  • Loading branch information
Nishchay Agrawal committed Feb 12, 2020
1 parent 3a672f7 commit ee699c6
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions tests/fuzz/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ void _parse_cbor(nanocbor_value_t *it, unsigned indent)
{
while (!nanocbor_at_end(it)) {
_indent(indent);
if(*it->cur == 0xFF && *(it->cur+1) == 0x00){
// printf("in end\n");
break;
}
//printf("Parsing: %x and end: %x.\n",*it->cur, *(it->cur+1));
int res = _parse_type(it, indent);
//printf(" res found : %d\n",res);
printf(",\n");
if (res < 0) {
printf("Err\n");
Expand Down Expand Up @@ -57,9 +63,19 @@ void _parse_map(nanocbor_value_t *it, unsigned indent)
}
}

bool _is_array_indefinite(nanocbor_value_t *value)
{
// printf("Cur value: %x, indefinite: %x, and: %x\n",*value->cur, NANOCBOR_SIZE_INDEFINITE,(*value->cur)& NANOCBOR_SIZE_INDEFINITE);
if(((*value->cur)& NANOCBOR_SIZE_INDEFINITE) == 0x1f){
return true;
}
return false;
}

static int _parse_type(nanocbor_value_t *value, unsigned indent)
{
uint8_t type = nanocbor_get_type(value);
//printf("Type for this is : %d\n",type);
if (indent > 10) {
return -2;
}
Expand Down Expand Up @@ -118,17 +134,32 @@ static int _parse_type(nanocbor_value_t *value, unsigned indent)
break;
case NANOCBOR_TYPE_ARR:
{
//printf("Found this is an array\n");
nanocbor_value_t arr;
if (nanocbor_enter_array(value, &arr) >= 0) {
if(_is_array_indefinite(value)){
printf("Indefinite array.\n");
printf("[\n");
// arr.cur=value->cur+1;
value->cur++;
// arr.end=value->end;

_parse_cbor(value,indent +1);
// _indent(indent-1);
printf("]");
break;
}
else if(nanocbor_enter_array(value, &arr) >= 0) {
//printf("Arr: %d\n",*arr.cur);
printf("[\n");
_parse_cbor(&arr, indent + 1);
nanocbor_leave_container(value, &arr);
_indent(indent);
printf("]");
}
else {
}
else {
// printf("Returning\n");
return -1;
}
}
}
break;
case NANOCBOR_TYPE_MAP:
Expand Down

0 comments on commit ee699c6

Please sign in to comment.