block.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. /* SPDX-License-Identifier: 0BSD */
  2. /**
  3. * \file lzma/block.h
  4. * \brief .xz Block handling
  5. * \note Never include this file directly. Use <lzma.h> instead.
  6. */
  7. /*
  8. * Author: Lasse Collin
  9. */
  10. #ifndef LZMA_H_INTERNAL
  11. # error Never include this file directly. Use <lzma.h> instead.
  12. #endif
  13. /**
  14. * \brief Options for the Block and Block Header encoders and decoders
  15. *
  16. * Different Block handling functions use different parts of this structure.
  17. * Some read some members, other functions write, and some do both. Only the
  18. * members listed for reading need to be initialized when the specified
  19. * functions are called. The members marked for writing will be assigned
  20. * new values at some point either by calling the given function or by
  21. * later calls to lzma_code().
  22. */
  23. typedef struct {
  24. /**
  25. * \brief Block format version
  26. *
  27. * To prevent API and ABI breakages when new features are needed,
  28. * a version number is used to indicate which members in this
  29. * structure are in use:
  30. * - liblzma >= 5.0.0: version = 0 is supported.
  31. * - liblzma >= 5.1.4beta: Support for version = 1 was added,
  32. * which adds the ignore_check member.
  33. *
  34. * If version is greater than one, most Block related functions
  35. * will return LZMA_OPTIONS_ERROR (lzma_block_header_decode() works
  36. * with any version value).
  37. *
  38. * Read by:
  39. * - lzma_block_header_size()
  40. * - lzma_block_header_encode()
  41. * - lzma_block_header_decode()
  42. * - lzma_block_compressed_size()
  43. * - lzma_block_unpadded_size()
  44. * - lzma_block_total_size()
  45. * - lzma_block_encoder()
  46. * - lzma_block_decoder()
  47. * - lzma_block_buffer_encode()
  48. * - lzma_block_uncomp_encode()
  49. * - lzma_block_buffer_decode()
  50. *
  51. * Written by:
  52. * - lzma_block_header_decode()
  53. */
  54. uint32_t version;
  55. /**
  56. * \brief Size of the Block Header field in bytes
  57. *
  58. * This is always a multiple of four.
  59. *
  60. * Read by:
  61. * - lzma_block_header_encode()
  62. * - lzma_block_header_decode()
  63. * - lzma_block_compressed_size()
  64. * - lzma_block_unpadded_size()
  65. * - lzma_block_total_size()
  66. * - lzma_block_decoder()
  67. * - lzma_block_buffer_decode()
  68. *
  69. * Written by:
  70. * - lzma_block_header_size()
  71. * - lzma_block_buffer_encode()
  72. * - lzma_block_uncomp_encode()
  73. */
  74. uint32_t header_size;
  75. # define LZMA_BLOCK_HEADER_SIZE_MIN 8
  76. # define LZMA_BLOCK_HEADER_SIZE_MAX 1024
  77. /**
  78. * \brief Type of integrity Check
  79. *
  80. * The Check ID is not stored into the Block Header, thus its value
  81. * must be provided also when decoding.
  82. *
  83. * Read by:
  84. * - lzma_block_header_encode()
  85. * - lzma_block_header_decode()
  86. * - lzma_block_compressed_size()
  87. * - lzma_block_unpadded_size()
  88. * - lzma_block_total_size()
  89. * - lzma_block_encoder()
  90. * - lzma_block_decoder()
  91. * - lzma_block_buffer_encode()
  92. * - lzma_block_buffer_decode()
  93. */
  94. lzma_check check;
  95. /**
  96. * \brief Size of the Compressed Data in bytes
  97. *
  98. * Encoding: If this is not LZMA_VLI_UNKNOWN, Block Header encoder
  99. * will store this value to the Block Header. Block encoder doesn't
  100. * care about this value, but will set it once the encoding has been
  101. * finished.
  102. *
  103. * Decoding: If this is not LZMA_VLI_UNKNOWN, Block decoder will
  104. * verify that the size of the Compressed Data field matches
  105. * compressed_size.
  106. *
  107. * Usually you don't know this value when encoding in streamed mode,
  108. * and thus cannot write this field into the Block Header.
  109. *
  110. * In non-streamed mode you can reserve space for this field before
  111. * encoding the actual Block. After encoding the data, finish the
  112. * Block by encoding the Block Header. Steps in detail:
  113. *
  114. * - Set compressed_size to some big enough value. If you don't know
  115. * better, use LZMA_VLI_MAX, but remember that bigger values take
  116. * more space in Block Header.
  117. *
  118. * - Call lzma_block_header_size() to see how much space you need to
  119. * reserve for the Block Header.
  120. *
  121. * - Encode the Block using lzma_block_encoder() and lzma_code().
  122. * It sets compressed_size to the correct value.
  123. *
  124. * - Use lzma_block_header_encode() to encode the Block Header.
  125. * Because space was reserved in the first step, you don't need
  126. * to call lzma_block_header_size() anymore, because due to
  127. * reserving, header_size has to be big enough. If it is "too big",
  128. * lzma_block_header_encode() will add enough Header Padding to
  129. * make Block Header to match the size specified by header_size.
  130. *
  131. * Read by:
  132. * - lzma_block_header_size()
  133. * - lzma_block_header_encode()
  134. * - lzma_block_compressed_size()
  135. * - lzma_block_unpadded_size()
  136. * - lzma_block_total_size()
  137. * - lzma_block_decoder()
  138. * - lzma_block_buffer_decode()
  139. *
  140. * Written by:
  141. * - lzma_block_header_decode()
  142. * - lzma_block_compressed_size()
  143. * - lzma_block_encoder()
  144. * - lzma_block_decoder()
  145. * - lzma_block_buffer_encode()
  146. * - lzma_block_uncomp_encode()
  147. * - lzma_block_buffer_decode()
  148. */
  149. lzma_vli compressed_size;
  150. /**
  151. * \brief Uncompressed Size in bytes
  152. *
  153. * This is handled very similarly to compressed_size above.
  154. *
  155. * uncompressed_size is needed by fewer functions than
  156. * compressed_size. This is because uncompressed_size isn't
  157. * needed to validate that Block stays within proper limits.
  158. *
  159. * Read by:
  160. * - lzma_block_header_size()
  161. * - lzma_block_header_encode()
  162. * - lzma_block_decoder()
  163. * - lzma_block_buffer_decode()
  164. *
  165. * Written by:
  166. * - lzma_block_header_decode()
  167. * - lzma_block_encoder()
  168. * - lzma_block_decoder()
  169. * - lzma_block_buffer_encode()
  170. * - lzma_block_uncomp_encode()
  171. * - lzma_block_buffer_decode()
  172. */
  173. lzma_vli uncompressed_size;
  174. /**
  175. * \brief Array of filters
  176. *
  177. * There can be 1-4 filters. The end of the array is marked with
  178. * .id = LZMA_VLI_UNKNOWN.
  179. *
  180. * Read by:
  181. * - lzma_block_header_size()
  182. * - lzma_block_header_encode()
  183. * - lzma_block_encoder()
  184. * - lzma_block_decoder()
  185. * - lzma_block_buffer_encode()
  186. * - lzma_block_buffer_decode()
  187. *
  188. * Written by:
  189. * - lzma_block_header_decode(): Note that this does NOT free()
  190. * the old filter options structures. All unused filters[] will
  191. * have .id == LZMA_VLI_UNKNOWN and .options == NULL. If
  192. * decoding fails, all filters[] are guaranteed to be
  193. * LZMA_VLI_UNKNOWN and NULL.
  194. *
  195. * \note Because of the array is terminated with
  196. * .id = LZMA_VLI_UNKNOWN, the actual array must
  197. * have LZMA_FILTERS_MAX + 1 members or the Block
  198. * Header decoder will overflow the buffer.
  199. */
  200. lzma_filter *filters;
  201. /**
  202. * \brief Raw value stored in the Check field
  203. *
  204. * After successful coding, the first lzma_check_size(check) bytes
  205. * of this array contain the raw value stored in the Check field.
  206. *
  207. * Note that CRC32 and CRC64 are stored in little endian byte order.
  208. * Take it into account if you display the Check values to the user.
  209. *
  210. * Written by:
  211. * - lzma_block_encoder()
  212. * - lzma_block_decoder()
  213. * - lzma_block_buffer_encode()
  214. * - lzma_block_uncomp_encode()
  215. * - lzma_block_buffer_decode()
  216. */
  217. uint8_t raw_check[LZMA_CHECK_SIZE_MAX];
  218. /*
  219. * Reserved space to allow possible future extensions without
  220. * breaking the ABI. You should not touch these, because the names
  221. * of these variables may change. These are and will never be used
  222. * with the currently supported options, so it is safe to leave these
  223. * uninitialized.
  224. */
  225. /** \private Reserved member. */
  226. void *reserved_ptr1;
  227. /** \private Reserved member. */
  228. void *reserved_ptr2;
  229. /** \private Reserved member. */
  230. void *reserved_ptr3;
  231. /** \private Reserved member. */
  232. uint32_t reserved_int1;
  233. /** \private Reserved member. */
  234. uint32_t reserved_int2;
  235. /** \private Reserved member. */
  236. lzma_vli reserved_int3;
  237. /** \private Reserved member. */
  238. lzma_vli reserved_int4;
  239. /** \private Reserved member. */
  240. lzma_vli reserved_int5;
  241. /** \private Reserved member. */
  242. lzma_vli reserved_int6;
  243. /** \private Reserved member. */
  244. lzma_vli reserved_int7;
  245. /** \private Reserved member. */
  246. lzma_vli reserved_int8;
  247. /** \private Reserved member. */
  248. lzma_reserved_enum reserved_enum1;
  249. /** \private Reserved member. */
  250. lzma_reserved_enum reserved_enum2;
  251. /** \private Reserved member. */
  252. lzma_reserved_enum reserved_enum3;
  253. /** \private Reserved member. */
  254. lzma_reserved_enum reserved_enum4;
  255. /**
  256. * \brief A flag to Block decoder to not verify the Check field
  257. *
  258. * This member is supported by liblzma >= 5.1.4beta if .version >= 1.
  259. *
  260. * If this is set to true, the integrity check won't be calculated
  261. * and verified. Unless you know what you are doing, you should
  262. * leave this to false. (A reason to set this to true is when the
  263. * file integrity is verified externally anyway and you want to
  264. * speed up the decompression, which matters mostly when using
  265. * SHA-256 as the integrity check.)
  266. *
  267. * If .version >= 1, read by:
  268. * - lzma_block_decoder()
  269. * - lzma_block_buffer_decode()
  270. *
  271. * Written by (.version is ignored):
  272. * - lzma_block_header_decode() always sets this to false
  273. */
  274. lzma_bool ignore_check;
  275. /** \private Reserved member. */
  276. lzma_bool reserved_bool2;
  277. /** \private Reserved member. */
  278. lzma_bool reserved_bool3;
  279. /** \private Reserved member. */
  280. lzma_bool reserved_bool4;
  281. /** \private Reserved member. */
  282. lzma_bool reserved_bool5;
  283. /** \private Reserved member. */
  284. lzma_bool reserved_bool6;
  285. /** \private Reserved member. */
  286. lzma_bool reserved_bool7;
  287. /** \private Reserved member. */
  288. lzma_bool reserved_bool8;
  289. } lzma_block;
  290. /**
  291. * \brief Decode the Block Header Size field
  292. *
  293. * To decode Block Header using lzma_block_header_decode(), the size of the
  294. * Block Header has to be known and stored into lzma_block.header_size.
  295. * The size can be calculated from the first byte of a Block using this macro.
  296. * Note that if the first byte is 0x00, it indicates beginning of Index; use
  297. * this macro only when the byte is not 0x00.
  298. *
  299. * There is no encoding macro because lzma_block_header_size() and
  300. * lzma_block_header_encode() should be used.
  301. */
  302. #define lzma_block_header_size_decode(b) (((uint32_t)(b) + 1) * 4)
  303. /**
  304. * \brief Calculate Block Header Size
  305. *
  306. * Calculate the minimum size needed for the Block Header field using the
  307. * settings specified in the lzma_block structure. Note that it is OK to
  308. * increase the calculated header_size value as long as it is a multiple of
  309. * four and doesn't exceed LZMA_BLOCK_HEADER_SIZE_MAX. Increasing header_size
  310. * just means that lzma_block_header_encode() will add Header Padding.
  311. *
  312. * \note This doesn't check that all the options are valid i.e. this
  313. * may return LZMA_OK even if lzma_block_header_encode() or
  314. * lzma_block_encoder() would fail. If you want to validate the
  315. * filter chain, consider using lzma_memlimit_encoder() which as
  316. * a side-effect validates the filter chain.
  317. *
  318. * \param block Block options
  319. *
  320. * \return Possible lzma_ret values:
  321. * - LZMA_OK: Size calculated successfully and stored to
  322. * block->header_size.
  323. * - LZMA_OPTIONS_ERROR: Unsupported version, filters or
  324. * filter options.
  325. * - LZMA_PROG_ERROR: Invalid values like compressed_size == 0.
  326. */
  327. extern LZMA_API(lzma_ret) lzma_block_header_size(lzma_block *block)
  328. lzma_nothrow lzma_attr_warn_unused_result;
  329. /**
  330. * \brief Encode Block Header
  331. *
  332. * The caller must have calculated the size of the Block Header already with
  333. * lzma_block_header_size(). If a value larger than the one calculated by
  334. * lzma_block_header_size() is used, the Block Header will be padded to the
  335. * specified size.
  336. *
  337. * \param block Block options to be encoded.
  338. * \param[out] out Beginning of the output buffer. This must be
  339. * at least block->header_size bytes.
  340. *
  341. * \return Possible lzma_ret values:
  342. * - LZMA_OK: Encoding was successful. block->header_size
  343. * bytes were written to output buffer.
  344. * - LZMA_OPTIONS_ERROR: Invalid or unsupported options.
  345. * - LZMA_PROG_ERROR: Invalid arguments, for example
  346. * block->header_size is invalid or block->filters is NULL.
  347. */
  348. extern LZMA_API(lzma_ret) lzma_block_header_encode(
  349. const lzma_block *block, uint8_t *out)
  350. lzma_nothrow lzma_attr_warn_unused_result;
  351. /**
  352. * \brief Decode Block Header
  353. *
  354. * block->version should (usually) be set to the highest value supported
  355. * by the application. If the application sets block->version to a value
  356. * higher than supported by the current liblzma version, this function will
  357. * downgrade block->version to the highest value supported by it. Thus one
  358. * should check the value of block->version after calling this function if
  359. * block->version was set to a non-zero value and the application doesn't
  360. * otherwise know that the liblzma version being used is new enough to
  361. * support the specified block->version.
  362. *
  363. * The size of the Block Header must have already been decoded with
  364. * lzma_block_header_size_decode() macro and stored to block->header_size.
  365. *
  366. * The integrity check type from Stream Header must have been stored
  367. * to block->check.
  368. *
  369. * block->filters must have been allocated, but they don't need to be
  370. * initialized (possible existing filter options are not freed).
  371. *
  372. * \param[out] block Destination for Block options
  373. * \param allocator lzma_allocator for custom allocator functions.
  374. * Set to NULL to use malloc() (and also free()
  375. * if an error occurs).
  376. * \param in Beginning of the input buffer. This must be
  377. * at least block->header_size bytes.
  378. *
  379. * \return Possible lzma_ret values:
  380. * - LZMA_OK: Decoding was successful. block->header_size
  381. * bytes were read from the input buffer.
  382. * - LZMA_OPTIONS_ERROR: The Block Header specifies some
  383. * unsupported options such as unsupported filters. This can
  384. * happen also if block->version was set to a too low value
  385. * compared to what would be required to properly represent
  386. * the information stored in the Block Header.
  387. * - LZMA_DATA_ERROR: Block Header is corrupt, for example,
  388. * the CRC32 doesn't match.
  389. * - LZMA_PROG_ERROR: Invalid arguments, for example
  390. * block->header_size is invalid or block->filters is NULL.
  391. */
  392. extern LZMA_API(lzma_ret) lzma_block_header_decode(lzma_block *block,
  393. const lzma_allocator *allocator, const uint8_t *in)
  394. lzma_nothrow lzma_attr_warn_unused_result;
  395. /**
  396. * \brief Validate and set Compressed Size according to Unpadded Size
  397. *
  398. * Block Header stores Compressed Size, but Index has Unpadded Size. If the
  399. * application has already parsed the Index and is now decoding Blocks,
  400. * it can calculate Compressed Size from Unpadded Size. This function does
  401. * exactly that with error checking:
  402. *
  403. * - Compressed Size calculated from Unpadded Size must be positive integer,
  404. * that is, Unpadded Size must be big enough that after Block Header and
  405. * Check fields there's still at least one byte for Compressed Size.
  406. *
  407. * - If Compressed Size was present in Block Header, the new value
  408. * calculated from Unpadded Size is compared against the value
  409. * from Block Header.
  410. *
  411. * \note This function must be called _after_ decoding the Block Header
  412. * field so that it can properly validate Compressed Size if it
  413. * was present in Block Header.
  414. *
  415. * \param block Block options: block->header_size must
  416. * already be set with lzma_block_header_size().
  417. * \param unpadded_size Unpadded Size from the Index field in bytes
  418. *
  419. * \return Possible lzma_ret values:
  420. * - LZMA_OK: block->compressed_size was set successfully.
  421. * - LZMA_DATA_ERROR: unpadded_size is too small compared to
  422. * block->header_size and lzma_check_size(block->check).
  423. * - LZMA_PROG_ERROR: Some values are invalid. For example,
  424. * block->header_size must be a multiple of four and
  425. * between 8 and 1024 inclusive.
  426. */
  427. extern LZMA_API(lzma_ret) lzma_block_compressed_size(
  428. lzma_block *block, lzma_vli unpadded_size)
  429. lzma_nothrow lzma_attr_warn_unused_result;
  430. /**
  431. * \brief Calculate Unpadded Size
  432. *
  433. * The Index field stores Unpadded Size and Uncompressed Size. The latter
  434. * can be taken directly from the lzma_block structure after coding a Block,
  435. * but Unpadded Size needs to be calculated from Block Header Size,
  436. * Compressed Size, and size of the Check field. This is where this function
  437. * is needed.
  438. *
  439. * \param block Block options: block->header_size must already be
  440. * set with lzma_block_header_size().
  441. *
  442. * \return Unpadded Size on success, or zero on error.
  443. */
  444. extern LZMA_API(lzma_vli) lzma_block_unpadded_size(const lzma_block *block)
  445. lzma_nothrow lzma_attr_pure;
  446. /**
  447. * \brief Calculate the total encoded size of a Block
  448. *
  449. * This is equivalent to lzma_block_unpadded_size() except that the returned
  450. * value includes the size of the Block Padding field.
  451. *
  452. * \param block Block options: block->header_size must already be
  453. * set with lzma_block_header_size().
  454. *
  455. * \return On success, total encoded size of the Block. On error,
  456. * zero is returned.
  457. */
  458. extern LZMA_API(lzma_vli) lzma_block_total_size(const lzma_block *block)
  459. lzma_nothrow lzma_attr_pure;
  460. /**
  461. * \brief Initialize .xz Block encoder
  462. *
  463. * Valid actions for lzma_code() are LZMA_RUN, LZMA_SYNC_FLUSH (only if the
  464. * filter chain supports it), and LZMA_FINISH.
  465. *
  466. * The Block encoder encodes the Block Data, Block Padding, and Check value.
  467. * It does NOT encode the Block Header which can be encoded with
  468. * lzma_block_header_encode().
  469. *
  470. * \param strm Pointer to lzma_stream that is at least initialized
  471. * with LZMA_STREAM_INIT.
  472. * \param block Block options: block->version, block->check,
  473. * and block->filters must have been initialized.
  474. *
  475. * \return Possible lzma_ret values:
  476. * - LZMA_OK: All good, continue with lzma_code().
  477. * - LZMA_MEM_ERROR
  478. * - LZMA_OPTIONS_ERROR
  479. * - LZMA_UNSUPPORTED_CHECK: block->check specifies a Check ID
  480. * that is not supported by this build of liblzma. Initializing
  481. * the encoder failed.
  482. * - LZMA_PROG_ERROR
  483. */
  484. extern LZMA_API(lzma_ret) lzma_block_encoder(
  485. lzma_stream *strm, lzma_block *block)
  486. lzma_nothrow lzma_attr_warn_unused_result;
  487. /**
  488. * \brief Initialize .xz Block decoder
  489. *
  490. * Valid actions for lzma_code() are LZMA_RUN and LZMA_FINISH. Using
  491. * LZMA_FINISH is not required. It is supported only for convenience.
  492. *
  493. * The Block decoder decodes the Block Data, Block Padding, and Check value.
  494. * It does NOT decode the Block Header which can be decoded with
  495. * lzma_block_header_decode().
  496. *
  497. * \param strm Pointer to lzma_stream that is at least initialized
  498. * with LZMA_STREAM_INIT.
  499. * \param block Block options
  500. *
  501. * \return Possible lzma_ret values:
  502. * - LZMA_OK: All good, continue with lzma_code().
  503. * - LZMA_PROG_ERROR
  504. * - LZMA_MEM_ERROR
  505. */
  506. extern LZMA_API(lzma_ret) lzma_block_decoder(
  507. lzma_stream *strm, lzma_block *block)
  508. lzma_nothrow lzma_attr_warn_unused_result;
  509. /**
  510. * \brief Calculate maximum output size for single-call Block encoding
  511. *
  512. * This is equivalent to lzma_stream_buffer_bound() but for .xz Blocks.
  513. * See the documentation of lzma_stream_buffer_bound().
  514. *
  515. * \param uncompressed_size Size of the data to be encoded with the
  516. * single-call Block encoder.
  517. *
  518. * \return Maximum output size in bytes for single-call Block encoding.
  519. */
  520. extern LZMA_API(size_t) lzma_block_buffer_bound(size_t uncompressed_size)
  521. lzma_nothrow;
  522. /**
  523. * \brief Single-call .xz Block encoder
  524. *
  525. * In contrast to the multi-call encoder initialized with
  526. * lzma_block_encoder(), this function encodes also the Block Header. This
  527. * is required to make it possible to write appropriate Block Header also
  528. * in case the data isn't compressible, and different filter chain has to be
  529. * used to encode the data in uncompressed form using uncompressed chunks
  530. * of the LZMA2 filter.
  531. *
  532. * When the data isn't compressible, header_size, compressed_size, and
  533. * uncompressed_size are set just like when the data was compressible, but
  534. * it is possible that header_size is too small to hold the filter chain
  535. * specified in block->filters, because that isn't necessarily the filter
  536. * chain that was actually used to encode the data. lzma_block_unpadded_size()
  537. * still works normally, because it doesn't read the filters array.
  538. *
  539. * \param block Block options: block->version, block->check,
  540. * and block->filters must have been initialized.
  541. * \param allocator lzma_allocator for custom allocator functions.
  542. * Set to NULL to use malloc() and free().
  543. * \param in Beginning of the input buffer
  544. * \param in_size Size of the input buffer
  545. * \param[out] out Beginning of the output buffer
  546. * \param[out] out_pos The next byte will be written to out[*out_pos].
  547. * *out_pos is updated only if encoding succeeds.
  548. * \param out_size Size of the out buffer; the first byte into
  549. * which no data is written to is out[out_size].
  550. *
  551. * \return Possible lzma_ret values:
  552. * - LZMA_OK: Encoding was successful.
  553. * - LZMA_BUF_ERROR: Not enough output buffer space.
  554. * - LZMA_UNSUPPORTED_CHECK
  555. * - LZMA_OPTIONS_ERROR
  556. * - LZMA_MEM_ERROR
  557. * - LZMA_DATA_ERROR
  558. * - LZMA_PROG_ERROR
  559. */
  560. extern LZMA_API(lzma_ret) lzma_block_buffer_encode(
  561. lzma_block *block, const lzma_allocator *allocator,
  562. const uint8_t *in, size_t in_size,
  563. uint8_t *out, size_t *out_pos, size_t out_size)
  564. lzma_nothrow lzma_attr_warn_unused_result;
  565. /**
  566. * \brief Single-call uncompressed .xz Block encoder
  567. *
  568. * This is like lzma_block_buffer_encode() except this doesn't try to
  569. * compress the data and instead encodes the data using LZMA2 uncompressed
  570. * chunks. The required output buffer size can be determined with
  571. * lzma_block_buffer_bound().
  572. *
  573. * Since the data won't be compressed, this function ignores block->filters.
  574. * This function doesn't take lzma_allocator because this function doesn't
  575. * allocate any memory from the heap.
  576. *
  577. * \param block Block options: block->version, block->check,
  578. * and block->filters must have been initialized.
  579. * \param in Beginning of the input buffer
  580. * \param in_size Size of the input buffer
  581. * \param[out] out Beginning of the output buffer
  582. * \param[out] out_pos The next byte will be written to out[*out_pos].
  583. * *out_pos is updated only if encoding succeeds.
  584. * \param out_size Size of the out buffer; the first byte into
  585. * which no data is written to is out[out_size].
  586. *
  587. * \return Possible lzma_ret values:
  588. * - LZMA_OK: Encoding was successful.
  589. * - LZMA_BUF_ERROR: Not enough output buffer space.
  590. * - LZMA_UNSUPPORTED_CHECK
  591. * - LZMA_OPTIONS_ERROR
  592. * - LZMA_MEM_ERROR
  593. * - LZMA_DATA_ERROR
  594. * - LZMA_PROG_ERROR
  595. */
  596. extern LZMA_API(lzma_ret) lzma_block_uncomp_encode(lzma_block *block,
  597. const uint8_t *in, size_t in_size,
  598. uint8_t *out, size_t *out_pos, size_t out_size)
  599. lzma_nothrow lzma_attr_warn_unused_result;
  600. /**
  601. * \brief Single-call .xz Block decoder
  602. *
  603. * This is single-call equivalent of lzma_block_decoder(), and requires that
  604. * the caller has already decoded Block Header and checked its memory usage.
  605. *
  606. * \param block Block options
  607. * \param allocator lzma_allocator for custom allocator functions.
  608. * Set to NULL to use malloc() and free().
  609. * \param in Beginning of the input buffer
  610. * \param in_pos The next byte will be read from in[*in_pos].
  611. * *in_pos is updated only if decoding succeeds.
  612. * \param in_size Size of the input buffer; the first byte that
  613. * won't be read is in[in_size].
  614. * \param[out] out Beginning of the output buffer
  615. * \param[out] out_pos The next byte will be written to out[*out_pos].
  616. * *out_pos is updated only if encoding succeeds.
  617. * \param out_size Size of the out buffer; the first byte into
  618. * which no data is written to is out[out_size].
  619. *
  620. * \return Possible lzma_ret values:
  621. * - LZMA_OK: Decoding was successful.
  622. * - LZMA_OPTIONS_ERROR
  623. * - LZMA_DATA_ERROR
  624. * - LZMA_MEM_ERROR
  625. * - LZMA_BUF_ERROR: Output buffer was too small.
  626. * - LZMA_PROG_ERROR
  627. */
  628. extern LZMA_API(lzma_ret) lzma_block_buffer_decode(
  629. lzma_block *block, const lzma_allocator *allocator,
  630. const uint8_t *in, size_t *in_pos, size_t in_size,
  631. uint8_t *out, size_t *out_pos, size_t out_size)
  632. lzma_nothrow;