Line data Source code
1 : #include "../fd_util.h" 2 : #include "fd_textstream.h" 3 : 4 : #include <stdlib.h> 5 : #include <stdint.h> 6 : 7 : #define PART_RAW_SZ (720UL) 8 : #define PART_BLK_SZ (4UL*(PART_RAW_SZ+2UL)/3UL) 9 : 10 : int 11 : LLVMFuzzerInitialize( int *argc, 12 12 : char ***argv ) { 13 12 : putenv( "FD_LOG_BACKTRACE=0" ); 14 12 : fd_boot( argc, argv ); 15 12 : (void) atexit( fd_halt ); 16 12 : fd_log_level_core_set( 1 ); 17 12 : return 0; 18 12 : } 19 : 20 : int 21 : LLVMFuzzerTestOneInput( uchar const *data, 22 : ulong size ) { 23 : fd_valloc_t valloc = fd_libc_alloc_virtual(); 24 : 25 : ulong metadata_size = sizeof(uint8_t); 26 : if (size < metadata_size) { 27 : return 0; 28 : } 29 : 30 : uint8_t choice = FD_LOAD( uint8_t, data+0 ); 31 : size -= metadata_size; 32 : 33 : uchar* content = (uchar*)data + metadata_size; 34 : 35 : fd_textstream_t _data_out[1]; 36 : fd_textstream_t * data_out = fd_textstream_new( _data_out, valloc, PART_BLK_SZ ); 37 : switch (choice) { 38 : case 0: { 39 : fd_textstream_encode_base64( data_out, content, size ); 40 : break; 41 : } 42 : case 1: { 43 : fd_textstream_encode_base58( data_out, content, size ); 44 : break; 45 : } 46 : case 2: { 47 : fd_textstream_encode_hex( data_out, content, size ); 48 : break; 49 : } 50 : case 3: { 51 : uint *utf8_content = (uint*)content; 52 : ulong utf8_size = ((size*sizeof(uchar))/sizeof(uint)); 53 : fd_textstream_encode_utf8( data_out, utf8_content, utf8_size ); 54 : break; 55 : } case 4: { 56 : fd_textstream_append( data_out, (const char*)content, size); 57 : break; 58 : } 59 : default: { 60 : goto cleanup; 61 : } 62 : } 63 : 64 : FD_TEST( 1UL==fd_textstream_get_iov_count( data_out ) ); 65 : struct fd_iovec iov[1]; 66 : FD_TEST( 0 ==fd_textstream_get_iov( data_out, iov ) ); 67 : 68 : ulong total_size = fd_textstream_total_size( data_out ); 69 : char *output = malloc( total_size ); 70 : if ( output == NULL ) { 71 : goto cleanup; 72 : } 73 : FD_TEST( 0==fd_textstream_get_output( data_out, output ) ); 74 : free( output ); 75 : 76 : 77 : cleanup: 78 : fd_textstream_destroy( data_out ); 79 : return 0; 80 : }