Coverage Report

Created: 2026-12-01 07:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libpff/libpff/libpff_block_tree_node.c
Line
Count
Source
1
/*
2
 * Block tree node functions
3
 *
4
 * Copyright (C) 2008-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 <memory.h>
24
#include <types.h>
25
26
#include "libpff_block_tree_node.h"
27
#include "libpff_definitions.h"
28
#include "libpff_libcerror.h"
29
30
/* Creates a block tree node
31
 * Make sure the value block_tree_node is referencing, is set to NULL
32
 * Returns 1 if successful or -1 on error
33
 */
34
int libpff_block_tree_node_initialize(
35
     libpff_block_tree_node_t **block_tree_node,
36
     off64_t offset,
37
     size64_t size,
38
     size64_t leaf_value_size,
39
     libcerror_error_t **error )
40
2.57M
{
41
2.57M
  static char *function       = "libpff_block_tree_node_initialize";
42
2.57M
  size64_t next_sub_node_size = 0;
43
2.57M
  size64_t sub_node_size      = 0;
44
45
2.57M
  if( block_tree_node == NULL )
46
0
  {
47
0
    libcerror_error_set(
48
0
     error,
49
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
50
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
51
0
     "%s: invalid block tree node.",
52
0
     function );
53
54
0
    return( -1 );
55
0
  }
56
2.57M
  if( *block_tree_node != NULL )
57
0
  {
58
0
    libcerror_error_set(
59
0
     error,
60
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
61
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
62
0
     "%s: invalid block tree node value already set.",
63
0
     function );
64
65
0
    return( -1 );
66
0
  }
67
2.57M
  if( offset < 0 )
68
0
  {
69
0
    libcerror_error_set(
70
0
     error,
71
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
72
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
73
0
     "%s: invalid offset value out of bounds.",
74
0
     function );
75
76
0
    return( -1 );
77
0
  }
78
2.57M
  if( ( size == 0 )
79
2.57M
   || ( size > (size64_t) ( INT64_MAX - offset ) ) )
80
293
  {
81
293
    libcerror_error_set(
82
293
     error,
83
293
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
84
293
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
85
293
     "%s: invalid size value out of bounds.",
86
293
     function );
87
88
293
    return( -1 );
89
293
  }
90
2.57M
  if( ( leaf_value_size == 0 )
91
2.57M
   || ( leaf_value_size > ( SIZE_MAX / LIBPFF_BLOCK_TREE_NUMBER_OF_SUB_NODES ) ) )
92
0
  {
93
0
    libcerror_error_set(
94
0
     error,
95
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
96
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
97
0
     "%s: invalid leaf value size value out of bounds.",
98
0
     function );
99
100
0
    return( -1 );
101
0
  }
102
2.57M
  *block_tree_node = memory_allocate_structure(
103
2.57M
                      libpff_block_tree_node_t );
104
105
2.57M
  if( *block_tree_node == NULL )
106
0
  {
107
0
    libcerror_error_set(
108
0
     error,
109
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
110
0
     LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
111
0
     "%s: unable to create block tree node.",
112
0
     function );
113
114
0
    goto on_error;
115
0
  }
116
2.57M
  if( memory_set(
117
2.57M
       *block_tree_node,
118
2.57M
       0,
119
2.57M
       sizeof( libpff_block_tree_node_t ) ) == NULL )
120
0
  {
121
0
    libcerror_error_set(
122
0
     error,
123
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
124
0
     LIBCERROR_MEMORY_ERROR_SET_FAILED,
125
0
     "%s: unable to clear block tree node.",
126
0
     function );
127
128
0
    memory_free(
129
0
     *block_tree_node );
130
131
0
    *block_tree_node = NULL;
132
133
0
    return( -1 );
134
0
  }
135
2.57M
  sub_node_size      = leaf_value_size;
136
2.57M
  next_sub_node_size = leaf_value_size * LIBPFF_BLOCK_TREE_NUMBER_OF_SUB_NODES;
137
138
4.43M
  while( size > next_sub_node_size )
139
1.86M
  {
140
1.86M
    if( next_sub_node_size > ( SIZE_MAX / LIBPFF_BLOCK_TREE_NUMBER_OF_SUB_NODES ) )
141
0
    {
142
0
      libcerror_error_set(
143
0
       error,
144
0
       LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
145
0
       LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
146
0
       "%s: invalid leaf value size value out of bounds.",
147
0
       function );
148
149
0
      goto on_error;
150
0
    }
151
1.86M
    sub_node_size       = next_sub_node_size;
152
1.86M
    next_sub_node_size *= LIBPFF_BLOCK_TREE_NUMBER_OF_SUB_NODES;
153
1.86M
  }
154
2.57M
  if( libcdata_array_initialize(
155
2.57M
       &( ( *block_tree_node )->sub_nodes_array ),
156
2.57M
       LIBPFF_BLOCK_TREE_NUMBER_OF_SUB_NODES,
157
2.57M
       error ) != 1 )
158
0
  {
159
0
    libcerror_error_set(
160
0
     error,
161
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
162
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
163
0
     "%s: unable to create sub nodes array.",
164
0
     function );
165
166
0
    goto on_error;
167
0
  }
168
2.57M
  ( *block_tree_node )->start_offset  = offset;
169
2.57M
  ( *block_tree_node )->end_offset    = offset + size;
170
2.57M
  ( *block_tree_node )->size          = size;
171
2.57M
  ( *block_tree_node )->sub_node_size = sub_node_size;
172
173
2.57M
  if( sub_node_size == leaf_value_size )
174
1.22M
  {
175
1.22M
    ( *block_tree_node )->is_leaf_node = 1;
176
1.22M
  }
177
2.57M
  return( 1 );
178
179
0
on_error:
180
0
  if( *block_tree_node != NULL )
181
0
  {
182
0
    memory_free(
183
0
     *block_tree_node );
184
185
0
    *block_tree_node = NULL;
186
0
  }
187
0
  return( -1 );
188
2.57M
}
189
190
/* Frees a block tree node
191
 * Returns 1 if successful or -1 on error
192
 */
