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

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

