| OLD | NEW |
| 1 /////////////////////////////////////////////////////////////////////////////// | 1 /////////////////////////////////////////////////////////////////////////////// |
| 2 // | 2 // |
| 3 /// \file list.c | 3 /// \file list.c |
| 4 /// \brief Listing information about .xz files | 4 /// \brief Listing information about .xz files |
| 5 // | 5 // |
| 6 // Author: Lasse Collin | 6 // Author: Lasse Collin |
| 7 // | 7 // |
| 8 // This file has been put into the public domain. | 8 // This file has been put into the public domain. |
| 9 // You can do whatever you want with this file. | 9 // You can do whatever you want with this file. |
| 10 // | 10 // |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 - lzma_check_size(iter->stream.flags->check), | 375 - lzma_check_size(iter->stream.flags->check), |
| 376 LZMA_BLOCK_HEADER_SIZE_MAX); | 376 LZMA_BLOCK_HEADER_SIZE_MAX); |
| 377 io_buf buf; | 377 io_buf buf; |
| 378 if (io_pread(pair, &buf, size, iter->block.compressed_file_offset)) | 378 if (io_pread(pair, &buf, size, iter->block.compressed_file_offset)) |
| 379 return true; | 379 return true; |
| 380 | 380 |
| 381 // Zero would mean Index Indicator and thus not a valid Block. | 381 // Zero would mean Index Indicator and thus not a valid Block. |
| 382 if (buf.u8[0] == 0) | 382 if (buf.u8[0] == 0) |
| 383 goto data_error; | 383 goto data_error; |
| 384 | 384 |
| 385 // Initialize the block structure and decode Block Header Size. |
| 386 lzma_filter filters[LZMA_FILTERS_MAX + 1]; |
| 385 lzma_block block; | 387 lzma_block block; |
| 386 lzma_filter filters[LZMA_FILTERS_MAX + 1]; | |
| 387 | |
| 388 // Initialize the pointers so that they can be passed to free(). | |
| 389 for (size_t i = 0; i < ARRAY_SIZE(filters); ++i) | |
| 390 filters[i].options = NULL; | |
| 391 | |
| 392 // Initialize the block structure and decode Block Header Size. | |
| 393 block.version = 0; | 388 block.version = 0; |
| 394 block.check = iter->stream.flags->check; | 389 block.check = iter->stream.flags->check; |
| 395 block.filters = filters; | 390 block.filters = filters; |
| 396 | 391 |
| 397 block.header_size = lzma_block_header_size_decode(buf.u8[0]); | 392 block.header_size = lzma_block_header_size_decode(buf.u8[0]); |
| 398 if (block.header_size > size) | 393 if (block.header_size > size) |
| 399 goto data_error; | 394 goto data_error; |
| 400 | 395 |
| 401 // Decode the Block Header. | 396 // Decode the Block Header. |
| 402 switch (lzma_block_header_decode(&block, NULL, buf.u8)) { | 397 switch (lzma_block_header_decode(&block, NULL, buf.u8)) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 430 xfi->all_have_sizes &= block.compressed_size != LZMA_VLI_UNKNOWN | 425 xfi->all_have_sizes &= block.compressed_size != LZMA_VLI_UNKNOWN |
| 431 && block.uncompressed_size != LZMA_VLI_UNKNOWN; | 426 && block.uncompressed_size != LZMA_VLI_UNKNOWN; |
| 432 | 427 |
| 433 // Validate or set block.compressed_size. | 428 // Validate or set block.compressed_size. |
| 434 switch (lzma_block_compressed_size(&block, | 429 switch (lzma_block_compressed_size(&block, |
| 435 iter->block.unpadded_size)) { | 430 iter->block.unpadded_size)) { |
| 436 case LZMA_OK: | 431 case LZMA_OK: |
| 437 break; | 432 break; |
| 438 | 433 |
| 439 case LZMA_DATA_ERROR: | 434 case LZMA_DATA_ERROR: |
| 435 // Free the memory allocated by lzma_block_header_decode(). |
| 436 for (size_t i = 0; filters[i].id != LZMA_VLI_UNKNOWN; ++i) |
| 437 free(filters[i].options); |
| 438 |
| 440 goto data_error; | 439 goto data_error; |
| 441 | 440 |
| 442 default: | 441 default: |
| 443 message_bug(); | 442 message_bug(); |
| 444 } | 443 } |
| 445 | 444 |
| 446 // Copy the known sizes. | 445 // Copy the known sizes. |
| 447 bhi->header_size = block.header_size; | 446 bhi->header_size = block.header_size; |
| 448 bhi->compressed_size = block.compressed_size; | 447 bhi->compressed_size = block.compressed_size; |
| 449 | 448 |
| 450 // Calculate the decoder memory usage and update the maximum | 449 // Calculate the decoder memory usage and update the maximum |
| 451 // memory usage of this Block. | 450 // memory usage of this Block. |
| 452 bhi->memusage = lzma_raw_decoder_memusage(filters); | 451 bhi->memusage = lzma_raw_decoder_memusage(filters); |
| 453 if (xfi->memusage_max < bhi->memusage) | 452 if (xfi->memusage_max < bhi->memusage) |
| 454 xfi->memusage_max = bhi->memusage; | 453 xfi->memusage_max = bhi->memusage; |
| 455 | 454 |
| 456 // Convert the filter chain to human readable form. | 455 // Convert the filter chain to human readable form. |
| 457 message_filters_to_str(bhi->filter_chain, filters, false); | 456 message_filters_to_str(bhi->filter_chain, filters, false); |
| 458 | 457 |
| 459 // Free the memory allocated by lzma_block_header_decode(). | 458 // Free the memory allocated by lzma_block_header_decode(). |
| 460 for (size_t i = 0; filters[i].id != LZMA_VLI_UNKNOWN; ++i) | 459 for (size_t i = 0; filters[i].id != LZMA_VLI_UNKNOWN; ++i) |
| 461 free(filters[i].options); | 460 free(filters[i].options); |
| 462 | 461 |
| 463 return false; | 462 return false; |
| 464 | 463 |
| 465 data_error: | 464 data_error: |
| 466 // Show the error message. | 465 // Show the error message. |
| 467 message_error("%s: %s", pair->src_name, | 466 message_error("%s: %s", pair->src_name, |
| 468 message_strm(LZMA_DATA_ERROR)); | 467 message_strm(LZMA_DATA_ERROR)); |
| 469 | |
| 470 // Free the memory allocated by lzma_block_header_decode(). | |
| 471 // This is truly needed only if we get here after a succcessful | |
| 472 // call to lzma_block_header_decode() but it doesn't hurt to | |
| 473 // always do it. | |
| 474 for (size_t i = 0; filters[i].id != LZMA_VLI_UNKNOWN; ++i) | |
| 475 free(filters[i].options); | |
| 476 | |
| 477 return true; | 468 return true; |
| 478 } | 469 } |
| 479 | 470 |
| 480 | 471 |
| 481 /// \brief Parse the Check field and put it into check_value[] | 472 /// \brief Parse the Check field and put it into check_value[] |
| 482 /// | 473 /// |
| 483 /// \return False on success, true on error. | 474 /// \return False on success, true on error. |
| 484 static bool | 475 static bool |
| 485 parse_check_value(file_pair *pair, const lzma_index_iter *iter) | 476 parse_check_value(file_pair *pair, const lzma_index_iter *iter) |
| 486 { | 477 { |
| (...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1109 // broken files. | 1100 // broken files. |
| 1110 if (!fail) | 1101 if (!fail) |
| 1111 update_totals(&xfi); | 1102 update_totals(&xfi); |
| 1112 | 1103 |
| 1113 lzma_index_end(xfi.idx, NULL); | 1104 lzma_index_end(xfi.idx, NULL); |
| 1114 } | 1105 } |
| 1115 | 1106 |
| 1116 io_close(pair, false); | 1107 io_close(pair, false); |
| 1117 return; | 1108 return; |
| 1118 } | 1109 } |
| OLD | NEW |