193
int libpff_block_tree_node_free(
194
     libpff_block_tree_node_t **block_tree_node,
195
     int (*value_free_function)(
196
            intptr_t **value,
197
            libcerror_error_t **error ),
198
     libcerror_error_t **error )
199
345M
{
200
345M
  libpff_block_tree_node_t *sub_block_tree_node = NULL;
201
345M
  static char *function                         = "libpff_block_tree_node_free";
202
345M
  int result                                    = 1;
203
345M
  int sub_node_index                            = 0;
204
205
345M
  if( block_tree_node == NULL )
206
0
  {
207
0
    libcerror_error_set(
208
0
     error,
209
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
210
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
211
0
     "%s: invalid block tree node.",
212
0
     function );
213
214
0
    return( -1 );
215
0
  }
216
345M
  if( *block_tree_node != NULL )
217
2.57M
  {
218
2.57M
    if( ( *block_tree_node )->is_leaf_node != 0 )
219
1.22M
    {
220
1.22M
      if( libcdata_array_free(
221
1.22M
           &( ( *block_tree_node )->sub_nodes_array ),
222
1.22M
           value_free_function,
223
1.22M
           error ) != 1 )
224
0
      {
225
0
        libcerror_error_set(
226
0
         error,
227
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
228
0
         LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
229
0
         "%s: unable to free sub nodes array.",
230
0
         function );
231
232
0
        result = -1;
233
0
      }
234
1.22M
    }
235
1.34M
    else
236
1.34M
    {
237
1.34M
      for( sub_node_index = 0;
238
346M
           sub_node_index < LIBPFF_BLOCK_TREE_NUMBER_OF_SUB_NODES;
239
344M
           sub_node_index++ )
240
344M
      {
241
344M
        if( libcdata_array_get_entry_by_index(
242
344M
             ( *block_tree_node )->sub_nodes_array,
243
344M
             sub_node_index,
244
344M
             (intptr_t **) &sub_block_tree_node,
245
344M
             error ) != 1 )
246
0
        {
247
0
          libcerror_error_set(
248
0
           error,
249
0
           LIBCERROR_ERROR_DOMAIN_RUNTIME,
250
0
           LIBCERROR_RUNTIME_ERROR_GET_FAILED,
251
0
           "%s: unable to retrieve sub node: %d.",
252
0
           function,
253
0
           sub_node_index );
254
255
0
          result = -1;
256
0
        }
257
344M
        if( libpff_block_tree_node_free(
258
344M
             &sub_block_tree_node,
259
344M
             value_free_function,
260
344M
             error ) != 1 )
261
0
        {
262
0
          libcerror_error_set(
263
0
           error,
264
0
           LIBCERROR_ERROR_DOMAIN_RUNTIME,
265
0
           LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
266
0
           "%s: unable to free sub node: %d.",
267
0
           function,
268
0
           sub_node_index );
269
270
0
          result = -1;
271
0
        }
272
344M
      }
273
1.34M
      if( libcdata_array_free(
274
1.34M
           &( ( *block_tree_node )->sub_nodes_array ),
275
1.34M
           NULL,
276
1.34M
           error ) != 1 )
277
0
      {
278
0
        libcerror_error_set(
279
0
         error,
280
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
281
0
         LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
282
0
         "%s: unable to free sub nodes array.",
283
0
         function );
284
285
0
        result = -1;
286
0
      }
287
1.34M
    }
288
2.57M
    memory_free(
289
2.57M
     *block_tree_node );
290
291
2.57M
    *block_tree_node = NULL;
292
2.57M
  }
293
345M
  return( result );
294
345M
}
295
296
/* Retrieves the sub node for a specific offset
297
 * Returns 1 if successful or -1 on error
298
 */
