Coverage Report

Created: 2026-12-01 07:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libmodi/libmodi/libmodi_data_block.c
Line
Count
Source
1
/*
2
 * Data block functions
3
 *
4
 * Copyright (C) 2012-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 <common.h>
23
#include <byte_stream.h>
24
#include <memory.h>
25
#include <types.h>
26
27
#include "libmodi_compression.h"
28
#include "libmodi_data_block.h"
29
#include "libmodi_definitions.h"
30
#include "libmodi_io_handle.h"
31
#include "libmodi_libbfio.h"
32
#include "libmodi_libcerror.h"
33
#include "libmodi_libcnotify.h"
34
#include "libmodi_libfdata.h"
35
#include "libmodi_unused.h"
36
37
/* Creates a data block
38
 * Make sure the value data_block is referencing, is set to NULL
39
 * Returns 1 if successful or -1 on error
40
 */
41
int libmodi_data_block_initialize(
42
     libmodi_data_block_t **data_block,
43
     size_t data_size,
44
     libcerror_error_t **error )
45
61.5k
{
46
61.5k
  static char *function = "libmodi_data_block_initialize";
47
48
61.5k
  if( data_block == NULL )
49
0
  {
50
0
    libcerror_error_set(
51
0
     error,
52
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
53
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
54
0
     "%s: invalid data block.",
55
0
     function );
56
57
0
    return( -1 );
58
0
  }
59
61.5k
  if( *data_block != NULL )
60
0
  {
61
0
    libcerror_error_set(
62
0
     error,
63
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
64
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
65
0
     "%s: invalid data block value already set.",
66
0
     function );
67
68
0
    return( -1 );
69
0
  }
70
61.5k
  if( ( data_size == 0 )
71
61.5k
   || ( data_size > (size_t) MEMORY_MAXIMUM_ALLOCATION_SIZE ) )
72
0
  {
73
0
    libcerror_error_set(
74
0
     error,
75
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
76
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
77
0
     "%s: invalid data size value out of bounds.",
78
0
     function );
79
80
0
    return( -1 );
81
0
  }
82
61.5k
  *data_block = memory_allocate_structure(
83
61.5k
                 libmodi_data_block_t );
84
85
61.5k
  if( *data_block == NULL )
86
0
  {
87
0
    libcerror_error_set(
88
0
     error,
89
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
90
0
     LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
91
0
     "%s: unable to create data block.",
92
0
     function );
93
94
0
    goto on_error;
95
0
  }
96
61.5k
  if( memory_set(
97
61.5k
       *data_block,
98
61.5k
       0,
99
61.5k
       sizeof( libmodi_data_block_t ) ) == NULL )
100
0
  {
101
0
    libcerror_error_set(
102
0
     error,
103
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
104
0
     LIBCERROR_MEMORY_ERROR_SET_FAILED,
105
0
     "%s: unable to clear data block.",
106
0
     function );
107
108
0
    memory_free(
109
0
     *data_block );
110
111
0
    *data_block = NULL;
112
113
0
    return( -1 );
114
0
  }
115
61.5k
  ( *data_block )->data = (uint8_t *) memory_allocate(
116
61.5k
                                       sizeof( uint8_t ) * data_size );
117
118
61.5k
  if( ( *data_block )->data == NULL )
119
0
  {
120
0
    libcerror_error_set(
121
0
     error,
122
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
123
0
     LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
124
0
     "%s: unable to create data.",
125
0
     function );
126
127
0
    goto on_error;
128
0
  }
129
61.5k
  ( *data_block )->data_size = data_size;
130
131
61.5k
  return( 1 );
132
133
0
on_error:
134
0
  if( *data_block != NULL )
135
0
  {
136
0
    memory_free(
137
0
     *data_block );
138
139
0
    *data_block = NULL;
140
0
  }
141
0
  return( -1 );
142
61.5k
}
143
144
/* Frees a data block
145
 * Returns 1 if successful or -1 on error
146
 */
147
int libmodi_data_block_free(
148
     libmodi_data_block_t **data_block,
149
     libcerror_error_t **error )
150
61.5k
{
151
61.5k
  static char *function = "libmodi_data_block_free";
152
61.5k
  int result            = 1;
153
154
61.5k
  if( data_block == NULL )
155
0
  {
156
0
    libcerror_error_set(
157
0
     error,
158
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
159
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
160
0
     "%s: invalid data block.",
161
0
     function );
162
163
0
    return( -1 );
164
0
  }
165
61.5k
  if( *data_block != NULL )
166
61.5k
  {
167
61.5k
    memory_free(
168
61.5k
     ( *data_block )->data );
169
170
61.5k
    memory_free(
171
61.5k
     *data_block );
172
173
61.5k
    *data_block = NULL;
174
61.5k
  }
175
61.5k
  return( result );
176
61.5k
}
177
178
/* Clears a data block
179
 * Returns 1 if successful or -1 on error
180
 */
