Coverage Report

Created: 2026-12-01 07:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libfsntfs/ossfuzz/attribute_fuzzer.cc
Line
Count
Source
1
/*
2
 * OSS-Fuzz target for libfsntfs attribute type
3
 *
4
 * Copyright (C) 2010-2026, 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_libfsntfs.h"
31
32
#if !defined( LIBFSNTFS_HAVE_BFIO )
33
34
/* Opens a volume using a Basic File IO (bfio) handle
35
 * Returns 1 if successful or -1 on error
36
 */
37
LIBFSNTFS_EXTERN \
38
int libfsntfs_volume_open_file_io_handle(
39
      libfsntfs_volume_t *volume,
40
      libbfio_handle_t *file_io_handle,
41
      int access_flags,
42
      libfsntfs_error_t **error );
43
44
#endif /* !defined( LIBFSNTFS_HAVE_BFIO ) */
45
46
int LLVMFuzzerTestOneInput(
47
      const uint8_t *data,
48
      size_t size )
49
5.05k
{
50
5.05k
  uint8_t guid[ 16 ];
51
5.05k
  uint8_t security_descriptor[ 64 ];
52
5.05k
  uint8_t utf8_string[ 64 ];
53
5.05k
  uint16_t utf16_string[ 32 ];
54
55
5.05k
  libbfio_handle_t *file_io_handle            = NULL;
56
5.05k
  libfsntfs_attribute_t *attribute            = NULL;
57
5.05k
  libfsntfs_file_entry_t *file_entry          = NULL;
58
5.05k
  libfsntfs_file_entry_t *root_directory      = NULL;
59
5.05k
  libfsntfs_file_entry_t *sub_file_entry      = NULL;
60
5.05k
  libfsntfs_volume_t *volume                  = NULL;
61
5.05k
  uint64_t update_sequence_number             = 0;
62
5.05k
  uint64_t parent_file_reference              = 0;
63
5.05k
  uint64_t data_first_vcn                     = 0;
64
5.05k
  uint64_t data_last_vcn                      = 0;
65
5.05k
  uint64_t filetime                           = 0;
66
5.05k
  size64_t valid_data_size                    = 0;
67
5.05k
  size64_t data_size                          = 0;
68
5.05k
  size_t utf8_string_size                     = 0;
69
5.05k
  size_t utf16_string_size                    = 0;
70
5.05k
  uint32_t file_attribute_flags                = 0;
71
5.05k
  uint32_t owner_identifier                    = 0;
72
5.05k
  uint32_t compression_method                  = 0;
73
5.05k
  uint32_t security_descriptor_identifier     = 0;
74
5.05k
  uint32_t tag                                = 0;
75
5.05k
  uint32_t attribute_type                      = 0;
76
5.05k
  uint16_t flags                              = 0;
77
5.05k
  uint16_t data_flags                         = 0;
78
5.05k
  uint8_t name_space                          = 0;
79
5.05k
  uint8_t major_version                       = 0;
80
5.05k
  uint8_t minor_version                       = 0;
81
5.05k
  int attribute_index                         = 0;
82
5.05k
  int number_of_attributes                    = 0;
83
5.05k
  int number_of_sub_file_entries              = 0;
84
5.05k
  int result                                  = 0;
85
86
5.05k
  if( libbfio_memory_range_initialize(
87
5.05k
       &file_io_handle,
88
5.05k
       NULL ) != 1 )
89
0
  {
90
0
    return( 0 );
91
0
  }
92
5.05k
  if( libbfio_memory_range_set(
93
5.05k
       file_io_handle,
94
5.05k
       (uint8_t *) data,
95
5.05k
       size,
96
5.05k
       NULL ) != 1 )
97
0
  {
98
0
    goto on_error_libbfio;
99
0
  }
100
5.05k
  if( libfsntfs_volume_initialize(
101
5.05k
       &volume,
102
5.05k
       NULL ) != 1 )
103
0
  {
104
0
    goto on_error_libbfio;
105
0
  }
106
5.05k
  if( libfsntfs_volume_open_file_io_handle(
107
5.05k
       volume,
108
5.05k
       file_io_handle,
109
5.05k
       LIBFSNTFS_OPEN_READ,
110
5.05k
       NULL ) != 1 )
111
3.40k
  {
112
3.40k
    goto on_error_libfsntfs_volume;
113
3.40k
  }
114
1.65k
  if( libfsntfs_volume_get_root_directory(
115
1.65k
       volume,
116
1.65k
       &root_directory,
117
1.65k
       NULL ) != 1 )
118
692
  {
119
692
    goto on_error_libfsntfs_volume;
120
692
  }
121
961
  if( libfsntfs_file_entry_get_number_of_sub_file_entries(
122
961
       root_directory,
123
961
       &number_of_sub_file_entries,
124
961
       NULL ) != 1 )
125
0
  {
126
0
    goto on_error_libfsntfs_file_entry;
127
0
  }
128
961
  if( number_of_sub_file_entries > 0 )
129
10
  {
130
10
    if( libfsntfs_file_entry_get_sub_file_entry_by_index(
131
10
         root_directory,
132
10
         0,
133
10
         &sub_file_entry,
134
10
         NULL ) != 1 )
135
8
    {
136
8
      goto on_error_libfsntfs_file_entry;
137
8
    }
138
2
    file_entry = sub_file_entry;
139
2
  }
140
951
  else
141
951
  {
142
951
    file_entry = root_directory;
143
951
  }
144
953
  if( libfsntfs_file_entry_get_number_of_attributes(
145
953
       file_entry,
146
953
       &number_of_attributes,
147
953
       NULL ) != 1 )
148
0
  {
149
0
    goto on_error_libfsntfs_file_entry;
150
0
  }
151
953
  for( attribute_index = 0;
152
4.65k
       ( attribute_index < number_of_attributes )
153
4.35k
    && ( attribute_index < 16 );
154
3.70k
       attribute_index++ )
155
4.35k
  {
156
4.35k
    result = libfsntfs_file_entry_get_attribute_by_index(
157
4.35k
               file_entry,
158
4.35k
               attribute_index,
159
4.35k
               &attribute,
160
4.35k
               NULL );
161
162
4.35k
    if( result == -1 )
163
621
    {
164
621
      goto on_error_libfsntfs_attribute;
165
621
    }
166
3.73k
    if( result != 1 )
167
0
    {
168
0
      continue;
169
0
    }
170
3.73k
    if( libfsntfs_attribute_get_type(
171
3.73k
         attribute,
172
3.73k
         &attribute_type,
173
3.73k
         NULL ) != 1 )
174
0
    {
175
0
      goto on_error_libfsntfs_attribute;
176
0
    }
177
3.73k
    if( libfsntfs_attribute_get_data_flags(
178
3.73k
         attribute,
179
3.73k
         &data_flags,
180
3.73k
         NULL ) != 1 )
181
0
    {
182
0
      goto on_error_libfsntfs_attribute;
183
0
    }
184
3.73k
    if( libfsntfs_attribute_get_utf8_name_size(
185
3.73k
         attribute,
186
3.73k
         &utf8_string_size,
187
3.73k
         NULL ) == -1 )
188
0
    {
189
0
      goto on_error_libfsntfs_attribute;
190
0
    }
191
3.73k
    if( utf8_string_size > 0 )
192
264
    {
193
264
      if( libfsntfs_attribute_get_utf8_name(
194
264
           attribute,
195
264
           utf8_string,
196
264
           64,
197
264
           NULL ) == -1 )
198
4
      {
199
4
        goto on_error_libfsntfs_attribute;
200
4
      }
201
264
    }
202
3.72k
    if( libfsntfs_attribute_get_utf16_name_size(
203
3.72k
         attribute,
204
3.72k
         &utf16_string_size,
205
3.72k
         NULL ) == -1 )
206
0
    {
207
0
      goto on_error_libfsntfs_attribute;
208
0
    }
209
3.72k
    if( utf16_string_size > 0 )
210
260
    {
211
260
      if( libfsntfs_attribute_get_utf16_name(
212
260
           attribute,
213
260
           utf16_string,
214
260
           32,
215
260
           NULL ) == -1 )
216
1
      {
217
1
        goto on_error_libfsntfs_attribute;
218
1
      }
219
260
    }
220
3.72k
    if( libfsntfs_attribute_get_data_vcn_range(
221
3.72k
         attribute,
222
3.72k
         &data_first_vcn,
223
3.72k
         &data_last_vcn,
224
3.72k
         NULL ) == -1 )
225
0
    {
226
0
      goto on_error_libfsntfs_attribute;
227
0
    }
228
3.72k
    if( libfsntfs_attribute_get_data_size(
229
3.72k
         attribute,
230
3.72k
         &data_size,
231
3.72k
         NULL ) != 1 )
232
0
    {
233
0
      goto on_error_libfsntfs_attribute;
234
0
    }
235
3.72k
    if( libfsntfs_attribute_get_valid_data_size(
236
3.72k
         attribute,
237
3.72k
         &valid_data_size,
238
3.72k
         NULL ) != 1 )
239
0
    {
240
0
      goto on_error_libfsntfs_attribute;
241
0
    }
242
3.72k
    if( attribute_type == LIBFSNTFS_ATTRIBUTE_TYPE_STANDARD_INFORMATION )
243
435
    {
244
435
      if( libfsntfs_standard_information_attribute_get_creation_time(
245
435
           attribute,
246
435
           &filetime,
247
435
           NULL ) != 1 )
248
0
      {
249
0
        goto on_error_libfsntfs_attribute;
250
0
      }
251
435
      if( libfsntfs_standard_information_attribute_get_modification_time(
252
435
           attribute,
253
435
           &filetime,
254
435
           NULL ) != 1 )
255
0
      {
256
0
        goto on_error_libfsntfs_attribute;
257
0
      }
258
435
      if( libfsntfs_standard_information_attribute_get_access_time(
259
435
           attribute,
260
435
           &filetime,
261
435
           NULL ) != 1 )
262
0
      {
263
0
        goto on_error_libfsntfs_attribute;
264
0
      }
265
435
      if( libfsntfs_standard_information_attribute_get_entry_modification_time(
266
435
           attribute,
267
435
           &filetime,
268
435
           NULL ) != 1 )
269
0
      {
270
0
        goto on_error_libfsntfs_attribute;
271
0
      }
272
435
      if( libfsntfs_standard_information_attribute_get_file_attribute_flags(
273
435
           attribute,
274
435
           &file_attribute_flags,
275
435
           NULL ) != 1 )
276
0
      {
277
0
        goto on_error_libfsntfs_attribute;
278
0
      }
279
435
      if( libfsntfs_standard_information_attribute_get_owner_identifier(
280
435
           attribute,
281
435
           &owner_identifier,
282
435
           NULL ) == -1 )
283
0
      {
284
0
        goto on_error_libfsntfs_attribute;
285
0
      }
286
435
      if( libfsntfs_standard_information_attribute_get_security_descriptor_identifier(
287
435
           attribute,
288
435
           &security_descriptor_identifier,
289
435
           NULL ) == -1 )
290
0
      {
291
0
        goto on_error_libfsntfs_attribute;
292
0
      }
293
435
      if( libfsntfs_standard_information_attribute_get_update_sequence_number(
294
435
           attribute,
295
435
           &update_sequence_number,
296
435
           NULL ) == -1 )
297
0
      {
298
0
        goto on_error_libfsntfs_attribute;
299
0
      }
300
435
    }
301
3.29k
    else if( attribute_type == LIBFSNTFS_ATTRIBUTE_TYPE_FILE_NAME )
302
444
    {
303
444
      if( libfsntfs_file_name_attribute_get_parent_file_reference(
304
444
           attribute,
305
444
           &parent_file_reference,
306
444
           NULL ) != 1 )
307
0
      {
308
0
        goto on_error_libfsntfs_attribute;
309
0
      }
310
444
      if( libfsntfs_file_name_attribute_get_creation_time(
311
444
           attribute,
312
444
           &filetime,
313
444
           NULL ) != 1 )
314
0
      {
315
0
        goto on_error_libfsntfs_attribute;
316
0
      }
317
444
      if( libfsntfs_file_name_attribute_get_modification_time(
318
444
           attribute,
319
444
           &filetime,
320
444
           NULL ) != 1 )
321
0
      {
322
0
        goto on_error_libfsntfs_attribute;
323
0
      }
324
444
      if( libfsntfs_file_name_attribute_get_access_time(
325
444
           attribute,
326
444
           &filetime,
327
444
           NULL ) != 1 )
328
0
      {
329
0
        goto on_error_libfsntfs_attribute;
330
0
      }
331
444
      if( libfsntfs_file_name_attribute_get_entry_modification_time(
332
444
           attribute,
333
444
           &filetime,
334
444
           NULL ) != 1 )
335
0
      {
336
0
        goto on_error_libfsntfs_attribute;
337
0
      }
338
444
      if( libfsntfs_file_name_attribute_get_file_attribute_flags(
339
444
           attribute,
340
444
           &file_attribute_flags,
341
444
           NULL ) != 1 )
342
0
      {
343
0
        goto on_error_libfsntfs_attribute;
344
0
      }
345
444
      if( libfsntfs_file_name_attribute_get_name_space(
346
444
           attribute,
347
444
           &name_space,
348
444
           NULL ) != 1 )
349
0
      {
350
0
        goto on_error_libfsntfs_attribute;
351
0
      }
352
444
      if( libfsntfs_file_name_attribute_get_utf8_name_size(
353
444
           attribute,
354
444
           &utf8_string_size,
355
444
           NULL ) != 1 )
356
8
      {
357
8
        goto on_error_libfsntfs_attribute;
358
8
      }
359
436
      if( libfsntfs_file_name_attribute_get_utf8_name(
360
436
           attribute,
361
436
           utf8_string,
362
436
           64,
363
436
           NULL ) != 1 )
364
0
      {
365
0
        goto on_error_libfsntfs_attribute;
366
0
      }
367
436
      if( libfsntfs_file_name_attribute_get_utf16_name_size(
368
436
           attribute,
369
436
           &utf16_string_size,
370
436
           NULL ) != 1 )
371
0
      {
372
0
        goto on_error_libfsntfs_attribute;
373
0
      }
374
436
      if( libfsntfs_file_name_attribute_get_utf16_name(
375
436
           attribute,
376
436
           utf16_string,
377
436
           32,
378
436
           NULL ) != 1 )
379
0
      {
380
0
        goto on_error_libfsntfs_attribute;
381
0
      }
382
436
    }
383
2.84k
    else if( attribute_type == LIBFSNTFS_ATTRIBUTE_TYPE_OBJECT_IDENTIFIER )
384
27
    {
385
27
      if( libfsntfs_object_identifier_attribute_get_droid_file_identifier(
386
27
           attribute,
387
27
           guid,
388
27
           16,
389
27
           NULL ) != 1 )
390
0
      {
391
0
        goto on_error_libfsntfs_attribute;
392
0
      }
393
27
      if( libfsntfs_object_identifier_attribute_get_birth_droid_volume_identifier(
394
27
           attribute,
395
27
           guid,
396
27
           16,
397
27
           NULL ) == -1 )
398
0
      {
399
0
        goto on_error_libfsntfs_attribute;
400
0
      }
401
27
      if( libfsntfs_object_identifier_attribute_get_birth_droid_file_identifier(
402
27
           attribute,
403
27
           guid,
404
27
           16,
405
27
           NULL ) == -1 )
406
0
      {
407
0
        goto on_error_libfsntfs_attribute;
408
0
      }
409
27
      if( libfsntfs_object_identifier_attribute_get_birth_droid_domain_identifier(
410
27
           attribute,
411
27
           guid,
412
27
           16,
413
27
           NULL ) == -1 )
414
0
      {
415
0
        goto on_error_libfsntfs_attribute;
416
0
      }
417
27
    }
418
2.82k
    else if( attribute_type == LIBFSNTFS_ATTRIBUTE_TYPE_SECURITY_DESCRIPTOR )
419
12
    {
420
12
      if( libfsntfs_security_descriptor_attribute_get_security_descriptor_size(
421
12
           attribute,
422
12
           &utf8_string_size,
423
12
           NULL ) == -1 )
424
0
      {
425
0
        goto on_error_libfsntfs_attribute;
426
0
      }
427
12
      if( libfsntfs_security_descriptor_attribute_get_security_descriptor(
428
12
           attribute,
429
12
           security_descriptor,
430
12
           64,
431
12
           NULL ) == -1 )
432
9
      {
433
9
        goto on_error_libfsntfs_attribute;
434
9
      }
435
12
    }
436
2.80k
    else if( attribute_type == LIBFSNTFS_ATTRIBUTE_TYPE_VOLUME_NAME )
437
186
    {
438
186
      if( libfsntfs_volume_name_attribute_get_utf8_name_size(
439
186
           attribute,
440
186
           &utf8_string_size,
441
186
           NULL ) != 1 )
442
2
      {
443
2
        goto on_error_libfsntfs_attribute;
444
2
      }
445
184
      if( libfsntfs_volume_name_attribute_get_utf8_name(
446
184
           attribute,
447
184
           utf8_string,
448
184
           64,
449
184
           NULL ) != 1 )
450
1
      {
451
1
        goto on_error_libfsntfs_attribute;
452
1
      }
453
183
      if( libfsntfs_volume_name_attribute_get_utf16_name_size(
454
183
           attribute,
455
183
           &utf16_string_size,
456
183
           NULL ) != 1 )
457
0
      {
458
0
        goto on_error_libfsntfs_attribute;
459
0
      }
460
183
      if( libfsntfs_volume_name_attribute_get_utf16_name(
461
183
           attribute,
462
183
           utf16_string,
463
183
           32,
464
183
           NULL ) != 1 )
465
0
      {
466
0
        goto on_error_libfsntfs_attribute;
467
0
      }
468
183
    }
469
2.62k
    else if( attribute_type == LIBFSNTFS_ATTRIBUTE_TYPE_VOLUME_INFORMATION )
470
16
    {
471
16
      if( libfsntfs_volume_information_attribute_get_version(
472
16
           attribute,
473
16
           &major_version,
474
16
           &minor_version,
475
16
           NULL ) != 1 )
476
0
      {
477
0
        goto on_error_libfsntfs_attribute;
478
0
      }
479
16
      if( libfsntfs_volume_information_attribute_get_flags(
480
16
           attribute,
481
16
           &flags,
482
16
           NULL ) != 1 )
483
0
      {
484
0
        goto on_error_libfsntfs_attribute;
485
0
      }
486
16
    }
487
2.60k
    else if( attribute_type == LIBFSNTFS_ATTRIBUTE_TYPE_REPARSE_POINT )
488
29
    {
489
29
      if( libfsntfs_reparse_point_attribute_get_tag(
490
29
           attribute,
491
29
           &tag,
492
29
           NULL ) != 1 )
493
0
      {
494
0
        goto on_error_libfsntfs_attribute;
495
0
      }
496
29
      if( libfsntfs_reparse_point_attribute_get_compression_method(
497
29
           attribute,
498
29
           &compression_method,
499
29
           NULL ) == -1 )
500
0
      {
501
0
        goto on_error_libfsntfs_attribute;
502
0
      }
503
29
      if( libfsntfs_reparse_point_attribute_get_utf8_substitute_name_size(
504
29
           attribute,
505
29
           &utf8_string_size,
506
29
           NULL ) == -1 )
507
1
      {
508
1
        goto on_error_libfsntfs_attribute;
509
1
      }
510
28
      if( libfsntfs_reparse_point_attribute_get_utf8_substitute_name(
511
28
           attribute,
512
28
           utf8_string,
513
28
           64,
514
28
           NULL ) == -1 )
515
0
      {
516
0
        goto on_error_libfsntfs_attribute;
517
0
      }
518
28
      if( libfsntfs_reparse_point_attribute_get_utf16_substitute_name_size(
519
28
           attribute,
520
28
           &utf16_string_size,
521
28
           NULL ) == -1 )
522
0
      {
523
0
        goto on_error_libfsntfs_attribute;
524
0
      }
525
28
      if( libfsntfs_reparse_point_attribute_get_utf16_substitute_name(
526
28
           attribute,
527
28
           utf16_string,
528
28
           32,
529
28
           NULL ) == -1 )
530
0
      {
531
0
        goto on_error_libfsntfs_attribute;
532
0
      }
533
28
      if( libfsntfs_reparse_point_attribute_get_utf8_print_name_size(
534
28
           attribute,
535
28
           &utf8_string_size,
536
28
           NULL ) == -1 )
537
1
      {
538
1
        goto on_error_libfsntfs_attribute;
539
1
      }
540
27
      if( libfsntfs_reparse_point_attribute_get_utf8_print_name(
541
27
           attribute,
542
27
           utf8_string,
543
27
           64,
544
27
           NULL ) == -1 )
545
0
      {
546
0
        goto on_error_libfsntfs_attribute;
547
0
      }
548
27
      if( libfsntfs_reparse_point_attribute_get_utf16_print_name_size(
549
27
           attribute,
550
27
           &utf16_string_size,
551
27
           NULL ) == -1 )
552
0
      {
553
0
        goto on_error_libfsntfs_attribute;
554
0
      }
555
27
      if( libfsntfs_reparse_point_attribute_get_utf16_print_name(
556
27
           attribute,
557
27
           utf16_string,
558
27
           32,
559
27
           NULL ) == -1 )
560
0
      {
561
0
        goto on_error_libfsntfs_attribute;
562
0
      }
563
27
    }
564
565
3.70k
    libfsntfs_attribute_free(
566
3.70k
     &attribute,
567
3.70k
     NULL );
568
3.70k
  }
569
953
on_error_libfsntfs_attribute:
570
953
  libfsntfs_attribute_free(
571
953
   &attribute,
572
953
   NULL );
573
574
961
on_error_libfsntfs_file_entry:
575
961
  if( sub_file_entry != NULL )
576
2
  {
577
2
    libfsntfs_file_entry_free(
578
2
     &sub_file_entry,
579
2
     NULL );
580
2
  }
581
961
  libfsntfs_file_entry_free(
582
961
   &root_directory,
583
961
   NULL );
584
961
  libfsntfs_volume_close(
585
961
   volume,
586
961
   NULL );
587
588
5.05k
on_error_libfsntfs_volume:
589
5.05k
  libfsntfs_volume_free(
590
5.05k
   &volume,
591
5.05k
   NULL );
592
593
5.05k
on_error_libbfio:
594
5.05k
  libbfio_handle_free(
595
5.05k
   &file_io_handle,
596
5.05k
   NULL );
597
598
5.05k
  return( 0 );
599
5.05k
}
600
601
} /* extern "C" */