| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#include <aws/common/encoding.h> |
| 7 |
|
| 8 |
|
| 9 |
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
| 10 |
|
| 11 |
struct aws_allocator *allocator = aws_default_allocator(); |
| 12 |
|
| 13 |
size_t output_size = 0; |
| 14 |
int result = aws_hex_compute_encoded_len(size, &output_size); |
| 15 |
AWS_ASSERT(result == AWS_OP_SUCCESS); |
| 16 |
|
| 17 |
struct aws_byte_cursor to_encode = aws_byte_cursor_from_array(data, size); |
| 18 |
|
| 19 |
struct aws_byte_buf encode_output; |
| 20 |
result = aws_byte_buf_init(&encode_output, allocator, output_size); |
| 21 |
AWS_ASSERT(result == AWS_OP_SUCCESS); |
| 22 |
|
| 23 |
result = aws_hex_encode(&to_encode, &encode_output); |
| 24 |
AWS_ASSERT(result == AWS_OP_SUCCESS); |
| 25 |
|
| 26 |
result = aws_hex_compute_decoded_len(encode_output.len, &output_size); |
| 27 |
AWS_ASSERT(result == AWS_OP_SUCCESS); |
| 28 |
AWS_ASSERT(output_size == size); |
| 29 |
|
| 30 |
struct aws_byte_buf decode_output; |
| 31 |
result = aws_byte_buf_init(&decode_output, allocator, output_size); |
| 32 |
AWS_ASSERT(result == AWS_OP_SUCCESS); |
| 33 |
|
| 34 |
struct aws_byte_cursor decode_input = aws_byte_cursor_from_buf(&encode_output); |
| 35 |
result = aws_hex_decode(&decode_input, &decode_output); |
| 36 |
AWS_ASSERT(result == AWS_OP_SUCCESS); |
| 37 |
AWS_ASSERT(output_size == decode_output.len); |
| 38 |
AWS_ASSERT(memcmp(decode_output.buffer, data, size) == 0); |
| 39 |
|
| 40 |
aws_byte_buf_clean_up(&encode_output); |
| 41 |
aws_byte_buf_clean_up(&decode_output); |
| 42 |
|
| 43 |
return 0; |
| 44 |
} |