Skip to content

Commit ce401c3

Browse files
committed
Worked on OSS-Fuzz targets
1 parent 0f3336c commit ce401c3

2 files changed

Lines changed: 80 additions & 6 deletions

File tree

ossfuzz/partition_fuzzer.cc

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,18 @@ int LLVMFuzzerTestOneInput(
4747
const uint8_t *data,
4848
size_t size )
4949
{
50+
uint8_t buffer[ 512 ];
51+
char string[ 64 ];
52+
5053
libbfio_handle_t *file_io_handle = NULL;
51-
libvsbsdl_partition_t *partition = NULL;
52-
libvsbsdl_volume_t *volume = NULL;
54+
libvsbsdl_partition_t *partition = NULL;
55+
libvsbsdl_volume_t *volume = NULL;
56+
off64_t partition_offset = 0;
57+
off64_t volume_offset = 0;
58+
size64_t partition_size = 0;
59+
uint16_t value_16bit = 0;
5360
int number_of_partitions = 0;
61+
int read_iterator = 0;
5462

5563
if( libbfio_memory_range_initialize(
5664
&file_io_handle,
@@ -93,12 +101,62 @@ int LLVMFuzzerTestOneInput(
93101
volume,
94102
0,
95103
&partition,
96-
NULL ) == 1 )
104+
NULL ) != 1 )
105+
{
106+
goto on_error_libvsbsdl_volume;
107+
}
108+
if( libvsbsdl_partition_get_entry_index(
109+
partition,
110+
&value_16bit,
111+
NULL ) != 1 )
112+
{
113+
goto on_error_libvsbsdl_partition;
114+
}
115+
if( libvsbsdl_partition_get_name_string(
116+
partition,
117+
string,
118+
64,
119+
NULL ) != 1 )
120+
{
121+
goto on_error_libvsbsdl_partition;
122+
}
123+
if( libvsbsdl_partition_get_volume_offset(
124+
partition,
125+
&volume_offset,
126+
NULL ) != 1 )
127+
{
128+
goto on_error_libvsbsdl_partition;
129+
}
130+
if( libvsbsdl_partition_get_size(
131+
partition,
132+
&partition_size,
133+
NULL ) != 1 )
134+
{
135+
goto on_error_libvsbsdl_partition;
136+
}
137+
for( read_iterator = 0;
138+
read_iterator < 128;
139+
read_iterator++ )
97140
{
98-
libvsbsdl_partition_free(
99-
&partition,
100-
NULL );
141+
if( partition_offset >= partition_size )
142+
{
143+
break;
144+
}
145+
if( libvsbsdl_partition_read_buffer_at_offset(
146+
partition,
147+
buffer,
148+
497,
149+
partition_offset,
150+
NULL ) == -1 )
151+
{
152+
goto on_error_libvsbsdl_partition;
153+
}
154+
partition_offset += 497;
101155
}
156+
on_error_libvsbsdl_partition:
157+
libvsbsdl_partition_free(
158+
&partition,
159+
NULL );
102160
}
103161
libvsbsdl_volume_close(
104162
volume,

ossfuzz/volume_fuzzer.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ int LLVMFuzzerTestOneInput(
4949
{
5050
libbfio_handle_t *file_io_handle = NULL;
5151
libvsbsdl_volume_t *volume = NULL;
52+
uint32_t value_32bit = 0;
53+
int number_of_partitions = 0;
5254

5355
if( libbfio_memory_range_initialize(
5456
&file_io_handle,
@@ -78,6 +80,20 @@ int LLVMFuzzerTestOneInput(
7880
{
7981
goto on_error_libvsbsdl;
8082
}
83+
if( libvsbsdl_volume_get_bytes_per_sector(
84+
volume,
85+
&value_32bit,
86+
NULL ) != 1 )
87+
{
88+
goto on_error_libvsbsdl;
89+
}
90+
if( libvsbsdl_volume_get_number_of_partitions(
91+
volume,
92+
&number_of_partitions,
93+
NULL ) != 1 )
94+
{
95+
goto on_error_libvsbsdl;
96+
}
8197
libvsbsdl_volume_close(
8298
volume,
8399
NULL );

0 commit comments

Comments
 (0)