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

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

