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

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

