diff
1358     uint8_t *dptr = dest;
+        size_t remaining_space = dest_size;
1359     uint8_t b64[B64_BLOCK] = { 0,0,0,0 };

// ... (in the loop)
1397             uint32_t numDecoded_blk = ASCII_BLOCK - (padding < B64_BLOCK ? padding : ASCII_BLOCK);
-1398             if (dest_size < *decoded_bytes + numDecoded_blk) {
+1398             if (remaining_space < numDecoded_blk) {
1399                 SCLogDebug("Destination buffer full");
1400                 ecode = BASE64_ECODE_BUF;
1401                 break;
1402             }
1405             DecodeBase64Block(dptr, b64);
+                remaining_space -= numDecoded_blk;
+                dptr += numDecoded_blk;
