/src/libbde/libbde/libbde_ntfs_volume_header.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * The NTFS volume header functions |
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 <common.h> |
23 | | #include <byte_stream.h> |
24 | | #include <memory.h> |
25 | | #include <types.h> |
26 | | |
27 | | #include "libbde_libcerror.h" |
28 | | #include "libbde_libcnotify.h" |
29 | | #include "libbde_ntfs_volume_header.h" |
30 | | |
31 | | #include "bde_volume.h" |
32 | | |
33 | | /* Creates a NTFS volume header |
34 | | * Make sure the value ntfs_volume_header is referencing, is set to NULL |
35 | | * Returns 1 if successful or -1 on error |
36 | | */ |
37 | | int libbde_ntfs_volume_header_initialize( |
38 | | libbde_ntfs_volume_header_t **ntfs_volume_header, |
39 | | libcerror_error_t **error ) |
40 | 338 | { |
41 | 338 | static char *function = "libbde_ntfs_volume_header_initialize"; |
42 | | |
43 | 338 | if( ntfs_volume_header == NULL ) |
44 | 0 | { |
45 | 0 | libcerror_error_set( |
46 | 0 | error, |
47 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
48 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
49 | 0 | "%s: invalid NTFS volume header.", |
50 | 0 | function ); |
51 | |
|
52 | 0 | return( -1 ); |
53 | 0 | } |
54 | 338 | if( *ntfs_volume_header != NULL ) |
55 | 0 | { |
56 | 0 | libcerror_error_set( |
57 | 0 | error, |
58 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
59 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
60 | 0 | "%s: invalid NTFS volume header value already set.", |
61 | 0 | function ); |
62 | |
|
63 | 0 | return( -1 ); |
64 | 0 | } |
65 | 338 | *ntfs_volume_header = memory_allocate_structure( |
66 | 338 | libbde_ntfs_volume_header_t ); |
67 | | |
68 | 338 | if( *ntfs_volume_header == NULL ) |
69 | 0 | { |
70 | 0 | libcerror_error_set( |
71 | 0 | error, |
72 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
73 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
74 | 0 | "%s: unable to create NTFS volume header.", |
75 | 0 | function ); |
76 | |
|
77 | 0 | goto on_error; |
78 | 0 | } |
79 | 338 | if( memory_set( |
80 | 338 | *ntfs_volume_header, |
81 | 338 | 0, |
82 | 338 | sizeof( libbde_ntfs_volume_header_t ) ) == NULL ) |
83 | 0 | { |
84 | 0 | libcerror_error_set( |
85 | 0 | error, |
86 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
87 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
88 | 0 | "%s: unable to clear NTFS volume header.", |
89 | 0 | function ); |
90 | |
|
91 | 0 | goto on_error; |
92 | 0 | } |
93 | 338 | return( 1 ); |
94 | | |
95 | 0 | on_error: |
96 | 0 | if( *ntfs_volume_header != NULL ) |
97 | 0 | { |
98 | 0 | memory_free( |
99 | 0 | *ntfs_volume_header ); |
100 | |
|
101 | 0 | *ntfs_volume_header = NULL; |
102 | 0 | } |
103 | 0 | return( -1 ); |
104 | 338 | } |
105 | | |
106 | | /* Frees a NTFS volume header |
107 | | * Returns 1 if successful or -1 on error |
108 | | */ |
109 | | int libbde_ntfs_volume_header_free( |
110 | | libbde_ntfs_volume_header_t **ntfs_volume_header, |
111 | | libcerror_error_t **error ) |
112 | 338 | { |
113 | 338 | static char *function = "libbde_ntfs_volume_header_free"; |
114 | | |
115 | 338 | if( ntfs_volume_header == NULL ) |
116 | 0 | { |
117 | 0 | libcerror_error_set( |
118 | 0 | error, |
119 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
120 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
121 | 0 | "%s: invalid NTFS volume header.", |
122 | 0 | function ); |
123 | |
|
124 | 0 | return( -1 ); |
125 | 0 | } |
126 | 338 | if( *ntfs_volume_header != NULL ) |
127 | 338 | { |
128 | 338 | memory_free( |
129 | 338 | *ntfs_volume_header ); |
130 | | |
131 | 338 | *ntfs_volume_header = NULL; |
132 | 338 | } |
133 | 338 | return( 1 ); |
134 | 338 | } |
135 | | |
136 | | /* Reads the NTFS volume header |
137 | | * Returns 1 if successful or -1 on error |
138 | | */ |
139 | | int libbde_ntfs_volume_header_read_data( |
140 | | libbde_ntfs_volume_header_t *ntfs_volume_header, |
141 | | const uint8_t *data, |
142 | | size_t data_size, |
143 | | libcerror_error_t **error ) |
144 | 338 | { |
145 | 338 | static char *function = "libbde_ntfs_volume_header_read_data"; |
146 | 338 | uint64_t mft_cluster_block_number = 0; |
147 | 338 | uint64_t mirror_mft_cluster_block_number = 0; |
148 | 338 | uint32_t cluster_block_size = 0; |
149 | 338 | uint32_t index_entry_size = 0; |
150 | 338 | uint32_t mft_entry_size = 0; |
151 | | |
152 | | #if defined( HAVE_DEBUG_OUTPUT ) |
153 | | uint64_t value_64bit = 0; |
154 | | uint32_t value_32bit = 0; |
155 | | uint16_t value_16bit = 0; |
156 | | #endif |
157 | | |
158 | 338 | if( ntfs_volume_header == NULL ) |
159 | 0 | { |
160 | 0 | libcerror_error_set( |
161 | 0 | error, |
162 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
163 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
164 | 0 | "%s: invalid NTFS volume header.", |
165 | 0 | function ); |
166 | |
|
167 | 0 | return( -1 ); |
168 | 0 | } |
169 | 338 | if( data == NULL ) |
170 | 0 | { |
171 | 0 | libcerror_error_set( |
172 | 0 | error, |
173 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
174 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
175 | 0 | "%s: invalid data.", |
176 | 0 | function ); |
177 | |
|
178 | 0 | return( -1 ); |
179 | 0 | } |
180 | 338 | if( ( data_size < sizeof( bde_ntfs_volume_header_t ) ) |
181 | 338 | || ( data_size > (size_t) SSIZE_MAX ) ) |
182 | 0 | { |
183 | 0 | libcerror_error_set( |
184 | 0 | error, |
185 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
186 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
187 | 0 | "%s: invalid data size value out of bounds.", |
188 | 0 | function ); |
189 | |
|
190 | 0 | return( -1 ); |
191 | 0 | } |
192 | | #if defined( HAVE_DEBUG_OUTPUT ) |
193 | | if( libcnotify_verbose != 0 ) |
194 | | { |
195 | | libcnotify_printf( |
196 | | "%s: NTFS volume header data:\n", |
197 | | function ); |
198 | | libcnotify_print_data( |
199 | | data, |
200 | | sizeof( bde_ntfs_volume_header_t ), |
201 | | LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); |
202 | | } |
203 | | #endif |
204 | 338 | if( memory_compare( |
205 | 338 | ( (bde_ntfs_volume_header_t *) data )->file_system_signature, |
206 | 338 | "NTFS ", |
207 | 338 | 8 ) != 0 ) |
208 | 11 | { |
209 | 11 | libcerror_error_set( |
210 | 11 | error, |
211 | 11 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
212 | 11 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
213 | 11 | "%s: invalid volume system signature.", |
214 | 11 | function ); |
215 | | |
216 | 11 | return( -1 ); |
217 | 11 | } |
218 | 327 | byte_stream_copy_to_uint16_little_endian( |
219 | 327 | ( (bde_ntfs_volume_header_t *) data )->bytes_per_sector, |
220 | 327 | ntfs_volume_header->bytes_per_sector ); |
221 | | |
222 | 327 | byte_stream_copy_to_uint64_little_endian( |
223 | 327 | ( (bde_ntfs_volume_header_t *) data )->total_number_of_sectors, |
224 | 327 | ntfs_volume_header->volume_size ); |
225 | | |
226 | 327 | byte_stream_copy_to_uint64_little_endian( |
227 | 327 | ( (bde_ntfs_volume_header_t *) data )->mft_cluster_block_number, |
228 | 327 | mft_cluster_block_number ); |
229 | | |
230 | 327 | byte_stream_copy_to_uint64_little_endian( |
231 | 327 | ( (bde_ntfs_volume_header_t *) data )->mirror_mft_cluster_block_number, |
232 | 327 | mirror_mft_cluster_block_number ); |
233 | | |
234 | 327 | byte_stream_copy_to_uint32_little_endian( |
235 | 327 | ( (bde_ntfs_volume_header_t *) data )->mft_entry_size, |
236 | 327 | mft_entry_size ); |
237 | | |
238 | 327 | byte_stream_copy_to_uint32_little_endian( |
239 | 327 | ( (bde_ntfs_volume_header_t *) data )->index_entry_size, |
240 | 327 | index_entry_size ); |
241 | | |
242 | | #if defined( HAVE_DEBUG_OUTPUT ) |
243 | | if( libcnotify_verbose != 0 ) |
244 | | { |
245 | | libcnotify_printf( |
246 | | "%s: boot entry point\t\t\t: 0x%02x 0x%02x 0x%02x\n", |
247 | | function, |
248 | | ( (bde_ntfs_volume_header_t *) data )->boot_entry_point[ 0 ], |
249 | | ( (bde_ntfs_volume_header_t *) data )->boot_entry_point[ 1 ], |
250 | | ( (bde_ntfs_volume_header_t *) data )->boot_entry_point[ 2 ] ); |
251 | | |
252 | | libcnotify_printf( |
253 | | "%s: file system signature\t\t: %c%c%c%c%c%c%c%c\n", |
254 | | function, |
255 | | ( (bde_ntfs_volume_header_t *) data )->file_system_signature[ 0 ], |
256 | | ( (bde_ntfs_volume_header_t *) data )->file_system_signature[ 1 ], |
257 | | ( (bde_ntfs_volume_header_t *) data )->file_system_signature[ 2 ], |
258 | | ( (bde_ntfs_volume_header_t *) data )->file_system_signature[ 3 ], |
259 | | ( (bde_ntfs_volume_header_t *) data )->file_system_signature[ 4 ], |
260 | | ( (bde_ntfs_volume_header_t *) data )->file_system_signature[ 5 ], |
261 | | ( (bde_ntfs_volume_header_t *) data )->file_system_signature[ 6 ], |
262 | | ( (bde_ntfs_volume_header_t *) data )->file_system_signature[ 7 ] ); |
263 | | |
264 | | libcnotify_printf( |
265 | | "%s: bytes per sector\t\t\t: %" PRIu16 "\n", |
266 | | function, |
267 | | ntfs_volume_header->bytes_per_sector ); |
268 | | |
269 | | libcnotify_printf( |
270 | | "%s: sectors per cluster block\t\t: %" PRIu8 "\n", |
271 | | function, |
272 | | ( (bde_ntfs_volume_header_t *) data )->sectors_per_cluster_block ); |
273 | | |
274 | | libcnotify_printf( |
275 | | "%s: unknown1\n", |
276 | | function ); |
277 | | libcnotify_print_data( |
278 | | ( (bde_ntfs_volume_header_t *) data )->unknown1, |
279 | | 7, |
280 | | 0 ); |
281 | | |
282 | | libcnotify_printf( |
283 | | "%s: media descriptor\t\t\t: 0x%02" PRIx8 "\n", |
284 | | function, |
285 | | ( (bde_ntfs_volume_header_t *) data )->media_descriptor ); |
286 | | |
287 | | byte_stream_copy_to_uint16_little_endian( |
288 | | ( (bde_ntfs_volume_header_t *) data )->unknown2, |
289 | | value_16bit ); |
290 | | libcnotify_printf( |
291 | | "%s: unknown2\t\t\t\t: %" PRIu16 "\n", |
292 | | function, |
293 | | value_16bit ); |
294 | | |
295 | | byte_stream_copy_to_uint16_little_endian( |
296 | | ( (bde_ntfs_volume_header_t *) data )->sectors_per_track, |
297 | | value_16bit ); |
298 | | libcnotify_printf( |
299 | | "%s: sectors per track\t\t\t: %" PRIu16 "\n", |
300 | | function, |
301 | | value_16bit ); |
302 | | |
303 | | byte_stream_copy_to_uint16_little_endian( |
304 | | ( (bde_ntfs_volume_header_t *) data )->number_of_heads, |
305 | | value_16bit ); |
306 | | libcnotify_printf( |
307 | | "%s: number of heads\t\t\t: %" PRIu16 "\n", |
308 | | function, |
309 | | value_16bit ); |
310 | | |
311 | | byte_stream_copy_to_uint32_little_endian( |
312 | | ( (bde_ntfs_volume_header_t *) data )->number_of_hidden_sectors, |
313 | | value_32bit ); |
314 | | libcnotify_printf( |
315 | | "%s: number of hidden sectors\t\t: %" PRIu32 "\n", |
316 | | function, |
317 | | value_32bit ); |
318 | | |
319 | | byte_stream_copy_to_uint32_little_endian( |
320 | | ( (bde_ntfs_volume_header_t *) data )->unknown3, |
321 | | value_32bit ); |
322 | | libcnotify_printf( |
323 | | "%s: unknown3\t\t\t\t: 0x%08" PRIx32 " (%" PRIu32 ")\n", |
324 | | function, |
325 | | value_32bit, |
326 | | value_32bit ); |
327 | | |
328 | | byte_stream_copy_to_uint32_little_endian( |
329 | | ( (bde_ntfs_volume_header_t *) data )->unknown4, |
330 | | value_32bit ); |
331 | | libcnotify_printf( |
332 | | "%s: unknown4\t\t\t\t: 0x%08" PRIx32 " (%" PRIu32 ")\n", |
333 | | function, |
334 | | value_32bit, |
335 | | value_32bit ); |
336 | | |
337 | | libcnotify_printf( |
338 | | "%s: total number of sectors\t\t: %" PRIu64 "\n", |
339 | | function, |
340 | | ntfs_volume_header->volume_size ); |
341 | | |
342 | | libcnotify_printf( |
343 | | "%s: MFT cluster block number\t\t: %" PRIu64 "\n", |
344 | | function, |
345 | | mft_cluster_block_number ); |
346 | | |
347 | | libcnotify_printf( |
348 | | "%s: mirror MFT cluster block number\t: %" PRIu64 "\n", |
349 | | function, |
350 | | mirror_mft_cluster_block_number ); |
351 | | |
352 | | libcnotify_printf( |
353 | | "%s: MFT entry size\t\t\t: %" PRIu32 "\n", |
354 | | function, |
355 | | mft_entry_size ); |
356 | | |
357 | | libcnotify_printf( |
358 | | "%s: index entry size\t\t\t: %" PRIu32 "\n", |
359 | | function, |
360 | | index_entry_size ); |
361 | | |
362 | | byte_stream_copy_to_uint64_little_endian( |
363 | | ( (bde_ntfs_volume_header_t *) data )->volume_serial_number, |
364 | | value_64bit ); |
365 | | libcnotify_printf( |
366 | | "%s: volume serial number\t\t: 0x%08" PRIx64 "\n", |
367 | | function, |
368 | | value_64bit ); |
369 | | |
370 | | byte_stream_copy_to_uint32_little_endian( |
371 | | ( (bde_ntfs_volume_header_t *) data )->checksum, |
372 | | value_32bit ); |
373 | | libcnotify_printf( |
374 | | "%s: checksum\t\t\t\t: 0x%08" PRIx32 "\n", |
375 | | function, |
376 | | value_32bit ); |
377 | | |
378 | | libcnotify_printf( |
379 | | "%s: bootcode\n", |
380 | | function ); |
381 | | libcnotify_print_data( |
382 | | ( (bde_ntfs_volume_header_t *) data )->bootcode, |
383 | | 426, |
384 | | 0 ); |
385 | | |
386 | | byte_stream_copy_to_uint16_little_endian( |
387 | | ( (bde_ntfs_volume_header_t *) data )->sector_signature, |
388 | | value_16bit ); |
389 | | libcnotify_printf( |
390 | | "%s: sector signature\t\t\t: 0x%04" PRIx16 "\n", |
391 | | function, |
392 | | value_16bit ); |
393 | | |
394 | | libcnotify_printf( |
395 | | "\n" ); |
396 | | } |
397 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
398 | | |
399 | 327 | if( ( ntfs_volume_header->bytes_per_sector != 256 ) |
400 | 327 | && ( ntfs_volume_header->bytes_per_sector != 512 ) |
401 | 327 | && ( ntfs_volume_header->bytes_per_sector != 1024 ) |
402 | 327 | && ( ntfs_volume_header->bytes_per_sector != 2048 ) |
403 | 327 | && ( ntfs_volume_header->bytes_per_sector != 4096 ) ) |
404 | 46 | { |
405 | 46 | libcerror_error_set( |
406 | 46 | error, |
407 | 46 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
408 | 46 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
409 | 46 | "%s: unsupported bytes per sector: %" PRIu16 ".", |
410 | 46 | function, |
411 | 46 | ntfs_volume_header->bytes_per_sector ); |
412 | | |
413 | 46 | return( -1 ); |
414 | 46 | } |
415 | 281 | cluster_block_size = ( (bde_ntfs_volume_header_t *) data )->sectors_per_cluster_block; |
416 | | |
417 | 281 | if( cluster_block_size > 128 ) |
418 | 142 | { |
419 | | /* The size is calculated as: 2 ^ ( 256 - value ) |
420 | | */ |
421 | 142 | cluster_block_size = 256 - cluster_block_size; |
422 | | |
423 | 142 | if( cluster_block_size > 12 ) |
424 | 8 | { |
425 | 8 | libcerror_error_set( |
426 | 8 | error, |
427 | 8 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
428 | 8 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
429 | 8 | "%s: invalid cluster block size value out of bounds.", |
430 | 8 | function ); |
431 | | |
432 | 8 | return( -1 ); |
433 | 8 | } |
434 | 134 | cluster_block_size = 1 << cluster_block_size; |
435 | 134 | } |
436 | 273 | cluster_block_size *= ntfs_volume_header->bytes_per_sector; |
437 | | |
438 | 273 | if( ( cluster_block_size != 256 ) |
439 | 273 | && ( cluster_block_size != 512 ) |
440 | 273 | && ( cluster_block_size != 1024 ) |
441 | 273 | && ( cluster_block_size != 2048 ) |
442 | 273 | && ( cluster_block_size != 4096 ) |
443 | 273 | && ( cluster_block_size != 8192 ) |
444 | 273 | && ( cluster_block_size != 16384 ) |
445 | 273 | && ( cluster_block_size != 32768 ) |
446 | 273 | && ( cluster_block_size != 65536 ) |
447 | 273 | && ( cluster_block_size != 131072 ) |
448 | 273 | && ( cluster_block_size != 262144 ) |
449 | 273 | && ( cluster_block_size != 524288 ) |
450 | 273 | && ( cluster_block_size != 1048576 ) |
451 | 273 | && ( cluster_block_size != 2097152 ) ) |
452 | 45 | { |
453 | 45 | libcerror_error_set( |
454 | 45 | error, |
455 | 45 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
456 | 45 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
457 | 45 | "%s: unsupported cluster block size: %" PRIu32 ".", |
458 | 45 | function, |
459 | 45 | cluster_block_size ); |
460 | | |
461 | 45 | return( -1 ); |
462 | 45 | } |
463 | 228 | if( ( mft_entry_size == 0 ) |
464 | 228 | || ( mft_entry_size > 255 ) ) |
465 | 43 | { |
466 | 43 | libcerror_error_set( |
467 | 43 | error, |
468 | 43 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
469 | 43 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
470 | 43 | "%s: unsupported MFT entry size: %" PRIu32 ".", |
471 | 43 | function, |
472 | 43 | mft_entry_size ); |
473 | | |
474 | 43 | return( -1 ); |
475 | 43 | } |
476 | 185 | if( mft_entry_size < 128 ) |
477 | 146 | { |
478 | 146 | if( mft_entry_size >= (size32_t) ( ( UINT32_MAX / cluster_block_size ) + 1 ) ) |
479 | 0 | { |
480 | 0 | libcerror_error_set( |
481 | 0 | error, |
482 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
483 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
484 | 0 | "%s: invalid MFT entry size value out of bounds.", |
485 | 0 | function ); |
486 | |
|
487 | 0 | return( -1 ); |
488 | 0 | } |
489 | 146 | mft_entry_size *= cluster_block_size; |
490 | 146 | } |
491 | 39 | else |
492 | 39 | { |
493 | | /* The size is calculated as: 2 ^ ( 256 - value ) |
494 | | */ |
495 | 39 | mft_entry_size = 256 - mft_entry_size; |
496 | | |
497 | 39 | if( mft_entry_size >= 32 ) |
498 | 7 | { |
499 | 7 | libcerror_error_set( |
500 | 7 | error, |
501 | 7 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
502 | 7 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
503 | 7 | "%s: invalid MFT entry size value out of bounds.", |
504 | 7 | function ); |
505 | | |
506 | 7 | return( -1 ); |
507 | 7 | } |
508 | 32 | mft_entry_size = (uint32_t) 1UL << mft_entry_size; |
509 | 32 | } |
510 | 178 | if( ( (size_t) mft_entry_size < 42 ) |
511 | 178 | || ( mft_entry_size >= (uint32_t) MEMORY_MAXIMUM_ALLOCATION_SIZE ) ) |
512 | 4 | { |
513 | 4 | libcerror_error_set( |
514 | 4 | error, |
515 | 4 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
516 | 4 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
517 | 4 | "%s: invalid MFT entry size: %" PRIu32 " value out of bounds.", |
518 | 4 | function, |
519 | 4 | mft_entry_size ); |
520 | | |
521 | 4 | return( -1 ); |
522 | 4 | } |
523 | 174 | if( ( index_entry_size == 0 ) |
524 | 174 | || ( index_entry_size > 255 ) ) |
525 | 43 | { |
526 | 43 | libcerror_error_set( |
527 | 43 | error, |
528 | 43 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
529 | 43 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
530 | 43 | "%s: unsupported index entry size: %" PRIu32 ".", |
531 | 43 | function, |
532 | 43 | index_entry_size ); |
533 | | |
534 | 43 | return( -1 ); |
535 | 43 | } |
536 | 131 | if( index_entry_size < 128 ) |
537 | 92 | { |
538 | 92 | if( index_entry_size >= (size32_t) ( ( UINT32_MAX / cluster_block_size ) + 1 ) ) |
539 | 0 | { |
540 | 0 | libcerror_error_set( |
541 | 0 | error, |
542 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
543 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
544 | 0 | "%s: invalid index entry size value out of bounds.", |
545 | 0 | function ); |
546 | |
|
547 | 0 | return( -1 ); |
548 | 0 | } |
549 | 92 | index_entry_size *= cluster_block_size; |
550 | 92 | } |
551 | 39 | else |
552 | 39 | { |
553 | | /* The size is calculated as: 2 ^ ( 256 - value ) |
554 | | */ |
555 | 39 | index_entry_size = 256 - index_entry_size; |
556 | | |
557 | 39 | if( index_entry_size >= 32 ) |
558 | 10 | { |
559 | 10 | libcerror_error_set( |
560 | 10 | error, |
561 | 10 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
562 | 10 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
563 | 10 | "%s: invalid index entry size value out of bounds.", |
564 | 10 | function ); |
565 | | |
566 | 10 | return( -1 ); |
567 | 10 | } |
568 | 29 | index_entry_size = (uint32_t) 1UL << index_entry_size; |
569 | 29 | } |
570 | 121 | if( (size_t) index_entry_size < 32 ) |
571 | 2 | { |
572 | 2 | libcerror_error_set( |
573 | 2 | error, |
574 | 2 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
575 | 2 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
576 | 2 | "%s: invalid MFT entry size: %" PRIu32 " value out of bounds.", |
577 | 2 | function, |
578 | 2 | index_entry_size ); |
579 | | |
580 | 2 | return( -1 ); |
581 | 2 | } |
582 | 119 | if( ntfs_volume_header->volume_size > (size64_t) ( ( UINT64_MAX / ntfs_volume_header->bytes_per_sector ) + 1 ) ) |
583 | 67 | { |
584 | 67 | libcerror_error_set( |
585 | 67 | error, |
586 | 67 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
587 | 67 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
588 | 67 | "%s: invalid volume size value out of bounds.", |
589 | 67 | function ); |
590 | | |
591 | 67 | return( -1 ); |
592 | 67 | } |
593 | 52 | ntfs_volume_header->volume_size *= ntfs_volume_header->bytes_per_sector; |
594 | 52 | ntfs_volume_header->volume_size += ntfs_volume_header->bytes_per_sector; |
595 | | |
596 | | #if defined( HAVE_DEBUG_OUTPUT ) |
597 | | if( libcnotify_verbose != 0 ) |
598 | | { |
599 | | libcnotify_printf( |
600 | | "%s: calculated cluster block size\t: %" PRIu32 "\n", |
601 | | function, |
602 | | cluster_block_size ); |
603 | | |
604 | | libcnotify_printf( |
605 | | "%s: calculated MFT entry size\t\t: %" PRIu32 "\n", |
606 | | function, |
607 | | mft_entry_size ); |
608 | | |
609 | | libcnotify_printf( |
610 | | "%s: calculated index entry size\t: %" PRIu32 "\n", |
611 | | function, |
612 | | index_entry_size ); |
613 | | |
614 | | libcnotify_printf( |
615 | | "%s: calculated volume size\t\t: %" PRIu64 "\n", |
616 | | function, |
617 | | ntfs_volume_header->volume_size ); |
618 | | |
619 | | libcnotify_printf( |
620 | | "\n" ); |
621 | | } |
622 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
623 | | |
624 | 52 | return( 1 ); |
625 | 119 | } |
626 | | |