299
int libpff_block_tree_node_get_sub_node_at_offset(
300
     libpff_block_tree_node_t *block_tree_node,
301
     off64_t offset,
302
     libpff_block_tree_node_t **sub_block_tree_node,
303
     libcerror_error_t **error )
304
2.23M
{
305
2.23M
  static char *function  = "libpff_block_tree_node_get_sub_node_at_offset";
306
2.23M
  off64_t sub_node_index = 0;
307
308
2.23M
  if( block_tree_node == NULL )
309
0
  {
310
0
    libcerror_error_set(
311
0
     error,
312
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
313
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
314
0
     "%s: invalid block tree node.",
315
0
     function );
316
317
0
    return( -1 );
318
0
  }
319
2.23M
  if( block_tree_node->is_leaf_node != 0 )
320
0
  {
321
0
    libcerror_error_set(
322
0
     error,
323
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
324
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
325
0
     "%s: invalid block tree node - not a branch node.",
326
0
     function );
327
328
0
    return( -1 );
329
0
  }
330
2.23M
  if( ( offset < block_tree_node->start_offset )
331
2.23M
   || ( offset >= block_tree_node->end_offset ) )
332
3.59k
  {
333
3.59k
    libcerror_error_set(
334
3.59k
     error,
335
3.59k
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
336
3.59k
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
337
3.59k
     "%s: invalid offset value out of bounds.",
338
3.59k
     function );
339
340
3.59k
    return( -1 );
341
3.59k
  }
342
2.23M
  sub_node_index = ( offset - block_tree_node->start_offset ) / block_tree_node->sub_node_size;
343
344
2.23M
  if( ( sub_node_index < 0 )
345
2.23M
   || ( sub_node_index > (off64_t) INT_MAX ) )
346
0
  {
347
0
    libcerror_error_set(
348
0
     error,
349
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
350
0
     LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
351
0
     "%s: invalid sub node index value out of bounds.",
352
0
     function );
353
354
0
    return( -1 );
355
0
  }
356
2.23M
  if( libcdata_array_get_entry_by_index(
357
2.23M
       block_tree_node->sub_nodes_array,
358
2.23M
       (int) sub_node_index,
359
2.23M
       (intptr_t **) sub_block_tree_node,
360
2.23M
       error ) != 1 )
361
0
  {
362
0
    libcerror_error_set(
363
0
     error,
364
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
365
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
366
0
     "%s: unable to retrieve sub node: %" PRIi64 ".",
367
0
     function,
368
0
     sub_node_index );
369
370
0
    return( -1 );
371
0
  }
372
2.23M
  return( 1 );
373
2.23M
}
374
375
/* Sets the sub node for a specific offset
376
 * Returns 1 if successful or -1 on error
377
 */
