UA_unbase64:
   75|     97|UA_unbase64(const unsigned char *src, size_t len, size_t *out_len) {
   76|       |    /* Empty base64 results in an empty byte-string */
   77|     97|    if(len == 0) {
  ------------------
  |  Branch (77:8): [True: 0, False: 97]
  ------------------
   78|      0|        *out_len = 0;
   79|      0|        return (unsigned char*)UA_EMPTY_ARRAY_SENTINEL;
  ------------------
  |  |  755|      0|#define UA_EMPTY_ARRAY_SENTINEL ((void*)0x01)
  ------------------
   80|      0|    }
   81|       |
   82|       |    /* Allocate the output string. Append four bytes to allow missing padding */
   83|     97|    size_t olen = (len / 4 * 3) + 4;
   84|     97|    unsigned char *out = (unsigned char*)UA_malloc(olen);
  ------------------
  |  |   18|     97|#define UA_malloc(size) UA_mallocSingleton(size)
  ------------------
   85|     97|    if(!out)
  ------------------
  |  Branch (85:8): [True: 0, False: 97]
  ------------------
   86|      0|        return NULL;
   87|       |
   88|       |    /* Iterate over the input */
   89|     97|    size_t pad = 0;
   90|     97|    unsigned char count = 0;
   91|     97|    unsigned char block[4];
   92|     97|    unsigned char *pos = out;
   93|  2.46M|    for(size_t i = 0; i < len; i++) {
  ------------------
  |  Branch (93:23): [True: 2.46M, False: 65]
  ------------------
   94|  2.46M|        if(src[i] & 0x80)
  ------------------
  |  Branch (94:12): [True: 17, False: 2.46M]
  ------------------
   95|     17|            goto error; /* Non-ASCII input */
   96|  2.46M|        unsigned char tmp = dtable[src[i]];
   97|  2.46M|        if(tmp == 0x80)
  ------------------
  |  Branch (97:12): [True: 9, False: 2.46M]
  ------------------
   98|      9|            goto error; /* Not an allowed character */
   99|  2.46M|        if(tmp == 0x7f)
  ------------------
  |  Branch (99:12): [True: 281, False: 2.46M]
  ------------------
  100|    281|            continue; /* Whitespace is ignored to accomodate RFC 2045, used in
  101|       |                       * XML for xs:base64Binary. */
  102|  2.46M|        block[count++] = tmp;
  103|       |
  104|       |        /* Padding */
  105|  2.46M|        if(src[i] == '=') {
  ------------------
  |  Branch (105:12): [True: 244, False: 2.46M]
  ------------------
  106|    244|            if(count < 3) /* Padding can only be the last two bytes of a block */
  ------------------
  |  Branch (106:16): [True: 4, False: 240]
  ------------------
  107|      4|                goto error;
  108|    240|            block[count-1] = 0;
  109|    240|            pad++;
  110|  2.46M|        } else if(pad > 0) {
  ------------------
  |  Branch (110:19): [True: 2, False: 2.46M]
  ------------------
  111|      2|            goto error; /* Padding not terminated correctly */
  112|      2|        }
  113|       |
  114|       |        /* Write three output characters for four characters of input */
  115|  2.46M|        if(count == 4) {
  ------------------
  |  Branch (115:12): [True: 616k, False: 1.84M]
  ------------------
  116|   616k|            if(pad > 2)
  ------------------
  |  Branch (116:16): [True: 0, False: 616k]
  ------------------
  117|      0|                goto error; /* Invalid padding */
  118|   616k|            *pos++ = (block[0] << 2) | (block[1] >> 4);
  119|   616k|            *pos++ = (block[1] << 4) | (block[2] >> 2);
  120|   616k|            *pos++ = (block[2] << 6) | block[3];
  121|   616k|            count = 0;
  122|   616k|            pos -= pad;
  123|   616k|            pad = 0;
  124|   616k|        }
  125|  2.46M|    }
  126|       |
  127|       |    /* Input length not a multiple of four */
  128|     65|    if(count > 0)
  ------------------
  |  Branch (128:8): [True: 23, False: 42]
  ------------------
  129|     23|        goto error;
  130|       |
  131|     42|    *out_len = (size_t)(pos - out);
  132|     42|    if(*out_len == 0) {
  ------------------
  |  Branch (132:8): [True: 10, False: 32]
  ------------------
  133|     10|        UA_free(out);
  ------------------
  |  |   19|     10|#define UA_free(ptr) UA_freeSingleton(ptr)
  ------------------
  134|     10|        return (unsigned char*)UA_EMPTY_ARRAY_SENTINEL;
  ------------------
  |  |  755|     10|#define UA_EMPTY_ARRAY_SENTINEL ((void*)0x01)
  ------------------
  135|     10|    }
  136|     32|    return out;
  137|       |
  138|     55| error:
  139|     55|    UA_free(out);
  ------------------
  |  |   19|     55|#define UA_free(ptr) UA_freeSingleton(ptr)
  ------------------
  140|       |    return NULL;
  141|     42|}

LLVMFuzzerTestOneInput:
   18|     97|LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
   19|     97|    size_t retLen;
   20|     97|    unsigned char* ret = UA_unbase64(data, size, &retLen);
   21|     97|    if (retLen > 0)
  ------------------
  |  Branch (21:9): [True: 87, False: 10]
  ------------------
   22|     87|        free(ret);
   23|     97|    return 0;
   24|     97|}