181
int libmodi_data_block_clear(
182
     libmodi_data_block_t *data_block,
183
     libcerror_error_t **error )
184
0
{
185
0
  static char *function = "libmodi_data_block_clear";
186
187
0
  if( data_block == NULL )
188
0
  {
189
0
    libcerror_error_set(
190
0
     error,
191
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
192
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
193
0
     "%s: invalid data block.",
194
0
     function );
195
196
0
    return( -1 );
197
0
  }
198
0
  if( data_block->data == NULL )
199
0
  {
200
0
    libcerror_error_set(
201
0
     error,
202
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
203
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
204
0
     "%s: invalid data block - missing data.",
205
0
     function );
206
207
0
    return( -1 );
208
0
  }
209
0
  if( memory_set(
210
0
       data_block->data,
211
0
       0,
212
0
       data_block->data_size ) == NULL )
213
0
  {
214
0
    libcerror_error_set(
215
0
     error,
216
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
217
0
     LIBCERROR_MEMORY_ERROR_SET_FAILED,
218
0
     "%s: unable to clear data block data.",
219
0
     function );
220
221
0
    return( -1 );
222
0
  }
223
0
  return( 1 );
224
0
}
225
226
/* Reads data block
227
 * Returns 1 if successful or -1 on error
228
 */
229
int libmodi_data_block_read_file_io_handle(
230
     libmodi_data_block_t *data_block,
231
     libbfio_handle_t *file_io_handle,
232
     off64_t data_block_offset,
233
     libcerror_error_t **error )
234
16.3k
{
235
16.3k
  static char *function = "libmodi_data_block_read_file_io_handle";
236
16.3k
  ssize_t read_count    = 0;
237
238
16.3k
  if( data_block == NULL )
239
0
  {
240
0
    libcerror_error_set(
241
0
     error,
242
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
243
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
244
0
     "%s: invalid data block.",
245
0
     function );
246
247
0
    return( -1 );
248
0
  }
249
#if defined( HAVE_DEBUG_OUTPUT )
250
  if( libcnotify_verbose != 0 )
251
  {
252
    libcnotify_printf(
253
     "%s: reading data block at offset: %" PRIi64 " (0x%08" PRIx64 ")\n",
254
     function,
255
     data_block_offset,
256
     data_block_offset );
257
  }
258
#endif
259
16.3k
  read_count = libbfio_handle_read_buffer_at_offset(
260
16.3k
                file_io_handle,
261
16.3k
                data_block->data,
262
16.3k
                data_block->data_size,
263
16.3k
                data_block_offset,
264
16.3k
                error );
265
266
16.3k
  if( read_count != (ssize_t) data_block->data_size )
267
202
  {
268
202
    libcerror_error_set(
269
202
     error,
270
202
     LIBCERROR_ERROR_DOMAIN_IO,
271
202
     LIBCERROR_IO_ERROR_READ_FAILED,
272
202
     "%s: unable to read data block at offset: %" PRIi64 " (0x%08" PRIx64 ").",
273
202
     function,
274
202
     data_block_offset,
275
202
     data_block_offset );
276
277
202
    return( -1 );
278
202
  }
279
#if defined( HAVE_DEBUG_OUTPUT )
280
  if( libcnotify_verbose != 0 )
281
  {
282
    libcnotify_printf(
283
     "%s: data block:\n",
284
     function );
285
    libcnotify_print_data(
286
     data_block->data,
287
     data_block->data_size,
288
     LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA );
289
  }
290
#endif
291
16.1k
  return( 1 );
292
16.3k
}
293
294
/* Reads a data block
295
 * Callback function for the block chunks list
296
 * Returns 1 if successful or -1 on error
297
 */
298
int libmodi_data_block_read_list_element_data(
299
     libmodi_io_handle_t *io_handle,
300
     libbfio_handle_t *file_io_handle,
301
     libfdata_list_element_t *element,
302
     libfdata_cache_t *cache,
303
     int element_data_file_index LIBMODI_ATTRIBUTE_UNUSED,
304
     off64_t element_data_offset,
305
     size64_t element_data_size,
306
     uint32_t element_data_flags,
307
     uint8_t read_flags LIBMODI_ATTRIBUTE_UNUSED,
308
     libcerror_error_t **error )