378
int libpff_block_tree_node_set_sub_node_at_offset(
379
     libpff_block_tree_node_t *block_tree_node,
380
     off64_t offset,
381
     libpff_block_tree_node_t *sub_block_tree_node,
382
     libcerror_error_t **error )
383
1.34M
{
384
1.34M
  static char *function  = "libpff_block_tree_node_set_sub_node_at_offset";
385
1.34M
  off64_t sub_node_index = 0;
386
387
1.34M
  if( block_tree_node == NULL )
388
0
  {
389
0
    libcerror_error_set(
390
0
     error,
391
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
392
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
393
0
     "%s: invalid block tree node.",
394
0
     function );
395
396
0
    return( -1 );
397
0
  }
398
1.34M
  if( block_tree_node->is_leaf_node != 0 )
399
0
  {
400
0
    libcerror_error_set(
401
0
     error,
402
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
403
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
404
0
     "%s: invalid block tree node - not a branch node.",
405
0
     function );
406
407
0
    return( -1 );
408
0
  }
409
1.34M
  if( ( offset < block_tree_node->start_offset )
410
1.34M
   || ( offset >= block_tree_node->end_offset ) )
411
0
  {
412
0
    libcerror_error_set(
413
0
     error,
414
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
415
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
416
0
     "%s: invalid offset value out of bounds.",
417
0
     function );
418
419
0
    return( -1 );
420
0
  }
421
1.34M
  sub_node_index = ( offset - block_tree_node->start_offset ) / block_tree_node->sub_node_size;
422
423
1.34M
  if( ( sub_node_index < 0 )
424
1.34M
   || ( sub_node_index > (off64_t) INT_MAX ) )
425
0
  {
426
0
    libcerror_error_set(
427
0
     error,
428
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
429
0
     LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
430
0
     "%s: invalid sub node index value out of bounds.",
431
0
     function );
432
433
0
    return( -1 );
434
0
  }
435
1.34M
  if( libcdata_array_set_entry_by_index(
436
1.34M
       block_tree_node->sub_nodes_array,
437
1.34M
       (int) sub_node_index,
438
1.34M
       (intptr_t *) sub_block_tree_node,
439
1.34M
       error ) != 1 )
440
0
  {
441
0
    libcerror_error_set(
442
0
     error,
443
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
444
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
445
0
     "%s: unable to set sub node: %" PRIi64 ".",
446
0
     function,
447
0
     sub_node_index );
448
449
0
    return( -1 );
450
0
  }
451
1.34M
  return( 1 );
452
1.34M
}
453
454
/* Retrieves the leaf value for a specific offset
455
 * Returns 1 if successful or -1 on error
456
 */
457
int libpff_block_tree_node_get_leaf_value_at_offset(
458
     libpff_block_tree_node_t *block_tree_node,
459
     off64_t offset,
460
     libpff_block_descriptor_t **block_descriptor,
461
     off64_t *block_offset,
462
     libcerror_error_t **error )
