1*3b35e7eeSXin LI // SPDX-License-Identifier: 0BSD 2*3b35e7eeSXin LI 381ad8388SMartin Matuska /////////////////////////////////////////////////////////////////////////////// 481ad8388SMartin Matuska // 581ad8388SMartin Matuska /// \file block_encoder.h 681ad8388SMartin Matuska /// \brief Encodes .xz Blocks 781ad8388SMartin Matuska // 881ad8388SMartin Matuska // Author: Lasse Collin 981ad8388SMartin Matuska // 1081ad8388SMartin Matuska /////////////////////////////////////////////////////////////////////////////// 1181ad8388SMartin Matuska 1281ad8388SMartin Matuska #ifndef LZMA_BLOCK_ENCODER_H 1381ad8388SMartin Matuska #define LZMA_BLOCK_ENCODER_H 1481ad8388SMartin Matuska 1581ad8388SMartin Matuska #include "common.h" 1681ad8388SMartin Matuska 1781ad8388SMartin Matuska 1881ad8388SMartin Matuska /// \brief Biggest Compressed Size value that the Block encoder supports 1981ad8388SMartin Matuska /// 2081ad8388SMartin Matuska /// The maximum size of a single Block is limited by the maximum size of 2181ad8388SMartin Matuska /// a Stream, which in theory is 2^63 - 3 bytes (i.e. LZMA_VLI_MAX - 3). 2281ad8388SMartin Matuska /// While the size is really big and no one should hit it in practice, we 2381ad8388SMartin Matuska /// take it into account in some places anyway to catch some errors e.g. if 2481ad8388SMartin Matuska /// application passes insanely big value to some function. 2581ad8388SMartin Matuska /// 2681ad8388SMartin Matuska /// We could take into account the headers etc. to determine the exact 2781ad8388SMartin Matuska /// maximum size of the Compressed Data field, but the complexity would give 2881ad8388SMartin Matuska /// us nothing useful. Instead, limit the size of Compressed Data so that 2981ad8388SMartin Matuska /// even with biggest possible Block Header and Check fields the total 3081ad8388SMartin Matuska /// encoded size of the Block stays as a valid VLI. This doesn't guarantee 3181ad8388SMartin Matuska /// that the size of the Stream doesn't grow too big, but that problem is 3281ad8388SMartin Matuska /// taken care outside the Block handling code. 3381ad8388SMartin Matuska /// 3481ad8388SMartin Matuska /// ~LZMA_VLI_C(3) is to guarantee that if we need padding at the end of 3581ad8388SMartin Matuska /// the Compressed Data field, it will still stay in the proper limit. 3681ad8388SMartin Matuska /// 3781ad8388SMartin Matuska /// This constant is in this file because it is needed in both 3881ad8388SMartin Matuska /// block_encoder.c and block_buffer_encoder.c. 3981ad8388SMartin Matuska #define COMPRESSED_SIZE_MAX ((LZMA_VLI_MAX - LZMA_BLOCK_HEADER_SIZE_MAX \ 4081ad8388SMartin Matuska - LZMA_CHECK_SIZE_MAX) & ~LZMA_VLI_C(3)) 4181ad8388SMartin Matuska 4281ad8388SMartin Matuska 4381ad8388SMartin Matuska extern lzma_ret lzma_block_encoder_init(lzma_next_coder *next, 4453200025SRui Paulo const lzma_allocator *allocator, lzma_block *block); 4581ad8388SMartin Matuska 4681ad8388SMartin Matuska #endif 47