309
1.51k
{
310
1.51k
  libmodi_data_block_t *data_block = NULL;
311
1.51k
  static char *function            = "libmodi_data_block_read_list_element_data";
312
1.51k
  uint8_t *compressed_data         = NULL;
313
1.51k
  size64_t mapped_size             = 0;
314
1.51k
  size_t uncompressed_data_size    = 0;
315
1.51k
  ssize_t read_count               = 0;
316
317
1.51k
  LIBMODI_UNREFERENCED_PARAMETER( element_data_file_index )
318
1.51k
  LIBMODI_UNREFERENCED_PARAMETER( read_flags )
319
320
1.51k
  if( io_handle == NULL )
321
0
  {
322
0
    libcerror_error_set(
323
0
     error,
324
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
325
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
326
0
     "%s: invalid IO handle.",
327
0
     function );
328
329
0
    return( -1 );
330
0
  }
331
1.51k
  if( ( element_data_flags & LIBFDATA_RANGE_FLAG_IS_COMPRESSED ) != 0 )
332
1.48k
  {
333
1.48k
    if( ( element_data_size == 0 )
334
1.48k
     || ( element_data_size > (size64_t) MEMORY_MAXIMUM_ALLOCATION_SIZE ) )
335
61
    {
336
61
      libcerror_error_set(
337
61
       error,
338
61
       LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
339
61
       LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
340
61
       "%s: invalid element data size value out of bounds.",
341
61
       function );
342
343
61
      return( -1 );
344
61
    }
345
1.48k
  }
346
1.45k
  if( libfdata_list_element_get_mapped_size(
347
1.45k
       element,
348
1.45k
       &mapped_size,
349
1.45k
       error ) != 1 )
350
0
  {
351
0
    libcerror_error_set(
352
0
     error,
353
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
354
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
355
0
     "%s: unable to retrieve mapped size from element.",
356
0
     function );
357
358
0
    goto on_error;
359
0
  }
360
1.45k
  if( ( mapped_size == 0 )
361
1.45k
   || ( mapped_size > (size64_t) SSIZE_MAX ) )
362
0
  {
363
0
    libcerror_error_set(
364
0
     error,
365
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
366
0
     LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
367
0
     "%s: invalid block chunk data size value out of bounds.",
368
0
     function );
369
370
0
    goto on_error;
371
0
  }
372
1.45k
  if( libmodi_data_block_initialize(
373
1.45k
       &data_block,
374
1.45k
       (size_t) mapped_size,
375
1.45k
       error ) != 1 )
376
0
  {
377
0
    libcerror_error_set(
378
0
     error,
379
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
380
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
381
0
     "%s: unable to create data block.",
382
0
     function );
383
384
0
    goto on_error;
385
0
  }
386
1.45k
  if( ( element_data_flags & LIBFDATA_RANGE_FLAG_IS_SPARSE ) != 0 )
387
0
  {
388
0
    if( memory_set(
389
0
         data_block->data,
390
0
         0,
391
0
         data_block->data_size ) == NULL )
392
0
    {
393
0
      libcerror_error_set(
394
0
       error,
395
0
       LIBCERROR_ERROR_DOMAIN_MEMORY,
396
0
       LIBCERROR_MEMORY_ERROR_SET_FAILED,
397
0
       "%s: unable to clear data block.",
398
0
       function );
399
400
0
      goto on_error;
401
0
    }
402
0
  }
403
1.45k
  else if( ( element_data_flags & LIBFDATA_RANGE_FLAG_IS_COMPRESSED ) != 0 )
404
1.42k
  {
405
#if defined( HAVE_DEBUG_OUTPUT )
406
    if( libcnotify_verbose != 0 )
407
    {
408
      libcnotify_printf(
409
       "%s: reading compressed block chunk at offset: %" PRIi64 " (0x%08" PRIx64 ")\n",
410
       function,
411
       element_data_offset,
412
       element_data_offset );
413
    }
414
#endif
415
1.42k
    compressed_data = (uint8_t *) memory_allocate(
416
1.42k
                                   sizeof( uint8_t ) * element_data_size );
417
418
1.42k
    if( compressed_data == NULL )
419
0
    {
420
0
      libcerror_error_set(
421
0
       error,
422
0
       LIBCERROR_ERROR_DOMAIN_MEMORY,
423
0
       LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
424
0
       "%s: unable to create compressed data.",
425
0
       function );
426
427
0
      goto on_error;
428
0
    }
429
1.42k
    read_count = libbfio_handle_read_buffer_at_offset(
430
1.42k
                  file_io_handle,
431
1.42k
                  compressed_data,
432
1.42k
                  element_data_size,
433
1.42k
                  element_data_offset,
434
1.42k
                  error );
435
436
1.42k
    if( read_count != (ssize_t) element_data_size )
437
26
    {
438
26
      libcerror_error_set(
439
26
       error,
440
26
       LIBCERROR_ERROR_DOMAIN_IO,
441
26
       LIBCERROR_IO_ERROR_READ_FAILED,
442
26
       "%s: unable to read compressed block chunk at offset: %" PRIi64 " (0x%08" PRIx64 ").",
443
26
       function,
444
26
       element_data_offset,
445
26
       element_data_offset );
446
447
26
      goto on_error;
448
26
    }
449
1.40k
    uncompressed_data_size = data_block->data_size;
450
451
1.40k
    if( libmodi_decompress_data(
452
1.40k
         compressed_data,
453
1.40k
         (size_t) read_count,
454
1.40k
         io_handle->compression_method,
455
1.40k
         data_block->data,
456
1.40k
         &uncompressed_data_size,
457
1.40k
         error ) != 1 )
458
818
    {
459
818
      libcerror_error_set(
460
818
       error,
461
818
       LIBCERROR_ERROR_DOMAIN_ENCRYPTION,
462
818
       LIBCERROR_ENCRYPTION_ERROR_GENERIC,
463
818
       "%s: unable to decompress block chunk at offset: %" PRIi64 " (0x%08" PRIx64 ").",
464
818
       function,
465
818
       element_data_offset,
466
818
       element_data_offset );
467
468
818
      goto on_error;
469
818
    }
470
583
    memory_free(
471
583
     compressed_data );
472
473
583
    compressed_data = NULL;
474
583
  }
475
29
  else
476
29
  {
477
29
    if( libmodi_data_block_read_file_io_handle(
478
29
         data_block,
479
29
         file_io_handle,
480
29
         element_data_offset,
481
29
         error ) != 1 )
482
19
    {
483
19
      libcerror_error_set(
484
19
       error,
485
19
       LIBCERROR_ERROR_DOMAIN_IO,
486
19
       LIBCERROR_IO_ERROR_READ_FAILED,
487
19
       "%s: unable to read data block at offset: %" PRIi64 " (0x%08" PRIx64 ").",
488
19
       function,
489
19
       element_data_offset,
490
19
       element_data_offset );
491
492
19
      goto on_error;
493
19
    }
494
29
  }
495
593
  if( libfdata_list_element_set_element_value(
496
593
       element,
497
593
       (intptr_t *) file_io_handle,
498
593
       cache,
499
593
       (intptr_t *) data_block,
500
593
       (int (*)(intptr_t **, libcerror_error_t **)) &libmodi_data_block_free,
501
593
       LIBFDATA_LIST_ELEMENT_VALUE_FLAG_MANAGED,
502
593
       error ) != 1 )
503
0
  {
504
0
    libcerror_error_set(
505
0
     error,
506
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
507
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
508
0
     "%s: unable to set data block as element value.",
509
0
     function );
510
511
0
    goto on_error;
512
0
  }
513
593
  return( 1 );
514
515
863
on_error:
516
863
  if( compressed_data != NULL )
517
844
  {
518
844
    memory_free(
519
844
     compressed_data );
520
844
  }
521
863
  if( data_block != NULL )
522
863
  {
523
863
    libmodi_data_block_free(
524
863
     &data_block,
525
863
     NULL );
526
863
  }
527
863
  return( -1 );
528
593
}
529
530
/* Reads a data block
531
 * Callback function for the data block vector
532
 * Returns 1 if successful or -1 on error
533
 */
