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

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

