/src/libwrc/ossfuzz/stream_fuzzer.cc
| Line | Count | Source (jump to first uncovered line) | 
| 1 |  | /* | 
| 2 |  |  * OSS-Fuzz target for libwrc stream type | 
| 3 |  |  * | 
| 4 |  |  * Copyright (C) 2011-2024, Joachim Metz <joachim.metz@gmail.com> | 
| 5 |  |  * | 
| 6 |  |  * Refer to AUTHORS for acknowledgements. | 
| 7 |  |  * | 
| 8 |  |  * This program is free software: you can redistribute it and/or modify | 
| 9 |  |  * it under the terms of the GNU Lesser General Public License as published by | 
| 10 |  |  * the Free Software Foundation, either version 3 of the License, or | 
| 11 |  |  * (at your option) any later version. | 
| 12 |  |  * | 
| 13 |  |  * This program is distributed in the hope that it will be useful, | 
| 14 |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| 15 |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
| 16 |  |  * GNU General Public License for more details. | 
| 17 |  |  * | 
| 18 |  |  * You should have received a copy of the GNU Lesser General Public License | 
| 19 |  |  * along with this program.  If not, see <https://www.gnu.org/licenses/>. | 
| 20 |  |  */ | 
| 21 |  |  | 
| 22 |  | #include <stddef.h> | 
| 23 |  | #include <stdint.h> | 
| 24 |  |  | 
| 25 |  | /* Note that some of the OSS-Fuzz engines use C++ | 
| 26 |  |  */ | 
| 27 |  | extern "C" { | 
| 28 |  |  | 
| 29 |  | #include "ossfuzz_libbfio.h" | 
| 30 |  | #include "ossfuzz_libwrc.h" | 
| 31 |  |  | 
| 32 |  | #if !defined( LIBWRC_HAVE_BFIO ) | 
| 33 |  |  | 
| 34 |  | /* Opens a stream using a Basic File IO (bfio) handle | 
| 35 |  |  * Returns 1 if successful or -1 on error | 
| 36 |  |  */ | 
| 37 |  | LIBWRC_EXTERN \ | 
| 38 |  | int libwrc_stream_open_file_io_handle( | 
| 39 |  |      libwrc_stream_t *stream, | 
| 40 |  |      libbfio_handle_t *file_io_handle, | 
| 41 |  |      int access_flags, | 
| 42 |  |      libwrc_error_t **error ); | 
| 43 |  |  | 
| 44 |  | #endif /* !defined( LIBWRC_HAVE_BFIO ) */ | 
| 45 |  |  | 
| 46 |  | int LLVMFuzzerTestOneInput( | 
| 47 |  |      const uint8_t *data, | 
| 48 |  |      size_t size ) | 
| 49 | 49.0k | { | 
| 50 | 49.0k |   libbfio_handle_t *file_io_handle = NULL; | 
| 51 | 49.0k |   libwrc_stream_t *stream          = NULL; | 
| 52 |  |  | 
| 53 | 49.0k |   if( libbfio_memory_range_initialize( | 
| 54 | 49.0k |        &file_io_handle, | 
| 55 | 49.0k |        NULL ) != 1 ) | 
| 56 | 0 |   { | 
| 57 | 0 |     return( 0 ); | 
| 58 | 0 |   } | 
| 59 | 49.0k |   if( libbfio_memory_range_set( | 
| 60 | 49.0k |        file_io_handle, | 
| 61 | 49.0k |        (uint8_t *) data, | 
| 62 | 49.0k |        size, | 
| 63 | 49.0k |        NULL ) != 1 ) | 
| 64 | 0 |   { | 
| 65 | 0 |     goto on_error_libbfio; | 
| 66 | 0 |   } | 
| 67 | 49.0k |   if( libwrc_stream_initialize( | 
| 68 | 49.0k |        &stream, | 
| 69 | 49.0k |        NULL ) != 1 ) | 
| 70 | 0 |   { | 
| 71 | 0 |     goto on_error_libbfio; | 
| 72 | 0 |   } | 
| 73 | 49.0k |   if( libwrc_stream_open_file_io_handle( | 
| 74 | 49.0k |        stream, | 
| 75 | 49.0k |        file_io_handle, | 
| 76 | 49.0k |        LIBWRC_OPEN_READ, | 
| 77 | 49.0k |        NULL ) != 1 ) | 
| 78 | 42.5k |   { | 
| 79 | 42.5k |     goto on_error_libwrc; | 
| 80 | 42.5k |   } | 
| 81 | 6.52k |   libwrc_stream_close( | 
| 82 | 6.52k |    stream, | 
| 83 | 6.52k |    NULL ); | 
| 84 |  |  | 
| 85 | 49.0k | on_error_libwrc: | 
| 86 | 49.0k |   libwrc_stream_free( | 
| 87 | 49.0k |    &stream, | 
| 88 | 49.0k |    NULL ); | 
| 89 |  |  | 
| 90 | 49.0k | on_error_libbfio: | 
| 91 | 49.0k |   libbfio_handle_free( | 
| 92 | 49.0k |    &file_io_handle, | 
| 93 | 49.0k |    NULL ); | 
| 94 |  |  | 
| 95 | 49.0k |   return( 0 ); | 
| 96 | 49.0k | } | 
| 97 |  |  | 
| 98 |  | } /* extern "C" */ | 
| 99 |  |  |