463
2.15M
{
464
2.15M
  static char *function     = "libpff_block_tree_node_get_leaf_value_at_offset";
465
2.15M
  off64_t leaf_value_index  = 0;
466
2.15M
  off64_t safe_block_offset = 0;
467
468
2.15M
  if( block_tree_node == NULL )
469
0
  {
470
0
    libcerror_error_set(
471
0
     error,
472
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
473
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
474
0
     "%s: invalid block tree node.",
475
0
     function );
476
477
0
    return( -1 );
478
0
  }
479
2.15M
  if( block_tree_node->is_leaf_node == 0 )
480
0
  {
481
0
    libcerror_error_set(
482
0
     error,
483
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
484
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
485
0
     "%s: invalid block tree node - not a leaf node.",
486
0
     function );
487
488
0
    return( -1 );
489
0
  }
490
2.15M
  if( ( offset < block_tree_node->start_offset )
491
2.15M
   || ( offset >= block_tree_node->end_offset ) )
492
538
  {
493
538
    libcerror_error_set(
494
538
     error,
495
538
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
496
538
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
497
538
     "%s: invalid offset value out of bounds.",
498
538
     function );
499
500
538
    return( -1 );
501
538
  }
502
2.15M
  if( block_offset == NULL )
503
0
  {
504
0
    libcerror_error_set(
505
0
     error,
506
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
507
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
508
0
     "%s: invalid block offset.",
509
0
     function );
510
511
0
    return( -1 );
512
0
  }
513
2.15M
  safe_block_offset = offset - block_tree_node->start_offset;
514
515
2.15M
  leaf_value_index = safe_block_offset / block_tree_node->sub_node_size;
516
517
2.15M
  if( ( leaf_value_index < 0 )
518
2.15M
   || ( leaf_value_index > (off64_t) INT_MAX ) )
519
0
  {
520
0
    libcerror_error_set(
521
0
     error,
522
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
523
0
     LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
524
0
     "%s: invalid leaf value index value out of bounds.",
525
0
     function );
526
527
0
    return( -1 );
528
0
  }
529
2.15M
  if( libcdata_array_get_entry_by_index(
530
2.15M
       block_tree_node->sub_nodes_array,
531
2.15M
       (int) leaf_value_index,
532
2.15M
       (intptr_t **) block_descriptor,
533
2.15M
       error ) != 1 )
534
0
  {
535
0
    libcerror_error_set(
536
0
     error,
537
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
538
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
539
0
     "%s: unable to retrieve leaf value: %" PRIi64 ".",
540
0
     function,
541
0
     leaf_value_index );
542
543
0
    return( -1 );
544
0
  }
545
2.15M
  *block_offset = safe_block_offset - ( leaf_value_index * block_tree_node->sub_node_size );
546
547
2.15M
  return( 1 );
548
2.15M
}
549
550
/* Sets the leaf value for a specific offset
551
 * Returns 1 if successful or -1 on error
552
 */
553
int libpff_block_tree_node_set_leaf_value_at_offset(
554
     libpff_block_tree_node_t *block_tree_node,
555
     off64_t offset,
556
     libpff_block_descriptor_t *block_descriptor,
557
     libcerror_error_t **error )
558
2.15M
{
559
2.15M
  static char *function    = "libpff_block_tree_node_set_leaf_value_at_offset";
560
2.15M
  off64_t leaf_value_index = 0;
561
562
2.15M
  if( block_tree_node == NULL )
563
0
  {
564
0
    libcerror_error_set(
565
0
     error,
566
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
567
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
568
0
     "%s: invalid block tree node.",
569
0
     function );
570
571
0
    return( -1 );
572
0
  }
573
2.15M
  if( block_tree_node->is_leaf_node == 0 )
574
0
  {
575
0
    libcerror_error_set(
576
0
     error,
577
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
578
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
579
0
     "%s: invalid block tree node - not a leaf node.",
580
0
     function );
581
582
0
    return( -1 );
583
0
  }
584
2.15M
  if( ( offset < block_tree_node->start_offset )
585
2.15M
   || ( offset >= block_tree_node->end_offset ) )
586
0
  {
587
0
    libcerror_error_set(
588
0
     error,
589
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
590
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
591
0
     "%s: invalid offset value out of bounds.",
592
0
     function );
593
594
0
    return( -1 );
595
0
  }
596
2.15M
  leaf_value_index = ( offset - block_tree_node->start_offset ) / block_tree_node->sub_node_size;
597
598
2.15M
  if( ( leaf_value_index < 0 )
599
2.15M
   || ( leaf_value_index > (off64_t) INT_MAX ) )
600
0
  {
601
0
    libcerror_error_set(
602
0
     error,
603
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
604
0
     LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
605
0
     "%s: invalid leaf value index value out of bounds.",
606
0
     function );
607
608
0
    return( -1 );
609
0
  }
610
2.15M
  if( libcdata_array_set_entry_by_index(
611
2.15M
       block_tree_node->sub_nodes_array,
612
2.15M
       (int) leaf_value_index,
613
2.15M
       (intptr_t *) block_descriptor,
614
2.15M
       error ) != 1 )
615
0
  {
616
0
    libcerror_error_set(
617
0
     error,
618
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
619
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
620
0
     "%s: unable to set leaf value: %" PRIi64 ".",
621
0
     function,
622
0
     leaf_value_index );
623
624
0
    return( -1 );
625
0
  }
626
2.15M
  return( 1 );
627
2.15M
}
628