534
int libmodi_data_block_read_vector_element_data(
535
     libmodi_io_handle_t *io_handle,
536
     intptr_t *file_io_handle,
537
     libfdata_vector_t *vector,
538
     libfdata_cache_t *cache,
539
     int element_index,
540
     int element_data_file_index,
541
     off64_t element_data_offset,
542
     size64_t element_data_size,
543
     uint32_t element_data_flags,
544
     uint8_t read_flags LIBMODI_ATTRIBUTE_UNUSED,
545
     libcerror_error_t **error )
546
60.1k
{
547
60.1k
  libbfio_handle_t *bfio_handle    = NULL;
548
60.1k
  libmodi_data_block_t *data_block = NULL;
549
60.1k
  static char *function            = "libmodi_data_block_read_vector_element_data";
550
551
60.1k
  LIBMODI_UNREFERENCED_PARAMETER( read_flags );
552
553
60.1k
  if( io_handle == NULL )
554
0
  {
555
0
    libcerror_error_set(
556
0
     error,
557
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
558
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
559
0
     "%s: invalid IO handle.",
560
0
     function );
561
562
0
    return( -1 );
563
0
  }
564
60.1k
  if( ( io_handle->image_type != LIBMODI_IMAGE_TYPE_SPARSE_BUNDLE )
565
60.1k
   && ( element_data_file_index != 0 ) )
566
0
  {
567
0
    libcerror_error_set(
568
0
     error,
569
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
570
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
571
0
     "%s: invalid element data file index value out of bounds.",
572
0
     function );
573
574
0
    return( -1 );
575
0
  }
576
60.1k
  if( ( element_data_size == 0 )
577
60.1k
   || ( element_data_size > (size64_t) SSIZE_MAX ) )
578
0
  {
579
0
    libcerror_error_set(
580
0
     error,
581
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
582
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
583
0
     "%s: invalid element data size value out of bounds.",
584
0
     function );
585
586
0
    return( -1 );
587
0
  }
588
60.1k
  if( libmodi_data_block_initialize(
589
60.1k
       &data_block,
590
60.1k
       (size_t) element_data_size,
591
60.1k
       error ) != 1 )
592
0
  {
593
0
    libcerror_error_set(
594
0
     error,
595
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
596
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
597
0
     "%s: unable to create data block.",
598
0
     function );
599
600
0
    goto on_error;
601
0
  }
602
60.1k
  if( ( element_data_flags & LIBFDATA_RANGE_FLAG_IS_SPARSE ) != 0 )
603
43.7k
  {
604
43.7k
    if( memory_set(
605
43.7k
         data_block->data,
606
43.7k
         0,
607
43.7k
         data_block->data_size ) == NULL )
608
0
    {
609
0
      libcerror_error_set(
610
0
       error,
611
0
       LIBCERROR_ERROR_DOMAIN_MEMORY,
612
0
       LIBCERROR_MEMORY_ERROR_SET_FAILED,
613
0
       "%s: unable to clear data block.",
614
0
       function );
615
616
0
      goto on_error;
617
0
    }
618
43.7k
  }
619
16.3k
  else
620
16.3k
  {
621
16.3k
    if( io_handle->image_type != LIBMODI_IMAGE_TYPE_SPARSE_BUNDLE )
622
16.3k
    {
623
16.3k
      bfio_handle = (libbfio_handle_t *) file_io_handle;
624
16.3k
    }
625
0
    else if( libbfio_pool_get_handle(
626
0
              (libbfio_pool_t *) file_io_handle,
627
0
              element_data_file_index,
628
0
              &bfio_handle,
629
0
              error ) != 1 )
630
0
    {
631
0
      libcerror_error_set(
632
0
       error,
633
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
634
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
635
0
       "%s: unable to retrieve handle: %d from file IO pool.",
636
0
       function,
637
0
       element_data_file_index );
638
639
0
      goto on_error;
640
0
    }
641
16.3k
    if( libmodi_data_block_read_file_io_handle(
642
16.3k
         data_block,
643
16.3k
         bfio_handle,
644
16.3k
         element_data_offset,
645
16.3k
         error ) != 1 )
646
183
    {
647
183
      libcerror_error_set(
648
183
       error,
649
183
       LIBCERROR_ERROR_DOMAIN_IO,
650
183
       LIBCERROR_IO_ERROR_READ_FAILED,
651
183
       "%s: unable to read data block at offset: %" PRIi64 " (0x%08" PRIx64 ").",
652
183
       function,
653
183
       element_data_offset,
654
183
       element_data_offset );
655
656
183
      goto on_error;
657
183
    }
658
16.3k
  }
659
59.9k
  if( libfdata_vector_set_element_value_by_index(
660
59.9k
       vector,
661
59.9k
       (intptr_t *) file_io_handle,
662
59.9k
       cache,
663
59.9k
       element_index,
664
59.9k
       (intptr_t *) data_block,
665
59.9k
       (int (*)(intptr_t **, libcerror_error_t **)) &libmodi_data_block_free,
666
59.9k
       LIBFDATA_LIST_ELEMENT_VALUE_FLAG_MANAGED,
667
59.9k
       error ) != 1 )
668
0
  {
669
0
    libcerror_error_set(
670
0
     error,
671
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
672
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
673
0
     "%s: unable to set data block as element value.",
674
0
     function );
675
676
0
    goto on_error;
677
0
  }
678
59.9k
  return( 1 );
679
680
183
on_error:
681
183
  if( data_block != NULL )
682
183
  {
683
183
    libmodi_data_block_free(
684
183
     &data_block,
685
     NULL );
686
183
  }
687
183
  return( -1 );
688
59.9k
}
689