LCOV - code coverage report
Current view: top level - disco/pack - fuzz_chkdup.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 7 7 100.0 %
Date: 2025-08-05 05:04:49 Functions: 1 1 100.0 %

          Line data    Source code
       1             : #if !FD_HAS_HOSTED
       2             : #error "This target requires FD_HAS_HOSTED"
       3             : #endif
       4             : 
       5             : #include "fd_chkdup.h"
       6             : #include <math.h>
       7             : 
       8             : #include <assert.h>
       9             : #include <stdio.h>
      10             : #include <stdlib.h>
      11             : #include <stdint.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 :   fd_boot( argc, argv );
      19          12 :   atexit( fd_halt );
      20          12 :   fd_log_level_core_set( 3 ); /* crash on warning log */
      21          12 :   return 0;
      22          12 : }
      23             : 
      24             : int
      25             : LLVMFuzzerTestOneInput( uchar const * data,
      26             :                         ulong         data_sz ) {
      27             :   ulong metadata_size = sizeof(uint) + sizeof(ulong) + sizeof(uint8_t);
      28             :   if (data_sz < metadata_size) {
      29             :     return 0;
      30             :   }
      31             :   uint seq = FD_LOAD( uint, data+0 );
      32             :   ulong idx = FD_LOAD( ulong, data+sizeof(seq));
      33             :   uint8_t split = FD_LOAD( uint8_t, data+sizeof(seq)+sizeof(idx) );
      34             :   data_sz -= metadata_size;
      35             : 
      36             :   uchar *content = (uchar*)data+metadata_size;
      37             : 
      38             :   size_t total_addrs = data_sz / sizeof(fd_acct_addr_t);
      39             :   if ( total_addrs == 0 ){
      40             :     return 0;
      41             :   }
      42             : 
      43             :   size_t split_index = split % (total_addrs + 1);  // +1 allows splitting at the end
      44             : 
      45             :   size_t count0 = split_index;
      46             :   size_t count1 = total_addrs - split_index;
      47             : 
      48             :   fd_rng_t _rng[1];
      49             :   fd_rng_t * rng = fd_rng_join( fd_rng_new( _rng, seq, idx ) );
      50             : 
      51             :   fd_chkdup_t _mem[1];
      52             :   fd_chkdup_t * chkdup = fd_chkdup_join( fd_chkdup_new( _mem, rng ) );
      53             : 
      54             :   fd_acct_addr_t const * all_structs = (fd_acct_addr_t const *) content;
      55             :   fd_acct_addr_t const * list0 = all_structs;
      56             :   fd_acct_addr_t const * list1 = all_structs + count0;
      57             : 
      58             :   int regular = fd_chkdup_check( chkdup, list0, count0, list1, count1 );
      59             :   int slow = fd_chkdup_check_slow( chkdup, list0, count0, list1, count1 );
      60             :   fd_chkdup_check_fast( chkdup, list0, count0, list1, count1 );
      61             : 
      62             :   FD_TEST( regular == slow );
      63             :   // fast can have false positives so we don't differentially test it
      64             : 
      65             :   fd_chkdup_delete( fd_chkdup_leave( chkdup ) );
      66             : 
      67             :   return 0;
      68             : }

Generated by: LCOV version 1.14