* \param dest The destination byte buffer
* \param src The source string
* \param len The length of the source string
+ * \param strict If set file on invalid byte, otherwise return what has been
+ * decoded.
*
* \return Number of bytes decoded, or 0 if no data is decoded or it fails
*/
-uint32_t DecodeBase64(uint8_t *dest, const uint8_t *src, uint32_t len) {
+uint32_t DecodeBase64(uint8_t *dest, const uint8_t *src, uint32_t len,
+ int strict) {
int val;
uint32_t padding = 0, numDecoded = 0, bbidx = 0, valid = 1, i;
/* Invalid character found, so decoding fails */
if (src[i] != '=') {
valid = 0;
- numDecoded = 0;
+ if (strict) {
+ numDecoded = 0;
+ }
break;
}
padding++;
#define B64_BLOCK 4
/* Function prototypes */
-uint32_t DecodeBase64(uint8_t *dest, const uint8_t *src, uint32_t len);
+uint32_t DecodeBase64(uint8_t *dest, const uint8_t *src, uint32_t len,
+ int strict);
#endif
/* Only decode if divisible by 4 */
if (state->bvr_len == B64_BLOCK || force) {
remdec = DecodeBase64(state->data_chunk + state->data_chunk_len,
- state->bvremain, state->bvr_len);
+ state->bvremain, state->bvr_len, 1);
if (remdec > 0) {
/* Track decoded length */
SCLogDebug("Decoding: %u", len - rem1 - rem2);
numDecoded = DecodeBase64(state->data_chunk + state->data_chunk_len,
- buf + offset, tobuf);
+ buf + offset, tobuf, 1);
if (numDecoded > 0) {
/* Track decoded length */
if (dst == NULL)
return 0;
- ret = DecodeBase64(dst, (const uint8_t *)base64msg, strlen(base64msg));
+ ret = DecodeBase64(dst, (const uint8_t *)base64msg, strlen(base64msg), 1);
if (memcmp(dst, msg, strlen(msg)) == 0) {
ret = 0;