Files
palladum-lightning/tests/fuzz/fuzz-base32-64.c
Chandra Pratap e721b0a89a fuzz-tests: Enhance b64_encode() validation with roundtrip decoding
Changelog-None: Currently, fuzz testing for b64_encode() merely
encodes input and frees the result, providing no real verification
of its behavior.

Introduce a new b64_decode() function (modeled after b32_decode())
and update the fuzz test to perform a roundtrip—encoding followed
by decoding—to ensure that b64_encode() correctly preserves the
original data.
2025-07-08 12:54:56 +09:30

29 lines
610 B
C

#include "config.h"
#include <assert.h>
#include <common/base32.h>
#include <common/base64.h>
#include <tests/fuzz/libfuzz.h>
void init(int *argc, char ***argv)
{
}
void run(const uint8_t *data, size_t size)
{
char *encoded;
uint8_t *decoded;
encoded = b32_encode(NULL, data, size);
decoded = b32_decode(NULL, encoded, strlen(encoded));
assert(memcmp(decoded, data, size) == 0);
tal_free(encoded);
tal_free(decoded);
encoded = b64_encode(NULL, data, size);
decoded = b64_decode(NULL, encoded, strlen(encoded));
assert(memcmp(decoded, data, size) == 0);
tal_free(encoded);
tal_free(decoded);
}