LCOV - code coverage report
Current view: top level - ballet/hex - fuzz_hex.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 8 19 42.1 %
Date: 2026-03-19 05:48:49 Functions: 1 2 50.0 %

          Line data    Source code
       1             : #if !FD_HAS_HOSTED
       2             : #error "This target requires FD_HAS_HOSTED"
       3             : #endif
       4             : 
       5             : #include <assert.h>
       6             : #include <stdio.h>
       7             : #include <stdlib.h>
       8             : 
       9             : #include "../../util/fd_util.h"
      10             : #include "../../util/sanitize/fd_fuzz.h"
      11             : #include "fd_hex.h"
      12             : 
      13             : int
      14             : LLVMFuzzerInitialize( int  *   argc,
      15          12 :                       char *** argv ) {
      16             :   /* Set up shell without signal handlers */
      17          12 :   putenv( "FD_LOG_BACKTRACE=0" );
      18          12 :   setenv( "FD_LOG_PATH", "", 0 );
      19          12 :   fd_boot( argc, argv );
      20          12 :   atexit( fd_halt );
      21          12 :   fd_log_level_core_set(3); /* crash on warning log */
      22          12 :   return 0;
      23          12 : }
      24             : 
      25             : /* checks if given encoding of sz chars is valid, sz must be even
      26             :    returns sz on success, index of first invalid char on failure */
      27             : static inline ulong
      28           0 : check_hex_encoding( char const * enc, ulong sz  ) {
      29           0 :   ulong i;
      30           0 :   for( i=0; i<sz; i++ ) {
      31           0 :     char c = enc[i];
      32           0 :     if( c>='0' && c<='9' ) continue;
      33           0 :     if( c>='a' && c<='f' ) continue;
      34           0 :     if( c>='A' && c<='F' ) continue;
      35           0 :     return i;
      36           0 :   }
      37           0 :   return sz;
      38           0 : }
      39             : 
      40             : #define MAX_DATA_SZ 4096UL
      41             : #define MAX_DECODED_SZ ( MAX_DATA_SZ / 2UL )
      42             : 
      43             : int
      44             : LLVMFuzzerTestOneInput( uchar const * data,
      45             :                         ulong         size ) {
      46             :   if( FD_UNLIKELY( size > MAX_DATA_SZ ) ) return -1;
      47             :   char const * encoded = ( char  const * ) data;
      48             : 
      49             :   size = size & ~1UL; /* ignore last char of encoding if size is odd */
      50             : 
      51             :   uchar decoded[ MAX_DECODED_SZ ];
      52             :   ulong decoded_sz = fd_hex_decode( decoded, encoded, size/2UL );
      53             : 
      54             :   assert( decoded_sz == ( check_hex_encoding( encoded, size )/2UL ) );
      55             : 
      56             :   FD_FUZZ_MUST_BE_COVERED;
      57             :   return 0;
      58             : }

Generated by: LCOV version 1.14