MFV: xz 5.4.2.

MFC after:	2 weeks
This commit is contained in:
Xin LI 2023-03-19 19:30:08 -07:00
commit c917796c04
49 changed files with 5198 additions and 496 deletions

View File

@ -21,6 +21,17 @@ XZ Utils Licensing
XZ Utils specific documentation files in other directories XZ Utils specific documentation files in other directories
are in the public domain. are in the public domain.
Note: The JavaScript files (under the MIT license) have
been removed from the Doxygen-generated HTML version of the
liblzma API documentation. Doxygen itself is under the GNU GPL
but the remaining files generated by Doxygen are not affected
by the licenses used in Doxygen because Doxygen licensing has
the following exception:
"Documents produced by doxygen are derivative works
derived from the input used in their production;
they are not affected by this license."
- Translated messages are in the public domain. - Translated messages are in the public domain.
- The build system contains public domain files, and files that - The build system contains public domain files, and files that

File diff suppressed because it is too large Load Diff

View File

@ -113,8 +113,8 @@ XZ Utils
Since the liblzma API has similarities to the zlib API, some people Since the liblzma API has similarities to the zlib API, some people
may find it useful to read the zlib docs and tutorial too: may find it useful to read the zlib docs and tutorial too:
http://zlib.net/manual.html https://zlib.net/manual.html
http://zlib.net/zlib_how.html https://zlib.net/zlib_how.html
2. Version numbering 2. Version numbering
@ -281,8 +281,8 @@ XZ Utils
7-Zip and the p7zip port of 7-Zip support the .xz format starting 7-Zip and the p7zip port of 7-Zip support the .xz format starting
from the version 9.00alpha. from the version 9.00alpha.
http://7-zip.org/ https://7-zip.org/
http://p7zip.sourceforge.net/ https://p7zip.sourceforge.net/
XZ Embedded is a limited implementation written for use in the Linux XZ Embedded is a limited implementation written for use in the Linux
kernel, but it is also suitable for other embedded use. kernel, but it is also suitable for other embedded use.

View File

@ -39,6 +39,7 @@ has been important. :-) In alphabetical order:
- Robert Elz - Robert Elz
- Gilles Espinasse - Gilles Espinasse
- Denis Excoffier - Denis Excoffier
- Vincent Fazio
- Michael Felt - Michael Felt
- Michael Fox - Michael Fox
- Mike Frysinger - Mike Frysinger
@ -66,6 +67,7 @@ has been important. :-) In alphabetical order:
- Thomas Klausner - Thomas Klausner
- Richard Koch - Richard Koch
- Ville Koskinen - Ville Koskinen
- Marcin Kowalczyk
- Jan Kratochvil - Jan Kratochvil
- Christian Kujau - Christian Kujau
- Stephan Kulow - Stephan Kulow

2684
contrib/xz/doxygen/Doxyfile Normal file

File diff suppressed because it is too large Load Diff

111
contrib/xz/doxygen/update-doxygen Executable file
View File

@ -0,0 +1,111 @@
#!/bin/sh
#
#############################################################################
#
# Updates the Doxygen generated documentation files in the source tree.
# If the doxygen command is not installed, it will exit with an error.
# This script can generate Doxygen documentation for all source files or for
# just liblzma API header files.
#
# It is recommended to use this script to update the Doxygen-generated HTML
# files since this will include the package version in the output and,
# in case of liblzma API docs, strip JavaScript files from the output.
#
#############################################################################
#
# Authors: Jia Tan
# Lasse Collin
#
# This file has been put into the public domain.
# You can do whatever you want with this file.
#
#############################################################################
set -e
if type doxygen > /dev/null 2>&1; then
:
else
echo "doxygen/update-doxygen: 'doxygen' command not found." >&2
echo "doxygen/update-doxygen: Skipping Doxygen docs generation." >&2
exit 1
fi
if test ! -f Doxyfile; then
cd `dirname "$0"` || exit 1
if test ! -f Doxyfile; then
echo "doxygen/update-doxygen: Cannot find Doxyfile" >&2
exit 1
fi
fi
# Get the package version so that it can be included in the generated docs.
PACKAGE_VERSION=`cd .. && sh build-aux/version.sh` || exit 1
# If no arguments are specified, default to generating liblzma API header
# documentation only.
case $1 in
'' | api)
# Remove old documentation before re-generating the new.
rm -rf ../doc/api
# Generate the HTML documentation by preparing the Doxyfile
# in stdin and piping the result to the doxygen command.
# With Doxygen, the last assignment of a value to a tag will
# override any earlier assignment. So, we can use this
# feature to override the tags that need to change between
# "api" and "internal" modes.
(
cat Doxyfile
echo "PROJECT_NUMBER = $PACKAGE_VERSION"
) | doxygen -
# As of Doxygen 1.8.0 - 1.9.6 and the Doxyfile options we use,
# the output is good without any JavaScript. Unfortunately
# Doxygen doesn't have an option to disable JavaScript usage
# completely so we strip it away with the hack below.
#
# Omitting the JavaScript code avoids some license hassle
# as jquery.js is fairly big, it contains more than jQuery
# itself, and doesn't include the actual license text (it
# only refers to the MIT license by name).
echo "Stripping JavaScript from Doxygen output..."
for F in ../doc/api/*.html
do
sed 's/<script [^>]*><\/script>//g
s/onclick="[^"]*"//g' \
"$F" > ../doc/api/tmp
mv -f ../doc/api/tmp "$F"
done
rm -f ../doc/api/*.js
;;
internal)
# The docs from internal aren't for distribution so
# the JavaScript files aren't an issue here.
rm -rf ../doc/internal
(
cat Doxyfile
echo "PROJECT_NUMBER = $PACKAGE_VERSION"
echo 'PROJECT_NAME = "XZ Utils"'
echo 'STRIP_FROM_PATH = ../src'
echo 'INPUT = ../src'
echo 'HTML_OUTPUT = internal'
echo 'EXTRACT_PRIVATE = YES'
echo 'EXTRACT_STATIC = YES'
echo 'EXTRACT_LOCAL_CLASSES = YES'
echo 'SEARCHENGINE = YES'
) | doxygen -
;;
*)
echo "doxygen/update-doxygen: Error: mode argument '$1'" \
"is not supported." >&2
echo "doxygen/update-doxygen: Supported modes:" >&2
echo "doxygen/update-doxygen: - 'api' (default):" \
"liblzma API docs into doc/api" >&2
echo "doxygen/update-doxygen: - 'internal':"\
"internal docs into doc/internal" >&2
exit 1
;;
esac

View File

@ -300,8 +300,8 @@ static inline void
mythread_condtime_set(mythread_condtime *condtime, const mythread_cond *cond, mythread_condtime_set(mythread_condtime *condtime, const mythread_cond *cond,
uint32_t timeout_ms) uint32_t timeout_ms)
{ {
condtime->tv_sec = timeout_ms / 1000; condtime->tv_sec = (time_t)(timeout_ms / 1000);
condtime->tv_nsec = (timeout_ms % 1000) * 1000000; condtime->tv_nsec = (long)((timeout_ms % 1000) * 1000000);
#ifdef HAVE_CLOCK_GETTIME #ifdef HAVE_CLOCK_GETTIME
struct timespec now; struct timespec now;

View File

@ -27,5 +27,5 @@ tuklib_mbstr_fw(const char *str, int columns_min)
if (width < (size_t)columns_min) if (width < (size_t)columns_min)
len += (size_t)columns_min - width; len += (size_t)columns_min - width;
return len; return (int)len;
} }

View File

@ -73,6 +73,17 @@
#endif #endif
// With GCC >= 8.1 with -Wextra and Clang >= 13 with -Wcast-function-type
// will warn about the Windows-specific code.
#if defined(__has_warning)
# if __has_warning("-Wcast-function-type")
# define CAN_DISABLE_WCAST_FUNCTION_TYPE 1
# endif
#elif TUKLIB_GNUC_REQ(8,1)
# define CAN_DISABLE_WCAST_FUNCTION_TYPE 1
#endif
extern uint64_t extern uint64_t
tuklib_physmem(void) tuklib_physmem(void)
{ {
@ -87,8 +98,15 @@ tuklib_physmem(void)
HMODULE kernel32 = GetModuleHandle(TEXT("kernel32.dll")); HMODULE kernel32 = GetModuleHandle(TEXT("kernel32.dll"));
if (kernel32 != NULL) { if (kernel32 != NULL) {
typedef BOOL (WINAPI *gmse_type)(LPMEMORYSTATUSEX); typedef BOOL (WINAPI *gmse_type)(LPMEMORYSTATUSEX);
#ifdef CAN_DISABLE_WCAST_FUNCTION_TYPE
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wcast-function-type"
#endif
gmse_type gmse = (gmse_type)GetProcAddress( gmse_type gmse = (gmse_type)GetProcAddress(
kernel32, "GlobalMemoryStatusEx"); kernel32, "GlobalMemoryStatusEx");
#ifdef CAN_DISABLE_WCAST_FUNCTION_TYPE
# pragma GCC diagnostic pop
#endif
if (gmse != NULL) { if (gmse != NULL) {
MEMORYSTATUSEX meminfo; MEMORYSTATUSEX meminfo;
meminfo.dwLength = sizeof(meminfo); meminfo.dwLength = sizeof(meminfo);

View File

@ -1,22 +1,23 @@
/** /**
* \file api/lzma.h * \file api/lzma.h
* \brief The public API of liblzma data compression library * \brief The public API of liblzma data compression library
* \mainpage
* *
* liblzma is a public domain general-purpose data compression library with * liblzma is a public domain general-purpose data compression library with
* a zlib-like API. The native file format is .xz, but also the old .lzma * a zlib-like API. The native file format is .xz, but also the old .lzma
* format and raw (no headers) streams are supported. Multiple compression * format and raw (no headers) streams are supported. Multiple compression
* algorithms (filters) are supported. Currently LZMA2 is the primary filter. * algorithms (filters) are supported. Currently LZMA2 is the primary filter.
* *
* liblzma is part of XZ Utils <http://tukaani.org/xz/>. XZ Utils includes * liblzma is part of XZ Utils <https://tukaani.org/xz/>. XZ Utils includes
* a gzip-like command line tool named xz and some other tools. XZ Utils * a gzip-like command line tool named xz and some other tools. XZ Utils
* is developed and maintained by Lasse Collin. * is developed and maintained by Lasse Collin.
* *
* Major parts of liblzma are based on Igor Pavlov's public domain LZMA SDK * Major parts of liblzma are based on Igor Pavlov's public domain LZMA SDK
* <http://7-zip.org/sdk.html>. * <https://7-zip.org/sdk.html>.
* *
* The SHA-256 implementation is based on the public domain code found from * The SHA-256 implementation is based on the public domain code found from
* 7-Zip <http://7-zip.org/>, which has a modified version of the public * 7-Zip <https://7-zip.org/>, which has a modified version of the public
* domain SHA-256 code found from Crypto++ <http://www.cryptopp.com/>. * domain SHA-256 code found from Crypto++ <https://www.cryptopp.com/>.
* The SHA-256 code in Crypto++ was written by Kevin Springle and Wei Dai. * The SHA-256 code in Crypto++ was written by Kevin Springle and Wei Dai.
*/ */

View File

@ -1,6 +1,7 @@
/** /**
* \file lzma/base.h * \file lzma/base.h
* \brief Data types and functions used in many places in liblzma API * \brief Data types and functions used in many places in liblzma API
* \note Never include this file directly. Use <lzma.h> instead.
*/ */
/* /*
@ -8,8 +9,6 @@
* *
* This file has been put into the public domain. * This file has been put into the public domain.
* You can do whatever you want with this file. * You can do whatever you want with this file.
*
* See ../lzma.h for information about liblzma as a whole.
*/ */
#ifndef LZMA_H_INTERNAL #ifndef LZMA_H_INTERNAL
@ -138,7 +137,7 @@ typedef enum {
*/ */
LZMA_MEMLIMIT_ERROR = 6, LZMA_MEMLIMIT_ERROR = 6,
/** /**<
* \brief Memory usage limit was reached * \brief Memory usage limit was reached
* *
* Decoder would need more memory than allowed by the * Decoder would need more memory than allowed by the
@ -277,7 +276,7 @@ typedef enum {
* \brief The `action' argument for lzma_code() * \brief The `action' argument for lzma_code()
* *
* After the first use of LZMA_SYNC_FLUSH, LZMA_FULL_FLUSH, LZMA_FULL_BARRIER, * After the first use of LZMA_SYNC_FLUSH, LZMA_FULL_FLUSH, LZMA_FULL_BARRIER,
* or LZMA_FINISH, the same `action' must is used until lzma_code() returns * or LZMA_FINISH, the same `action' must be used until lzma_code() returns
* LZMA_STREAM_END. Also, the amount of input (that is, strm->avail_in) must * LZMA_STREAM_END. Also, the amount of input (that is, strm->avail_in) must
* not be modified by the application until lzma_code() returns * not be modified by the application until lzma_code() returns
* LZMA_STREAM_END. Changing the `action' or modifying the amount of input * LZMA_STREAM_END. Changing the `action' or modifying the amount of input
@ -546,9 +545,17 @@ typedef struct {
* you should not touch these, because the names of these variables * you should not touch these, because the names of these variables
* may change. * may change.
*/ */
/** \private Reserved member. */
void *reserved_ptr1; void *reserved_ptr1;
/** \private Reserved member. */
void *reserved_ptr2; void *reserved_ptr2;
/** \private Reserved member. */
void *reserved_ptr3; void *reserved_ptr3;
/** \private Reserved member. */
void *reserved_ptr4; void *reserved_ptr4;
/** /**
@ -563,10 +570,19 @@ typedef struct {
*/ */
uint64_t seek_pos; uint64_t seek_pos;
/** \private Reserved member. */
uint64_t reserved_int2; uint64_t reserved_int2;
/** \private Reserved member. */
size_t reserved_int3; size_t reserved_int3;
/** \private Reserved member. */
size_t reserved_int4; size_t reserved_int4;
/** \private Reserved member. */
lzma_reserved_enum reserved_enum1; lzma_reserved_enum reserved_enum1;
/** \private Reserved member. */
lzma_reserved_enum reserved_enum2; lzma_reserved_enum reserved_enum2;
} lzma_stream; } lzma_stream;
@ -607,6 +623,14 @@ typedef struct {
* *
* See the description of the coder-specific initialization function to find * See the description of the coder-specific initialization function to find
* out what `action' values are supported by the coder. * out what `action' values are supported by the coder.
*
* \param strm Pointer to lzma_stream that is at least initialized
* with LZMA_STREAM_INIT.
* \param action Action for this function to take. Must be a valid
* lzma_action enum value.
*
* \return Any valid lzma_ret. See the lzma_ret enum description for more
* information.
*/ */
extern LZMA_API(lzma_ret) lzma_code(lzma_stream *strm, lzma_action action) extern LZMA_API(lzma_ret) lzma_code(lzma_stream *strm, lzma_action action)
lzma_nothrow lzma_attr_warn_unused_result; lzma_nothrow lzma_attr_warn_unused_result;
@ -615,15 +639,15 @@ extern LZMA_API(lzma_ret) lzma_code(lzma_stream *strm, lzma_action action)
/** /**
* \brief Free memory allocated for the coder data structures * \brief Free memory allocated for the coder data structures
* *
* \param strm Pointer to lzma_stream that is at least initialized
* with LZMA_STREAM_INIT.
*
* After lzma_end(strm), strm->internal is guaranteed to be NULL. No other * After lzma_end(strm), strm->internal is guaranteed to be NULL. No other
* members of the lzma_stream structure are touched. * members of the lzma_stream structure are touched.
* *
* \note zlib indicates an error if application end()s unfinished * \note zlib indicates an error if application end()s unfinished
* stream structure. liblzma doesn't do this, and assumes that * stream structure. liblzma doesn't do this, and assumes that
* application knows what it is doing. * application knows what it is doing.
*
* \param strm Pointer to lzma_stream that is at least initialized
* with LZMA_STREAM_INIT.
*/ */
extern LZMA_API(void) lzma_end(lzma_stream *strm) lzma_nothrow; extern LZMA_API(void) lzma_end(lzma_stream *strm) lzma_nothrow;
@ -642,6 +666,11 @@ extern LZMA_API(void) lzma_end(lzma_stream *strm) lzma_nothrow;
* mode by taking into account the progress made by each thread. In * mode by taking into account the progress made by each thread. In
* single-threaded mode *progress_in and *progress_out are set to * single-threaded mode *progress_in and *progress_out are set to
* strm->total_in and strm->total_out, respectively. * strm->total_in and strm->total_out, respectively.
*
* \param strm Pointer to lzma_stream that is at least
* initialized with LZMA_STREAM_INIT.
* \param[out] progress_in Pointer to the number of input bytes processed.
* \param[out] progress_out Pointer to the number of output bytes processed.
*/ */
extern LZMA_API(void) lzma_get_progress(lzma_stream *strm, extern LZMA_API(void) lzma_get_progress(lzma_stream *strm,
uint64_t *progress_in, uint64_t *progress_out) lzma_nothrow; uint64_t *progress_in, uint64_t *progress_out) lzma_nothrow;
@ -660,6 +689,9 @@ extern LZMA_API(void) lzma_get_progress(lzma_stream *strm,
* this may give misleading information if decoding .xz Streams that have * this may give misleading information if decoding .xz Streams that have
* multiple Blocks, because each Block can have different memory requirements. * multiple Blocks, because each Block can have different memory requirements.
* *
* \param strm Pointer to lzma_stream that is at least initialized
* with LZMA_STREAM_INIT.
*
* \return How much memory is currently allocated for the filter * \return How much memory is currently allocated for the filter
* decoders. If no filter chain is currently allocated, * decoders. If no filter chain is currently allocated,
* some non-zero value is still returned, which is less than * some non-zero value is still returned, which is less than
@ -679,6 +711,9 @@ extern LZMA_API(uint64_t) lzma_memusage(const lzma_stream *strm)
* This function is supported only when *strm has been initialized with * This function is supported only when *strm has been initialized with
* a function that takes a memlimit argument. * a function that takes a memlimit argument.
* *
* \param strm Pointer to lzma_stream that is at least initialized
* with LZMA_STREAM_INIT.
*
* \return On success, the current memory usage limit is returned * \return On success, the current memory usage limit is returned
* (always non-zero). On error, zero is returned. * (always non-zero). On error, zero is returned.
*/ */
@ -702,7 +737,8 @@ extern LZMA_API(uint64_t) lzma_memlimit_get(const lzma_stream *strm)
* after LZMA_MEMLIMIT_ERROR even if the limit was increased using * after LZMA_MEMLIMIT_ERROR even if the limit was increased using
* lzma_memlimit_set(). Other decoders worked correctly. * lzma_memlimit_set(). Other decoders worked correctly.
* *
* \return - LZMA_OK: New memory usage limit successfully set. * \return Possible lzma_ret values:
* - LZMA_OK: New memory usage limit successfully set.
* - LZMA_MEMLIMIT_ERROR: The new limit is too small. * - LZMA_MEMLIMIT_ERROR: The new limit is too small.
* The limit was not changed. * The limit was not changed.
* - LZMA_PROG_ERROR: Invalid arguments, e.g. *strm doesn't * - LZMA_PROG_ERROR: Invalid arguments, e.g. *strm doesn't

View File

@ -1,6 +1,7 @@
/** /**
* \file lzma/bcj.h * \file lzma/bcj.h
* \brief Branch/Call/Jump conversion filters * \brief Branch/Call/Jump conversion filters
* \note Never include this file directly. Use <lzma.h> instead.
*/ */
/* /*
@ -8,8 +9,6 @@
* *
* This file has been put into the public domain. * This file has been put into the public domain.
* You can do whatever you want with this file. * You can do whatever you want with this file.
*
* See ../lzma.h for information about liblzma as a whole.
*/ */
#ifndef LZMA_H_INTERNAL #ifndef LZMA_H_INTERNAL
@ -19,43 +18,44 @@
/* Filter IDs for lzma_filter.id */ /* Filter IDs for lzma_filter.id */
/**
* \brief Filter for x86 binaries
*/
#define LZMA_FILTER_X86 LZMA_VLI_C(0x04) #define LZMA_FILTER_X86 LZMA_VLI_C(0x04)
/**<
* Filter for x86 binaries
*/
#define LZMA_FILTER_POWERPC LZMA_VLI_C(0x05)
/**<
* Filter for Big endian PowerPC binaries
*/
#define LZMA_FILTER_IA64 LZMA_VLI_C(0x06)
/**<
* Filter for IA-64 (Itanium) binaries.
*/
#define LZMA_FILTER_ARM LZMA_VLI_C(0x07)
/**<
* Filter for ARM binaries.
*/
#define LZMA_FILTER_ARMTHUMB LZMA_VLI_C(0x08)
/**<
* Filter for ARM-Thumb binaries.
*/
#define LZMA_FILTER_SPARC LZMA_VLI_C(0x09)
/**<
* Filter for SPARC binaries.
*/
#define LZMA_FILTER_ARM64 LZMA_VLI_C(0x0A)
/**<
* Filter for ARM64 binaries.
*/
/** /**
* \brief Options for BCJ filters (except ARM64) * \brief Filter for Big endian PowerPC binaries
*/
#define LZMA_FILTER_POWERPC LZMA_VLI_C(0x05)
/**
* \brief Filter for IA-64 (Itanium) binaries
*/
#define LZMA_FILTER_IA64 LZMA_VLI_C(0x06)
/**
* \brief Filter for ARM binaries
*/
#define LZMA_FILTER_ARM LZMA_VLI_C(0x07)
/**
* \brief Filter for ARM-Thumb binaries
*/
#define LZMA_FILTER_ARMTHUMB LZMA_VLI_C(0x08)
/**
* \brief Filter for SPARC binaries
*/
#define LZMA_FILTER_SPARC LZMA_VLI_C(0x09)
/**
* \brief Filter for ARM64 binaries
*/
#define LZMA_FILTER_ARM64 LZMA_VLI_C(0x0A)
/**
* \brief Options for BCJ filters
* *
* The BCJ filters never change the size of the data. Specifying options * The BCJ filters never change the size of the data. Specifying options
* for them is optional: if pointer to options is NULL, default value is * for them is optional: if pointer to options is NULL, default value is

View File

@ -1,6 +1,7 @@
/** /**
* \file lzma/block.h * \file lzma/block.h
* \brief .xz Block handling * \brief .xz Block handling
* \note Never include this file directly. Use <lzma.h> instead.
*/ */
/* /*
@ -8,8 +9,6 @@
* *
* This file has been put into the public domain. * This file has been put into the public domain.
* You can do whatever you want with this file. * You can do whatever you want with this file.
*
* See ../lzma.h for information about liblzma as a whole.
*/ */
#ifndef LZMA_H_INTERNAL #ifndef LZMA_H_INTERNAL
@ -32,19 +31,28 @@ typedef struct {
* \brief Block format version * \brief Block format version
* *
* To prevent API and ABI breakages when new features are needed, * To prevent API and ABI breakages when new features are needed,
* a version number is used to indicate which fields in this * a version number is used to indicate which members in this
* structure are in use: * structure are in use:
* - liblzma >= 5.0.0: version = 0 is supported. * - liblzma >= 5.0.0: version = 0 is supported.
* - liblzma >= 5.1.4beta: Support for version = 1 was added, * - liblzma >= 5.1.4beta: Support for version = 1 was added,
* which adds the ignore_check field. * which adds the ignore_check member.
* *
* If version is greater than one, most Block related functions * If version is greater than one, most Block related functions
* will return LZMA_OPTIONS_ERROR (lzma_block_header_decode() works * will return LZMA_OPTIONS_ERROR (lzma_block_header_decode() works
* with any version value). * with any version value).
* *
* Read by: * Read by:
* - All functions that take pointer to lzma_block as argument, * - lzma_block_header_size()
* including lzma_block_header_decode(). * - lzma_block_header_encode()
* - lzma_block_header_decode()
* - lzma_block_compressed_size()
* - lzma_block_unpadded_size()
* - lzma_block_total_size()
* - lzma_block_encoder()
* - lzma_block_decoder()
* - lzma_block_buffer_encode()
* - lzma_block_uncomp_encode()
* - lzma_block_buffer_decode()
* *
* Written by: * Written by:
* - lzma_block_header_decode() * - lzma_block_header_decode()
@ -52,7 +60,7 @@ typedef struct {
uint32_t version; uint32_t version;
/** /**
* \brief Size of the Block Header field * \brief Size of the Block Header field in bytes
* *
* This is always a multiple of four. * This is always a multiple of four.
* *
@ -68,6 +76,7 @@ typedef struct {
* Written by: * Written by:
* - lzma_block_header_size() * - lzma_block_header_size()
* - lzma_block_buffer_encode() * - lzma_block_buffer_encode()
* - lzma_block_uncomp_encode()
*/ */
uint32_t header_size; uint32_t header_size;
# define LZMA_BLOCK_HEADER_SIZE_MIN 8 # define LZMA_BLOCK_HEADER_SIZE_MIN 8
@ -143,6 +152,7 @@ typedef struct {
* - lzma_block_encoder() * - lzma_block_encoder()
* - lzma_block_decoder() * - lzma_block_decoder()
* - lzma_block_buffer_encode() * - lzma_block_buffer_encode()
* - lzma_block_uncomp_encode()
* - lzma_block_buffer_decode() * - lzma_block_buffer_decode()
*/ */
lzma_vli compressed_size; lzma_vli compressed_size;
@ -167,6 +177,7 @@ typedef struct {
* - lzma_block_encoder() * - lzma_block_encoder()
* - lzma_block_decoder() * - lzma_block_decoder()
* - lzma_block_buffer_encode() * - lzma_block_buffer_encode()
* - lzma_block_uncomp_encode()
* - lzma_block_buffer_decode() * - lzma_block_buffer_decode()
*/ */
lzma_vli uncompressed_size; lzma_vli uncompressed_size;
@ -212,6 +223,7 @@ typedef struct {
* - lzma_block_encoder() * - lzma_block_encoder()
* - lzma_block_decoder() * - lzma_block_decoder()
* - lzma_block_buffer_encode() * - lzma_block_buffer_encode()
* - lzma_block_uncomp_encode()
* - lzma_block_buffer_decode() * - lzma_block_buffer_decode()
*/ */
uint8_t raw_check[LZMA_CHECK_SIZE_MAX]; uint8_t raw_check[LZMA_CHECK_SIZE_MAX];
@ -223,26 +235,56 @@ typedef struct {
* with the currently supported options, so it is safe to leave these * with the currently supported options, so it is safe to leave these
* uninitialized. * uninitialized.
*/ */
/** \private Reserved member. */
void *reserved_ptr1; void *reserved_ptr1;
/** \private Reserved member. */
void *reserved_ptr2; void *reserved_ptr2;
/** \private Reserved member. */
void *reserved_ptr3; void *reserved_ptr3;
/** \private Reserved member. */
uint32_t reserved_int1; uint32_t reserved_int1;
/** \private Reserved member. */
uint32_t reserved_int2; uint32_t reserved_int2;
/** \private Reserved member. */
lzma_vli reserved_int3; lzma_vli reserved_int3;
/** \private Reserved member. */
lzma_vli reserved_int4; lzma_vli reserved_int4;
/** \private Reserved member. */
lzma_vli reserved_int5; lzma_vli reserved_int5;
/** \private Reserved member. */
lzma_vli reserved_int6; lzma_vli reserved_int6;
/** \private Reserved member. */
lzma_vli reserved_int7; lzma_vli reserved_int7;
/** \private Reserved member. */
lzma_vli reserved_int8; lzma_vli reserved_int8;
/** \private Reserved member. */
lzma_reserved_enum reserved_enum1; lzma_reserved_enum reserved_enum1;
/** \private Reserved member. */
lzma_reserved_enum reserved_enum2; lzma_reserved_enum reserved_enum2;
/** \private Reserved member. */
lzma_reserved_enum reserved_enum3; lzma_reserved_enum reserved_enum3;
/** \private Reserved member. */
lzma_reserved_enum reserved_enum4; lzma_reserved_enum reserved_enum4;
/** /**
* \brief A flag to Block decoder to not verify the Check field * \brief A flag to Block decoder to not verify the Check field
* *
* This field is supported by liblzma >= 5.1.4beta if .version >= 1. * This member is supported by liblzma >= 5.1.4beta if .version >= 1.
* *
* If this is set to true, the integrity check won't be calculated * If this is set to true, the integrity check won't be calculated
* and verified. Unless you know what you are doing, you should * and verified. Unless you know what you are doing, you should
@ -260,12 +302,25 @@ typedef struct {
*/ */
lzma_bool ignore_check; lzma_bool ignore_check;
/** \private Reserved member. */
lzma_bool reserved_bool2; lzma_bool reserved_bool2;
/** \private Reserved member. */
lzma_bool reserved_bool3; lzma_bool reserved_bool3;
/** \private Reserved member. */
lzma_bool reserved_bool4; lzma_bool reserved_bool4;
/** \private Reserved member. */
lzma_bool reserved_bool5; lzma_bool reserved_bool5;
/** \private Reserved member. */
lzma_bool reserved_bool6; lzma_bool reserved_bool6;
/** \private Reserved member. */
lzma_bool reserved_bool7; lzma_bool reserved_bool7;
/** \private Reserved member. */
lzma_bool reserved_bool8; lzma_bool reserved_bool8;
} lzma_block; } lzma_block;
@ -280,7 +335,8 @@ typedef struct {
* Note that if the first byte is 0x00, it indicates beginning of Index; use * Note that if the first byte is 0x00, it indicates beginning of Index; use
* this macro only when the byte is not 0x00. * this macro only when the byte is not 0x00.
* *
* There is no encoding macro, because Block Header encoder is enough for that. * There is no encoding macro because lzma_block_header_size() and
* lzma_block_header_encode() should be used.
*/ */
#define lzma_block_header_size_decode(b) (((uint32_t)(b) + 1) * 4) #define lzma_block_header_size_decode(b) (((uint32_t)(b) + 1) * 4)
@ -294,17 +350,20 @@ typedef struct {
* four and doesn't exceed LZMA_BLOCK_HEADER_SIZE_MAX. Increasing header_size * four and doesn't exceed LZMA_BLOCK_HEADER_SIZE_MAX. Increasing header_size
* just means that lzma_block_header_encode() will add Header Padding. * just means that lzma_block_header_encode() will add Header Padding.
* *
* \return - LZMA_OK: Size calculated successfully and stored to
* block->header_size.
* - LZMA_OPTIONS_ERROR: Unsupported version, filters or
* filter options.
* - LZMA_PROG_ERROR: Invalid values like compressed_size == 0.
*
* \note This doesn't check that all the options are valid i.e. this * \note This doesn't check that all the options are valid i.e. this
* may return LZMA_OK even if lzma_block_header_encode() or * may return LZMA_OK even if lzma_block_header_encode() or
* lzma_block_encoder() would fail. If you want to validate the * lzma_block_encoder() would fail. If you want to validate the
* filter chain, consider using lzma_memlimit_encoder() which as * filter chain, consider using lzma_memlimit_encoder() which as
* a side-effect validates the filter chain. * a side-effect validates the filter chain.
*
* \param block Block options
*
* \return Possible lzma_ret values:
* - LZMA_OK: Size calculated successfully and stored to
* block->header_size.
* - LZMA_OPTIONS_ERROR: Unsupported version, filters or
* filter options.
* - LZMA_PROG_ERROR: Invalid values like compressed_size == 0.
*/ */
extern LZMA_API(lzma_ret) lzma_block_header_size(lzma_block *block) extern LZMA_API(lzma_ret) lzma_block_header_size(lzma_block *block)
lzma_nothrow lzma_attr_warn_unused_result; lzma_nothrow lzma_attr_warn_unused_result;
@ -318,11 +377,12 @@ extern LZMA_API(lzma_ret) lzma_block_header_size(lzma_block *block)
* lzma_block_header_size() is used, the Block Header will be padded to the * lzma_block_header_size() is used, the Block Header will be padded to the
* specified size. * specified size.
* *
* \param out Beginning of the output buffer. This must be
* at least block->header_size bytes.
* \param block Block options to be encoded. * \param block Block options to be encoded.
* \param[out] out Beginning of the output buffer. This must be
* at least block->header_size bytes.
* *
* \return - LZMA_OK: Encoding was successful. block->header_size * \return Possible lzma_ret values:
* - LZMA_OK: Encoding was successful. block->header_size
* bytes were written to output buffer. * bytes were written to output buffer.
* - LZMA_OPTIONS_ERROR: Invalid or unsupported options. * - LZMA_OPTIONS_ERROR: Invalid or unsupported options.
* - LZMA_PROG_ERROR: Invalid arguments, for example * - LZMA_PROG_ERROR: Invalid arguments, for example
@ -354,14 +414,15 @@ extern LZMA_API(lzma_ret) lzma_block_header_encode(
* block->filters must have been allocated, but they don't need to be * block->filters must have been allocated, but they don't need to be
* initialized (possible existing filter options are not freed). * initialized (possible existing filter options are not freed).
* *
* \param block Destination for Block options. * \param[out] block Destination for Block options
* \param allocator lzma_allocator for custom allocator functions. * \param allocator lzma_allocator for custom allocator functions.
* Set to NULL to use malloc() (and also free() * Set to NULL to use malloc() (and also free()
* if an error occurs). * if an error occurs).
* \param in Beginning of the input buffer. This must be * \param in Beginning of the input buffer. This must be
* at least block->header_size bytes. * at least block->header_size bytes.
* *
* \return - LZMA_OK: Decoding was successful. block->header_size * \return Possible lzma_ret values:
* - LZMA_OK: Decoding was successful. block->header_size
* bytes were read from the input buffer. * bytes were read from the input buffer.
* - LZMA_OPTIONS_ERROR: The Block Header specifies some * - LZMA_OPTIONS_ERROR: The Block Header specifies some
* unsupported options such as unsupported filters. This can * unsupported options such as unsupported filters. This can
@ -398,7 +459,12 @@ extern LZMA_API(lzma_ret) lzma_block_header_decode(lzma_block *block,
* field so that it can properly validate Compressed Size if it * field so that it can properly validate Compressed Size if it
* was present in Block Header. * was present in Block Header.
* *
* \return - LZMA_OK: block->compressed_size was set successfully. * \param block Block options: block->header_size must
* already be set with lzma_block_header_size().
* \param unpadded_size Unpadded Size from the Index field in bytes
*
* \return Possible lzma_ret values:
* - LZMA_OK: block->compressed_size was set successfully.
* - LZMA_DATA_ERROR: unpadded_size is too small compared to * - LZMA_DATA_ERROR: unpadded_size is too small compared to
* block->header_size and lzma_check_size(block->check). * block->header_size and lzma_check_size(block->check).
* - LZMA_PROG_ERROR: Some values are invalid. For example, * - LZMA_PROG_ERROR: Some values are invalid. For example,
@ -419,6 +485,9 @@ extern LZMA_API(lzma_ret) lzma_block_compressed_size(
* Compressed Size, and size of the Check field. This is where this function * Compressed Size, and size of the Check field. This is where this function
* is needed. * is needed.
* *
* \param block Block options: block->header_size must already be
* set with lzma_block_header_size().
*
* \return Unpadded Size on success, or zero on error. * \return Unpadded Size on success, or zero on error.
*/ */
extern LZMA_API(lzma_vli) lzma_block_unpadded_size(const lzma_block *block) extern LZMA_API(lzma_vli) lzma_block_unpadded_size(const lzma_block *block)
@ -431,6 +500,9 @@ extern LZMA_API(lzma_vli) lzma_block_unpadded_size(const lzma_block *block)
* This is equivalent to lzma_block_unpadded_size() except that the returned * This is equivalent to lzma_block_unpadded_size() except that the returned
* value includes the size of the Block Padding field. * value includes the size of the Block Padding field.
* *
* \param block Block options: block->header_size must already be
* set with lzma_block_header_size().
*
* \return On success, total encoded size of the Block. On error, * \return On success, total encoded size of the Block. On error,
* zero is returned. * zero is returned.
*/ */
@ -444,7 +516,17 @@ extern LZMA_API(lzma_vli) lzma_block_total_size(const lzma_block *block)
* Valid actions for lzma_code() are LZMA_RUN, LZMA_SYNC_FLUSH (only if the * Valid actions for lzma_code() are LZMA_RUN, LZMA_SYNC_FLUSH (only if the
* filter chain supports it), and LZMA_FINISH. * filter chain supports it), and LZMA_FINISH.
* *
* \return - LZMA_OK: All good, continue with lzma_code(). * The Block encoder encodes the Block Data, Block Padding, and Check value.
* It does NOT encode the Block Header which can be encoded with
* lzma_block_header_encode().
*
* \param strm Pointer to lzma_stream that is at least initialized
* with LZMA_STREAM_INIT.
* \param block Block options: block->version, block->check,
* and block->filters must have been initialized.
*
* \return Possible lzma_ret values:
* - LZMA_OK: All good, continue with lzma_code().
* - LZMA_MEM_ERROR * - LZMA_MEM_ERROR
* - LZMA_OPTIONS_ERROR * - LZMA_OPTIONS_ERROR
* - LZMA_UNSUPPORTED_CHECK: block->check specifies a Check ID * - LZMA_UNSUPPORTED_CHECK: block->check specifies a Check ID
@ -463,7 +545,16 @@ extern LZMA_API(lzma_ret) lzma_block_encoder(
* Valid actions for lzma_code() are LZMA_RUN and LZMA_FINISH. Using * Valid actions for lzma_code() are LZMA_RUN and LZMA_FINISH. Using
* LZMA_FINISH is not required. It is supported only for convenience. * LZMA_FINISH is not required. It is supported only for convenience.
* *
* \return - LZMA_OK: All good, continue with lzma_code(). * The Block decoder decodes the Block Data, Block Padding, and Check value.
* It does NOT decode the Block Header which can be decoded with
* lzma_block_header_decode().
*
* \param strm Pointer to lzma_stream that is at least initialized
* with LZMA_STREAM_INIT.
* \param block Block options
*
* \return Possible lzma_ret values:
* - LZMA_OK: All good, continue with lzma_code().
* - LZMA_PROG_ERROR * - LZMA_PROG_ERROR
* - LZMA_MEM_ERROR * - LZMA_MEM_ERROR
*/ */
@ -477,6 +568,11 @@ extern LZMA_API(lzma_ret) lzma_block_decoder(
* *
* This is equivalent to lzma_stream_buffer_bound() but for .xz Blocks. * This is equivalent to lzma_stream_buffer_bound() but for .xz Blocks.
* See the documentation of lzma_stream_buffer_bound(). * See the documentation of lzma_stream_buffer_bound().
*
* \param uncompressed_size Size of the data to be encoded with the
* single-call Block encoder.
*
* \return Maximum output size in bytes for single-call Block encoding.
*/ */
extern LZMA_API(size_t) lzma_block_buffer_bound(size_t uncompressed_size) extern LZMA_API(size_t) lzma_block_buffer_bound(size_t uncompressed_size)
lzma_nothrow; lzma_nothrow;
@ -505,13 +601,14 @@ extern LZMA_API(size_t) lzma_block_buffer_bound(size_t uncompressed_size)
* Set to NULL to use malloc() and free(). * Set to NULL to use malloc() and free().
* \param in Beginning of the input buffer * \param in Beginning of the input buffer
* \param in_size Size of the input buffer * \param in_size Size of the input buffer
* \param out Beginning of the output buffer * \param[out] out Beginning of the output buffer
* \param out_pos The next byte will be written to out[*out_pos]. * \param[out] out_pos The next byte will be written to out[*out_pos].
* *out_pos is updated only if encoding succeeds. * *out_pos is updated only if encoding succeeds.
* \param out_size Size of the out buffer; the first byte into * \param out_size Size of the out buffer; the first byte into
* which no data is written to is out[out_size]. * which no data is written to is out[out_size].
* *
* \return - LZMA_OK: Encoding was successful. * \return Possible lzma_ret values:
* - LZMA_OK: Encoding was successful.
* - LZMA_BUF_ERROR: Not enough output buffer space. * - LZMA_BUF_ERROR: Not enough output buffer space.
* - LZMA_UNSUPPORTED_CHECK * - LZMA_UNSUPPORTED_CHECK
* - LZMA_OPTIONS_ERROR * - LZMA_OPTIONS_ERROR
@ -537,6 +634,25 @@ extern LZMA_API(lzma_ret) lzma_block_buffer_encode(
* Since the data won't be compressed, this function ignores block->filters. * Since the data won't be compressed, this function ignores block->filters.
* This function doesn't take lzma_allocator because this function doesn't * This function doesn't take lzma_allocator because this function doesn't
* allocate any memory from the heap. * allocate any memory from the heap.
*
* \param block Block options: block->version, block->check,
* and block->filters must have been initialized.
* \param in Beginning of the input buffer
* \param in_size Size of the input buffer
* \param[out] out Beginning of the output buffer
* \param[out] out_pos The next byte will be written to out[*out_pos].
* *out_pos is updated only if encoding succeeds.
* \param out_size Size of the out buffer; the first byte into
* which no data is written to is out[out_size].
*
* \return Possible lzma_ret values:
* - LZMA_OK: Encoding was successful.
* - LZMA_BUF_ERROR: Not enough output buffer space.
* - LZMA_UNSUPPORTED_CHECK
* - LZMA_OPTIONS_ERROR
* - LZMA_MEM_ERROR
* - LZMA_DATA_ERROR
* - LZMA_PROG_ERROR
*/ */
extern LZMA_API(lzma_ret) lzma_block_uncomp_encode(lzma_block *block, extern LZMA_API(lzma_ret) lzma_block_uncomp_encode(lzma_block *block,
const uint8_t *in, size_t in_size, const uint8_t *in, size_t in_size,
@ -550,7 +666,7 @@ extern LZMA_API(lzma_ret) lzma_block_uncomp_encode(lzma_block *block,
* This is single-call equivalent of lzma_block_decoder(), and requires that * This is single-call equivalent of lzma_block_decoder(), and requires that
* the caller has already decoded Block Header and checked its memory usage. * the caller has already decoded Block Header and checked its memory usage.
* *
* \param block Block options just like with lzma_block_decoder(). * \param block Block options
* \param allocator lzma_allocator for custom allocator functions. * \param allocator lzma_allocator for custom allocator functions.
* Set to NULL to use malloc() and free(). * Set to NULL to use malloc() and free().
* \param in Beginning of the input buffer * \param in Beginning of the input buffer
@ -558,13 +674,14 @@ extern LZMA_API(lzma_ret) lzma_block_uncomp_encode(lzma_block *block,
* *in_pos is updated only if decoding succeeds. * *in_pos is updated only if decoding succeeds.
* \param in_size Size of the input buffer; the first byte that * \param in_size Size of the input buffer; the first byte that
* won't be read is in[in_size]. * won't be read is in[in_size].
* \param out Beginning of the output buffer * \param[out] out Beginning of the output buffer
* \param out_pos The next byte will be written to out[*out_pos]. * \param[out] out_pos The next byte will be written to out[*out_pos].
* *out_pos is updated only if encoding succeeds. * *out_pos is updated only if encoding succeeds.
* \param out_size Size of the out buffer; the first byte into * \param out_size Size of the out buffer; the first byte into
* which no data is written to is out[out_size]. * which no data is written to is out[out_size].
* *
* \return - LZMA_OK: Decoding was successful. * \return Possible lzma_ret values:
* - LZMA_OK: Decoding was successful.
* - LZMA_OPTIONS_ERROR * - LZMA_OPTIONS_ERROR
* - LZMA_DATA_ERROR * - LZMA_DATA_ERROR
* - LZMA_MEM_ERROR * - LZMA_MEM_ERROR

View File

@ -1,6 +1,7 @@
/** /**
* \file lzma/check.h * \file lzma/check.h
* \brief Integrity checks * \brief Integrity checks
* \note Never include this file directly. Use <lzma.h> instead.
*/ */
/* /*
@ -8,8 +9,6 @@
* *
* This file has been put into the public domain. * This file has been put into the public domain.
* You can do whatever you want with this file. * You can do whatever you want with this file.
*
* See ../lzma.h for information about liblzma as a whole.
*/ */
#ifndef LZMA_H_INTERNAL #ifndef LZMA_H_INTERNAL
@ -71,12 +70,17 @@ typedef enum {
/** /**
* \brief Test if the given Check ID is supported * \brief Test if the given Check ID is supported
* *
* Return true if the given Check ID is supported by this liblzma build. * LZMA_CHECK_NONE and LZMA_CHECK_CRC32 are always supported (even if
* Otherwise false is returned. It is safe to call this with a value that * liblzma is built with limited features).
* is not in the range [0, 15]; in that case the return value is always false.
* *
* You can assume that LZMA_CHECK_NONE and LZMA_CHECK_CRC32 are always * \note It is safe to call this with a value that is not in the
* supported (even if liblzma is built with limited features). * range [0, 15]; in that case the return value is always false.
*
* \param check Check ID
*
* \return lzma_bool:
* - true if Check ID is supported by this liblzma build.
* - false otherwise.
*/ */
extern LZMA_API(lzma_bool) lzma_check_is_supported(lzma_check check) extern LZMA_API(lzma_bool) lzma_check_is_supported(lzma_check check)
lzma_nothrow lzma_attr_const; lzma_nothrow lzma_attr_const;
@ -90,7 +94,10 @@ extern LZMA_API(lzma_bool) lzma_check_is_supported(lzma_check check)
* the Check field with the specified Check ID. The values are: * the Check field with the specified Check ID. The values are:
* { 0, 4, 4, 4, 8, 8, 8, 16, 16, 16, 32, 32, 32, 64, 64, 64 } * { 0, 4, 4, 4, 8, 8, 8, 16, 16, 16, 32, 32, 32, 64, 64, 64 }
* *
* If the argument is not in the range [0, 15], UINT32_MAX is returned. * \param check Check ID
*
* \return Size of the Check field in bytes. If the argument is not in
* the range [0, 15], UINT32_MAX is returned.
*/ */
extern LZMA_API(uint32_t) lzma_check_size(lzma_check check) extern LZMA_API(uint32_t) lzma_check_size(lzma_check check)
lzma_nothrow lzma_attr_const; lzma_nothrow lzma_attr_const;
@ -126,25 +133,32 @@ extern LZMA_API(uint32_t) lzma_crc32(
* *
* Calculate CRC64 using the polynomial from the ECMA-182 standard. * Calculate CRC64 using the polynomial from the ECMA-182 standard.
* *
* This function is used similarly to lzma_crc32(). See its documentation. * This function is used similarly to lzma_crc32().
*
* \param buf Pointer to the input buffer
* \param size Size of the input buffer
* \param crc Previously returned CRC value. This is used to
* calculate the CRC of a big buffer in smaller chunks.
* Set to zero when starting a new calculation.
*
* \return Updated CRC value, which can be passed to this function
* again to continue CRC calculation.
*/ */
extern LZMA_API(uint64_t) lzma_crc64( extern LZMA_API(uint64_t) lzma_crc64(
const uint8_t *buf, size_t size, uint64_t crc) const uint8_t *buf, size_t size, uint64_t crc)
lzma_nothrow lzma_attr_pure; lzma_nothrow lzma_attr_pure;
/*
* SHA-256 functions are currently not exported to public API.
* Contact Lasse Collin if you think it should be.
*/
/** /**
* \brief Get the type of the integrity check * \brief Get the type of the integrity check
* *
* This function can be called only immediately after lzma_code() has * This function can be called only immediately after lzma_code() has
* returned LZMA_NO_CHECK, LZMA_UNSUPPORTED_CHECK, or LZMA_GET_CHECK. * returned LZMA_NO_CHECK, LZMA_UNSUPPORTED_CHECK, or LZMA_GET_CHECK.
* Calling this function in any other situation has undefined behavior. * Calling this function in any other situation has undefined behavior.
*
* \param strm Pointer to lzma_stream meeting the above conditions.
*
* \return Check ID in the lzma_stream, or undefined if called improperly.
*/ */
extern LZMA_API(lzma_check) lzma_get_check(const lzma_stream *strm) extern LZMA_API(lzma_check) lzma_get_check(const lzma_stream *strm)
lzma_nothrow; lzma_nothrow;

View File

@ -1,6 +1,7 @@
/** /**
* \file lzma/container.h * \file lzma/container.h
* \brief File formats * \brief File formats
* \note Never include this file directly. Use <lzma.h> instead.
*/ */
/* /*
@ -8,8 +9,6 @@
* *
* This file has been put into the public domain. * This file has been put into the public domain.
* You can do whatever you want with this file. * You can do whatever you want with this file.
*
* See ../lzma.h for information about liblzma as a whole.
*/ */
#ifndef LZMA_H_INTERNAL #ifndef LZMA_H_INTERNAL
@ -51,7 +50,7 @@
* *
* This flag modifies the preset to make the encoding significantly slower * This flag modifies the preset to make the encoding significantly slower
* while improving the compression ratio only marginally. This is useful * while improving the compression ratio only marginally. This is useful
* when you don't mind wasting time to get as small result as possible. * when you don't mind spending time to get as small result as possible.
* *
* This flag doesn't affect the memory usage requirements of the decoder (at * This flag doesn't affect the memory usage requirements of the decoder (at
* least not significantly). The memory usage of the encoder may be increased * least not significantly). The memory usage of the encoder may be increased
@ -72,9 +71,12 @@ typedef struct {
* Encoder: No flags are currently supported. * Encoder: No flags are currently supported.
* *
* Decoder: Bitwise-or of zero or more of the decoder flags: * Decoder: Bitwise-or of zero or more of the decoder flags:
* LZMA_TELL_NO_CHECK, LZMA_TELL_UNSUPPORTED_CHECK, * - LZMA_TELL_NO_CHECK
* LZMA_TELL_ANY_CHECK, LZMA_IGNORE_CHECK, * - LZMA_TELL_UNSUPPORTED_CHECK
* LZMA_CONCATENATED, LZMA_FAIL_FAST * - LZMA_TELL_ANY_CHECK
* - LZMA_IGNORE_CHECK
* - LZMA_CONCATENATED
* - LZMA_FAIL_FAST
*/ */
uint32_t flags; uint32_t flags;
@ -111,7 +113,7 @@ typedef struct {
/** /**
* \brief Timeout to allow lzma_code() to return early * \brief Timeout to allow lzma_code() to return early
* *
* Multithreading can make liblzma to consume input and produce * Multithreading can make liblzma consume input and produce
* output in a very bursty way: it may first read a lot of input * output in a very bursty way: it may first read a lot of input
* to fill internal buffers, then no input or output occurs for * to fill internal buffers, then no input or output occurs for
* a while. * a while.
@ -128,14 +130,13 @@ typedef struct {
* LZMA_OK. Reasonable values are 100 ms or more. The xz command * LZMA_OK. Reasonable values are 100 ms or more. The xz command
* line tool uses 300 ms. * line tool uses 300 ms.
* *
* If long blocking times are fine for you, set timeout to a special * If long blocking times are acceptable, set timeout to a special
* value of 0, which will disable the timeout mechanism and will make * value of 0. This will disable the timeout mechanism and will make
* lzma_code() block until all the input is consumed or the output * lzma_code() block until all the input is consumed or the output
* buffer has been filled. * buffer has been filled.
* *
* \note Even with a timeout, lzma_code() might sometimes take * \note Even with a timeout, lzma_code() might sometimes take
* somewhat long time to return. No timing guarantees * a long time to return. No timing guarantees are made.
* are made.
*/ */
uint32_t timeout; uint32_t timeout;
@ -171,12 +172,25 @@ typedef struct {
* with the currently supported options, so it is safe to leave these * with the currently supported options, so it is safe to leave these
* uninitialized. * uninitialized.
*/ */
/** \private Reserved member. */
lzma_reserved_enum reserved_enum1; lzma_reserved_enum reserved_enum1;
/** \private Reserved member. */
lzma_reserved_enum reserved_enum2; lzma_reserved_enum reserved_enum2;
/** \private Reserved member. */
lzma_reserved_enum reserved_enum3; lzma_reserved_enum reserved_enum3;
/** \private Reserved member. */
uint32_t reserved_int1; uint32_t reserved_int1;
/** \private Reserved member. */
uint32_t reserved_int2; uint32_t reserved_int2;
/** \private Reserved member. */
uint32_t reserved_int3; uint32_t reserved_int3;
/** \private Reserved member. */
uint32_t reserved_int4; uint32_t reserved_int4;
/** /**
@ -222,11 +236,22 @@ typedef struct {
*/ */
uint64_t memlimit_stop; uint64_t memlimit_stop;
/** \private Reserved member. */
uint64_t reserved_int7; uint64_t reserved_int7;
/** \private Reserved member. */
uint64_t reserved_int8; uint64_t reserved_int8;
/** \private Reserved member. */
void *reserved_ptr1; void *reserved_ptr1;
/** \private Reserved member. */
void *reserved_ptr2; void *reserved_ptr2;
/** \private Reserved member. */
void *reserved_ptr3; void *reserved_ptr3;
/** \private Reserved member. */
void *reserved_ptr4; void *reserved_ptr4;
} lzma_mt; } lzma_mt;
@ -240,8 +265,7 @@ typedef struct {
* \param preset Compression preset (level and possible flags) * \param preset Compression preset (level and possible flags)
* *
* \return Number of bytes of memory required for the given * \return Number of bytes of memory required for the given
* preset when encoding. If an error occurs, for example * preset when encoding or UINT64_MAX on error.
* due to unsupported preset, UINT64_MAX is returned.
*/ */
extern LZMA_API(uint64_t) lzma_easy_encoder_memusage(uint32_t preset) extern LZMA_API(uint64_t) lzma_easy_encoder_memusage(uint32_t preset)
lzma_nothrow lzma_attr_pure; lzma_nothrow lzma_attr_pure;
@ -255,9 +279,8 @@ extern LZMA_API(uint64_t) lzma_easy_encoder_memusage(uint32_t preset)
* \param preset Compression preset (level and possible flags) * \param preset Compression preset (level and possible flags)
* *
* \return Number of bytes of memory required to decompress a file * \return Number of bytes of memory required to decompress a file
* that was compressed using the given preset. If an error * that was compressed using the given preset or UINT64_MAX
* occurs, for example due to unsupported preset, UINT64_MAX * on error.
* is returned.
*/ */
extern LZMA_API(uint64_t) lzma_easy_decoder_memusage(uint32_t preset) extern LZMA_API(uint64_t) lzma_easy_decoder_memusage(uint32_t preset)
lzma_nothrow lzma_attr_pure; lzma_nothrow lzma_attr_pure;
@ -267,7 +290,16 @@ extern LZMA_API(uint64_t) lzma_easy_decoder_memusage(uint32_t preset)
* \brief Initialize .xz Stream encoder using a preset number * \brief Initialize .xz Stream encoder using a preset number
* *
* This function is intended for those who just want to use the basic features * This function is intended for those who just want to use the basic features
* if liblzma (that is, most developers out there). * of liblzma (that is, most developers out there).
*
* If initialization fails (return value is not LZMA_OK), all the memory
* allocated for *strm by liblzma is always freed. Thus, there is no need
* to call lzma_end() after failed initialization.
*
* If initialization succeeds, use lzma_code() to do the actual encoding.
* Valid values for `action' (the second argument of lzma_code()) are
* LZMA_RUN, LZMA_SYNC_FLUSH, LZMA_FULL_FLUSH, and LZMA_FINISH. In future,
* there may be compression levels or flags that don't support LZMA_SYNC_FLUSH.
* *
* \param strm Pointer to lzma_stream that is at least initialized * \param strm Pointer to lzma_stream that is at least initialized
* with LZMA_STREAM_INIT. * with LZMA_STREAM_INIT.
@ -283,7 +315,8 @@ extern LZMA_API(uint64_t) lzma_easy_decoder_memusage(uint32_t preset)
* unsure. LZMA_CHECK_CRC32 is good too as long as the * unsure. LZMA_CHECK_CRC32 is good too as long as the
* uncompressed file is not many gigabytes. * uncompressed file is not many gigabytes.
* *
* \return - LZMA_OK: Initialization succeeded. Use lzma_code() to * \return Possible lzma_ret values:
* - LZMA_OK: Initialization succeeded. Use lzma_code() to
* encode your data. * encode your data.
* - LZMA_MEM_ERROR: Memory allocation failed. * - LZMA_MEM_ERROR: Memory allocation failed.
* - LZMA_OPTIONS_ERROR: The given compression preset is not * - LZMA_OPTIONS_ERROR: The given compression preset is not
@ -292,15 +325,6 @@ extern LZMA_API(uint64_t) lzma_easy_decoder_memusage(uint32_t preset)
* supported by this liblzma build. * supported by this liblzma build.
* - LZMA_PROG_ERROR: One or more of the parameters have values * - LZMA_PROG_ERROR: One or more of the parameters have values
* that will never be valid. For example, strm == NULL. * that will never be valid. For example, strm == NULL.
*
* If initialization fails (return value is not LZMA_OK), all the memory
* allocated for *strm by liblzma is always freed. Thus, there is no need
* to call lzma_end() after failed initialization.
*
* If initialization succeeds, use lzma_code() to do the actual encoding.
* Valid values for `action' (the second argument of lzma_code()) are
* LZMA_RUN, LZMA_SYNC_FLUSH, LZMA_FULL_FLUSH, and LZMA_FINISH. In future,
* there may be compression levels or flags that don't support LZMA_SYNC_FLUSH.
*/ */
extern LZMA_API(lzma_ret) lzma_easy_encoder( extern LZMA_API(lzma_ret) lzma_easy_encoder(
lzma_stream *strm, uint32_t preset, lzma_check check) lzma_stream *strm, uint32_t preset, lzma_check check)
@ -321,13 +345,14 @@ extern LZMA_API(lzma_ret) lzma_easy_encoder(
* Set to NULL to use malloc() and free(). * Set to NULL to use malloc() and free().
* \param in Beginning of the input buffer * \param in Beginning of the input buffer
* \param in_size Size of the input buffer * \param in_size Size of the input buffer
* \param out Beginning of the output buffer * \param[out] out Beginning of the output buffer
* \param out_pos The next byte will be written to out[*out_pos]. * \param[out] out_pos The next byte will be written to out[*out_pos].
* *out_pos is updated only if encoding succeeds. * *out_pos is updated only if encoding succeeds.
* \param out_size Size of the out buffer; the first byte into * \param out_size Size of the out buffer; the first byte into
* which no data is written to is out[out_size]. * which no data is written to is out[out_size].
* *
* \return - LZMA_OK: Encoding was successful. * \return Possible lzma_ret values:
* - LZMA_OK: Encoding was successful.
* - LZMA_BUF_ERROR: Not enough output buffer space. * - LZMA_BUF_ERROR: Not enough output buffer space.
* - LZMA_UNSUPPORTED_CHECK * - LZMA_UNSUPPORTED_CHECK
* - LZMA_OPTIONS_ERROR * - LZMA_OPTIONS_ERROR
@ -345,14 +370,16 @@ extern LZMA_API(lzma_ret) lzma_easy_buffer_encode(
/** /**
* \brief Initialize .xz Stream encoder using a custom filter chain * \brief Initialize .xz Stream encoder using a custom filter chain
* *
* \param strm Pointer to properly prepared lzma_stream * \param strm Pointer to lzma_stream that is at least initialized
* \param filters Array of filters. This must be terminated with * with LZMA_STREAM_INIT.
* filters[n].id = LZMA_VLI_UNKNOWN. See filter.h for * \param filters Array of filters terminated with
* more information. * .id == LZMA_VLI_UNKNOWN. See filters.h for more
* information.
* \param check Type of the integrity check to calculate from * \param check Type of the integrity check to calculate from
* uncompressed data. * uncompressed data.
* *
* \return - LZMA_OK: Initialization was successful. * \return Possible lzma_ret values:
* - LZMA_OK: Initialization was successful.
* - LZMA_MEM_ERROR * - LZMA_MEM_ERROR
* - LZMA_UNSUPPORTED_CHECK * - LZMA_UNSUPPORTED_CHECK
* - LZMA_OPTIONS_ERROR * - LZMA_OPTIONS_ERROR
@ -392,10 +419,12 @@ extern LZMA_API(uint64_t) lzma_stream_encoder_mt_memusage(
* LZMA_FULL_BARRIER, and LZMA_FINISH. Support for LZMA_SYNC_FLUSH might be * LZMA_FULL_BARRIER, and LZMA_FINISH. Support for LZMA_SYNC_FLUSH might be
* added in the future. * added in the future.
* *
* \param strm Pointer to properly prepared lzma_stream * \param strm Pointer to lzma_stream that is at least initialized
* with LZMA_STREAM_INIT.
* \param options Pointer to multithreaded compression options * \param options Pointer to multithreaded compression options
* *
* \return - LZMA_OK * \return Possible lzma_ret values:
* - LZMA_OK
* - LZMA_MEM_ERROR * - LZMA_MEM_ERROR
* - LZMA_UNSUPPORTED_CHECK * - LZMA_UNSUPPORTED_CHECK
* - LZMA_OPTIONS_ERROR * - LZMA_OPTIONS_ERROR
@ -421,7 +450,12 @@ extern LZMA_API(lzma_ret) lzma_stream_encoder_mt(
* No kind of flushing is supported, because the file format doesn't make * No kind of flushing is supported, because the file format doesn't make
* it possible. * it possible.
* *
* \return - LZMA_OK * \param strm Pointer to lzma_stream that is at least initialized
* with LZMA_STREAM_INIT.
* \param options Pointer to encoder options
*
* \return Possible lzma_ret values:
* - LZMA_OK
* - LZMA_MEM_ERROR * - LZMA_MEM_ERROR
* - LZMA_OPTIONS_ERROR * - LZMA_OPTIONS_ERROR
* - LZMA_PROG_ERROR * - LZMA_PROG_ERROR
@ -452,6 +486,11 @@ extern LZMA_API(lzma_ret) lzma_alone_encoder(
* will) have larger maximum expansion when encoding * will) have larger maximum expansion when encoding
* uncompressible data. Currently there is no function to * uncompressible data. Currently there is no function to
* calculate the maximum expansion of multi-call encoding. * calculate the maximum expansion of multi-call encoding.
*
* \param uncompressed_size Size in bytes of the uncompressed
* input data
*
* \return Maximum number of bytes needed to store the compressed data.
*/ */
extern LZMA_API(size_t) lzma_stream_buffer_bound(size_t uncompressed_size) extern LZMA_API(size_t) lzma_stream_buffer_bound(size_t uncompressed_size)
lzma_nothrow; lzma_nothrow;
@ -460,22 +499,23 @@ extern LZMA_API(size_t) lzma_stream_buffer_bound(size_t uncompressed_size)
/** /**
* \brief Single-call .xz Stream encoder * \brief Single-call .xz Stream encoder
* *
* \param filters Array of filters. This must be terminated with * \param filters Array of filters terminated with
* filters[n].id = LZMA_VLI_UNKNOWN. See filter.h * .id == LZMA_VLI_UNKNOWN. See filters.h for more
* for more information. * information.
* \param check Type of the integrity check to calculate from * \param check Type of the integrity check to calculate from
* uncompressed data. * uncompressed data.
* \param allocator lzma_allocator for custom allocator functions. * \param allocator lzma_allocator for custom allocator functions.
* Set to NULL to use malloc() and free(). * Set to NULL to use malloc() and free().
* \param in Beginning of the input buffer * \param in Beginning of the input buffer
* \param in_size Size of the input buffer * \param in_size Size of the input buffer
* \param out Beginning of the output buffer * \param[out] out Beginning of the output buffer
* \param out_pos The next byte will be written to out[*out_pos]. * \param[out] out_pos The next byte will be written to out[*out_pos].
* *out_pos is updated only if encoding succeeds. * *out_pos is updated only if encoding succeeds.
* \param out_size Size of the out buffer; the first byte into * \param out_size Size of the out buffer; the first byte into
* which no data is written to is out[out_size]. * which no data is written to is out[out_size].
* *
* \return - LZMA_OK: Encoding was successful. * \return Possible lzma_ret values:
* - LZMA_OK: Encoding was successful.
* - LZMA_BUF_ERROR: Not enough output buffer space. * - LZMA_BUF_ERROR: Not enough output buffer space.
* - LZMA_UNSUPPORTED_CHECK * - LZMA_UNSUPPORTED_CHECK
* - LZMA_OPTIONS_ERROR * - LZMA_OPTIONS_ERROR
@ -531,7 +571,12 @@ extern LZMA_API(lzma_ret) lzma_stream_buffer_encode(
* uses too where many small streams are needed. XZ Embedded includes a * uses too where many small streams are needed. XZ Embedded includes a
* decoder for this format. * decoder for this format.
* *
* \return - LZMA_STREAM_END: All good. Check the amounts of input used * \param strm Pointer to lzma_stream that is at least initialized
* with LZMA_STREAM_INIT.
* \param options Pointer to encoder options
*
* \return Possible lzma_ret values:
* - LZMA_STREAM_END: All good. Check the amounts of input used
* and output produced. Store the amount of input used * and output produced. Store the amount of input used
* (uncompressed size) as it needs to be known to decompress * (uncompressed size) as it needs to be known to decompress
* the data. * the data.
@ -648,7 +693,8 @@ extern LZMA_API(lzma_ret) lzma_microlzma_encoder(
/** /**
* \brief Initialize .xz Stream decoder * \brief Initialize .xz Stream decoder
* *
* \param strm Pointer to properly prepared lzma_stream * \param strm Pointer to lzma_stream that is at least initialized
* with LZMA_STREAM_INIT.
* \param memlimit Memory usage limit as bytes. Use UINT64_MAX * \param memlimit Memory usage limit as bytes. Use UINT64_MAX
* to effectively disable the limiter. liblzma * to effectively disable the limiter. liblzma
* 5.2.3 and earlier don't allow 0 here and return * 5.2.3 and earlier don't allow 0 here and return
@ -659,7 +705,8 @@ extern LZMA_API(lzma_ret) lzma_microlzma_encoder(
* LZMA_TELL_ANY_CHECK, LZMA_IGNORE_CHECK, * LZMA_TELL_ANY_CHECK, LZMA_IGNORE_CHECK,
* LZMA_CONCATENATED, LZMA_FAIL_FAST * LZMA_CONCATENATED, LZMA_FAIL_FAST
* *
* \return - LZMA_OK: Initialization was successful. * \return Possible lzma_ret values:
* - LZMA_OK: Initialization was successful.
* - LZMA_MEM_ERROR: Cannot allocate memory. * - LZMA_MEM_ERROR: Cannot allocate memory.
* - LZMA_OPTIONS_ERROR: Unsupported flags * - LZMA_OPTIONS_ERROR: Unsupported flags
* - LZMA_PROG_ERROR * - LZMA_PROG_ERROR
@ -672,9 +719,6 @@ extern LZMA_API(lzma_ret) lzma_stream_decoder(
/** /**
* \brief Initialize multithreaded .xz Stream decoder * \brief Initialize multithreaded .xz Stream decoder
* *
* \param strm Pointer to properly prepared lzma_stream
* \param options Pointer to multithreaded compression options
*
* The decoder can decode multiple Blocks in parallel. This requires that each * The decoder can decode multiple Blocks in parallel. This requires that each
* Block Header contains the Compressed Size and Uncompressed size fields * Block Header contains the Compressed Size and Uncompressed size fields
* which are added by the multi-threaded encoder, see lzma_stream_encoder_mt(). * which are added by the multi-threaded encoder, see lzma_stream_encoder_mt().
@ -688,7 +732,12 @@ extern LZMA_API(lzma_ret) lzma_stream_decoder(
* This function behaves like lzma_stream_decoder() when options->threads == 1 * This function behaves like lzma_stream_decoder() when options->threads == 1
* and options->memlimit_threading <= 1. * and options->memlimit_threading <= 1.
* *
* \return - LZMA_OK: Initialization was successful. * \param strm Pointer to lzma_stream that is at least initialized
* with LZMA_STREAM_INIT.
* \param options Pointer to multithreaded compression options
*
* \return Possible lzma_ret values:
* - LZMA_OK: Initialization was successful.
* - LZMA_MEM_ERROR: Cannot allocate memory. * - LZMA_MEM_ERROR: Cannot allocate memory.
* - LZMA_MEMLIMIT_ERROR: Memory usage limit was reached. * - LZMA_MEMLIMIT_ERROR: Memory usage limit was reached.
* - LZMA_OPTIONS_ERROR: Unsupported flags. * - LZMA_OPTIONS_ERROR: Unsupported flags.
@ -715,7 +764,8 @@ extern LZMA_API(lzma_ret) lzma_stream_decoder_mt(
* as it doesn't support any decoder flags. It will return LZMA_STREAM_END * as it doesn't support any decoder flags. It will return LZMA_STREAM_END
* after one .lzma stream.) * after one .lzma stream.)
* *
* \param strm Pointer to properly prepared lzma_stream * \param strm Pointer to lzma_stream that is at least initialized
* with LZMA_STREAM_INIT.
* \param memlimit Memory usage limit as bytes. Use UINT64_MAX * \param memlimit Memory usage limit as bytes. Use UINT64_MAX
* to effectively disable the limiter. liblzma * to effectively disable the limiter. liblzma
* 5.2.3 and earlier don't allow 0 here and return * 5.2.3 and earlier don't allow 0 here and return
@ -726,7 +776,8 @@ extern LZMA_API(lzma_ret) lzma_stream_decoder_mt(
* LZMA_TELL_ANY_CHECK, LZMA_IGNORE_CHECK, * LZMA_TELL_ANY_CHECK, LZMA_IGNORE_CHECK,
* LZMA_CONCATENATED, LZMA_FAIL_FAST * LZMA_CONCATENATED, LZMA_FAIL_FAST
* *
* \return - LZMA_OK: Initialization was successful. * \return Possible lzma_ret values:
* - LZMA_OK: Initialization was successful.
* - LZMA_MEM_ERROR: Cannot allocate memory. * - LZMA_MEM_ERROR: Cannot allocate memory.
* - LZMA_OPTIONS_ERROR: Unsupported flags * - LZMA_OPTIONS_ERROR: Unsupported flags
* - LZMA_PROG_ERROR * - LZMA_PROG_ERROR
@ -739,18 +790,20 @@ extern LZMA_API(lzma_ret) lzma_auto_decoder(
/** /**
* \brief Initialize .lzma decoder (legacy file format) * \brief Initialize .lzma decoder (legacy file format)
* *
* \param strm Pointer to properly prepared lzma_stream * Valid `action' arguments to lzma_code() are LZMA_RUN and LZMA_FINISH.
* There is no need to use LZMA_FINISH, but it's allowed because it may
* simplify certain types of applications.
*
* \param strm Pointer to lzma_stream that is at least initialized
* with LZMA_STREAM_INIT.
* \param memlimit Memory usage limit as bytes. Use UINT64_MAX * \param memlimit Memory usage limit as bytes. Use UINT64_MAX
* to effectively disable the limiter. liblzma * to effectively disable the limiter. liblzma
* 5.2.3 and earlier don't allow 0 here and return * 5.2.3 and earlier don't allow 0 here and return
* LZMA_PROG_ERROR; later versions treat 0 as if 1 * LZMA_PROG_ERROR; later versions treat 0 as if 1
* had been specified. * had been specified.
* *
* Valid `action' arguments to lzma_code() are LZMA_RUN and LZMA_FINISH. * \return Possible lzma_ret values:
* There is no need to use LZMA_FINISH, but it's allowed because it may * - LZMA_OK
* simplify certain types of applications.
*
* \return - LZMA_OK
* - LZMA_MEM_ERROR * - LZMA_MEM_ERROR
* - LZMA_PROG_ERROR * - LZMA_PROG_ERROR
*/ */
@ -762,18 +815,6 @@ extern LZMA_API(lzma_ret) lzma_alone_decoder(
/** /**
* \brief Initialize .lz (lzip) decoder (a foreign file format) * \brief Initialize .lz (lzip) decoder (a foreign file format)
* *
* \param strm Pointer to properly prepared lzma_stream
* \param memlimit Memory usage limit as bytes. Use UINT64_MAX
* to effectively disable the limiter.
* \param flags Bitwise-or of flags, or zero for no flags.
* All decoder flags listed above are supported
* although only LZMA_CONCATENATED and (in very rare
* cases) LZMA_IGNORE_CHECK are actually useful.
* LZMA_TELL_NO_CHECK, LZMA_TELL_UNSUPPORTED_CHECK,
* and LZMA_FAIL_FAST do nothing. LZMA_TELL_ANY_CHECK
* is supported for consistency only as CRC32 is
* always used in the .lz format.
*
* This decoder supports the .lz format version 0 and the unextended .lz * This decoder supports the .lz format version 0 and the unextended .lz
* format version 1: * format version 1:
* *
@ -807,7 +848,21 @@ extern LZMA_API(lzma_ret) lzma_alone_decoder(
* one should ensure that none of the first four bytes of trailing data are * one should ensure that none of the first four bytes of trailing data are
* equal to the magic bytes because lzip >= 1.20 requires it by default. * equal to the magic bytes because lzip >= 1.20 requires it by default.
* *
* \return - LZMA_OK: Initialization was successful. * \param strm Pointer to lzma_stream that is at least initialized
* with LZMA_STREAM_INIT.
* \param memlimit Memory usage limit as bytes. Use UINT64_MAX
* to effectively disable the limiter.
* \param flags Bitwise-or of flags, or zero for no flags.
* All decoder flags listed above are supported
* although only LZMA_CONCATENATED and (in very rare
* cases) LZMA_IGNORE_CHECK are actually useful.
* LZMA_TELL_NO_CHECK, LZMA_TELL_UNSUPPORTED_CHECK,
* and LZMA_FAIL_FAST do nothing. LZMA_TELL_ANY_CHECK
* is supported for consistency only as CRC32 is
* always used in the .lz format.
*
* \return Possible lzma_ret values:
* - LZMA_OK: Initialization was successful.
* - LZMA_MEM_ERROR: Cannot allocate memory. * - LZMA_MEM_ERROR: Cannot allocate memory.
* - LZMA_OPTIONS_ERROR: Unsupported flags * - LZMA_OPTIONS_ERROR: Unsupported flags
* - LZMA_PROG_ERROR * - LZMA_PROG_ERROR
@ -836,13 +891,14 @@ extern LZMA_API(lzma_ret) lzma_lzip_decoder(
* *in_pos is updated only if decoding succeeds. * *in_pos is updated only if decoding succeeds.
* \param in_size Size of the input buffer; the first byte that * \param in_size Size of the input buffer; the first byte that
* won't be read is in[in_size]. * won't be read is in[in_size].
* \param out Beginning of the output buffer * \param[out] out Beginning of the output buffer
* \param out_pos The next byte will be written to out[*out_pos]. * \param[out] out_pos The next byte will be written to out[*out_pos].
* *out_pos is updated only if decoding succeeds. * *out_pos is updated only if decoding succeeds.
* \param out_size Size of the out buffer; the first byte into * \param out_size Size of the out buffer; the first byte into
* which no data is written to is out[out_size]. * which no data is written to is out[out_size].
* *
* \return - LZMA_OK: Decoding was successful. * \return Possible lzma_ret values:
* - LZMA_OK: Decoding was successful.
* - LZMA_FORMAT_ERROR * - LZMA_FORMAT_ERROR
* - LZMA_OPTIONS_ERROR * - LZMA_OPTIONS_ERROR
* - LZMA_DATA_ERROR * - LZMA_DATA_ERROR
@ -867,12 +923,13 @@ extern LZMA_API(lzma_ret) lzma_stream_buffer_decode(
/** /**
* \brief MicroLZMA decoder * \brief MicroLZMA decoder
* *
* See lzma_microlzma_decoder() for more information. * See lzma_microlzma_encoder() for more information.
* *
* The lzma_code() usage with this decoder is completely normal. The * The lzma_code() usage with this decoder is completely normal. The
* special behavior of lzma_code() applies to lzma_microlzma_encoder() only. * special behavior of lzma_code() applies to lzma_microlzma_encoder() only.
* *
* \param strm Pointer to properly prepared lzma_stream * \param strm Pointer to lzma_stream that is at least initialized
* with LZMA_STREAM_INIT.
* \param comp_size Compressed size of the MicroLZMA stream. * \param comp_size Compressed size of the MicroLZMA stream.
* The caller must somehow know this exactly. * The caller must somehow know this exactly.
* \param uncomp_size Uncompressed size of the MicroLZMA stream. * \param uncomp_size Uncompressed size of the MicroLZMA stream.
@ -897,6 +954,12 @@ extern LZMA_API(lzma_ret) lzma_stream_buffer_decode(
* the implementation in XZ Embedded it doesn't * the implementation in XZ Embedded it doesn't
* affect the memory usage if one specifies bigger * affect the memory usage if one specifies bigger
* dictionary than actually required.) * dictionary than actually required.)
*
* \return Possible lzma_ret values:
* - LZMA_OK
* - LZMA_MEM_ERROR
* - LZMA_OPTIONS_ERROR
* - LZMA_PROG_ERROR
*/ */
extern LZMA_API(lzma_ret) lzma_microlzma_decoder( extern LZMA_API(lzma_ret) lzma_microlzma_decoder(
lzma_stream *strm, uint64_t comp_size, lzma_stream *strm, uint64_t comp_size,

View File

@ -1,6 +1,7 @@
/** /**
* \file lzma/delta.h * \file lzma/delta.h
* \brief Delta filter * \brief Delta filter
* \note Never include this file directly. Use <lzma.h> instead.
*/ */
/* /*
@ -8,8 +9,6 @@
* *
* This file has been put into the public domain. * This file has been put into the public domain.
* You can do whatever you want with this file. * You can do whatever you want with this file.
*
* See ../lzma.h for information about liblzma as a whole.
*/ */
#ifndef LZMA_H_INTERNAL #ifndef LZMA_H_INTERNAL
@ -57,7 +56,15 @@ typedef struct {
* - 24-bit RGB image data: distance = 3 bytes * - 24-bit RGB image data: distance = 3 bytes
*/ */
uint32_t dist; uint32_t dist;
/**
* \brief Minimum value for lzma_options_delta.dist.
*/
# define LZMA_DELTA_DIST_MIN 1 # define LZMA_DELTA_DIST_MIN 1
/**
* \brief Maximum value for lzma_options_delta.dist.
*/
# define LZMA_DELTA_DIST_MAX 256 # define LZMA_DELTA_DIST_MAX 256
/* /*
@ -67,11 +74,23 @@ typedef struct {
* when type is LZMA_DELTA_TYPE_BYTE, so it is safe to leave these * when type is LZMA_DELTA_TYPE_BYTE, so it is safe to leave these
* uninitialized. * uninitialized.
*/ */
/** \private Reserved member. */
uint32_t reserved_int1; uint32_t reserved_int1;
/** \private Reserved member. */
uint32_t reserved_int2; uint32_t reserved_int2;
/** \private Reserved member. */
uint32_t reserved_int3; uint32_t reserved_int3;
/** \private Reserved member. */
uint32_t reserved_int4; uint32_t reserved_int4;
/** \private Reserved member. */
void *reserved_ptr1; void *reserved_ptr1;
/** \private Reserved member. */
void *reserved_ptr2; void *reserved_ptr2;
} lzma_options_delta; } lzma_options_delta;

View File

@ -1,6 +1,7 @@
/** /**
* \file lzma/filter.h * \file lzma/filter.h
* \brief Common filter related types and functions * \brief Common filter related types and functions
* \note Never include this file directly. Use <lzma.h> instead.
*/ */
/* /*
@ -8,8 +9,6 @@
* *
* This file has been put into the public domain. * This file has been put into the public domain.
* You can do whatever you want with this file. * You can do whatever you want with this file.
*
* See ../lzma.h for information about liblzma as a whole.
*/ */
#ifndef LZMA_H_INTERNAL #ifndef LZMA_H_INTERNAL
@ -29,7 +28,7 @@
/** /**
* \brief Filter options * \brief Filter options
* *
* This structure is used to pass Filter ID and a pointer filter's * This structure is used to pass a Filter ID and a pointer to the filter's
* options to liblzma. A few functions work with a single lzma_filter * options to liblzma. A few functions work with a single lzma_filter
* structure, while most functions expect a filter chain. * structure, while most functions expect a filter chain.
* *
@ -37,8 +36,8 @@
* The array is terminated with .id = LZMA_VLI_UNKNOWN. Thus, the filter * The array is terminated with .id = LZMA_VLI_UNKNOWN. Thus, the filter
* array must have LZMA_FILTERS_MAX + 1 elements (that is, five) to * array must have LZMA_FILTERS_MAX + 1 elements (that is, five) to
* be able to hold any arbitrary filter chain. This is important when * be able to hold any arbitrary filter chain. This is important when
* using lzma_block_header_decode() from block.h, because too small * using lzma_block_header_decode() from block.h, because a filter array
* array would make liblzma write past the end of the filters array. * that is too small would make liblzma write past the end of the array.
*/ */
typedef struct { typedef struct {
/** /**
@ -68,12 +67,12 @@ typedef struct {
/** /**
* \brief Test if the given Filter ID is supported for encoding * \brief Test if the given Filter ID is supported for encoding
* *
* Return true if the give Filter ID is supported for encoding by this * \param id Filter ID
* liblzma build. Otherwise false is returned.
* *
* There is no way to list which filters are available in this particular * \return lzma_bool:
* liblzma version and build. It would be useless, because the application * - true if the Filter ID is supported for encoding by this
* couldn't know what kind of options the filter would need. * liblzma build.
* - false otherwise.
*/ */
extern LZMA_API(lzma_bool) lzma_filter_encoder_is_supported(lzma_vli id) extern LZMA_API(lzma_bool) lzma_filter_encoder_is_supported(lzma_vli id)
lzma_nothrow lzma_attr_const; lzma_nothrow lzma_attr_const;
@ -82,8 +81,12 @@ extern LZMA_API(lzma_bool) lzma_filter_encoder_is_supported(lzma_vli id)
/** /**
* \brief Test if the given Filter ID is supported for decoding * \brief Test if the given Filter ID is supported for decoding
* *
* Return true if the give Filter ID is supported for decoding by this * \param id Filter ID
* liblzma build. Otherwise false is returned. *
* \return lzma_bool:
* - true if the Filter ID is supported for decoding by this
* liblzma build.
* - false otherwise.
*/ */
extern LZMA_API(lzma_bool) lzma_filter_decoder_is_supported(lzma_vli id) extern LZMA_API(lzma_bool) lzma_filter_decoder_is_supported(lzma_vli id)
lzma_nothrow lzma_attr_const; lzma_nothrow lzma_attr_const;
@ -112,7 +115,14 @@ extern LZMA_API(lzma_bool) lzma_filter_decoder_is_supported(lzma_vli id)
* array and leave its contents in an undefined state if an error occurs. * array and leave its contents in an undefined state if an error occurs.
* liblzma 5.2.7 and newer only modify the dest array when returning LZMA_OK. * liblzma 5.2.7 and newer only modify the dest array when returning LZMA_OK.
* *
* \return - LZMA_OK * \param src Array of filters terminated with
* .id == LZMA_VLI_UNKNOWN.
* \param[out] dest Destination filter array
* \param allocator lzma_allocator for custom allocator functions.
* Set to NULL to use malloc() and free().
*
* \return Possible lzma_ret values:
* - LZMA_OK
* - LZMA_MEM_ERROR * - LZMA_MEM_ERROR
* - LZMA_OPTIONS_ERROR: Unsupported Filter ID and its options * - LZMA_OPTIONS_ERROR: Unsupported Filter ID and its options
* is not NULL. * is not NULL.
@ -137,8 +147,13 @@ extern LZMA_API(lzma_ret) lzma_filters_copy(
* - options will be set to NULL. * - options will be set to NULL.
* - id will be set to LZMA_VLI_UNKNOWN. * - id will be set to LZMA_VLI_UNKNOWN.
* *
* If filters is NULL, this does nothing but remember that this never frees * If filters is NULL, this does nothing. Again, this never frees the
* the filters array itself. * filters array itself.
*
* \param filters Array of filters terminated with
* .id == LZMA_VLI_UNKNOWN.
* \param allocator lzma_allocator for custom allocator functions.
* Set to NULL to use malloc() and free().
*/ */
extern LZMA_API(void) lzma_filters_free( extern LZMA_API(void) lzma_filters_free(
lzma_filter *filters, const lzma_allocator *allocator) lzma_filter *filters, const lzma_allocator *allocator)
@ -156,9 +171,7 @@ extern LZMA_API(void) lzma_filters_free(
* .id == LZMA_VLI_UNKNOWN. * .id == LZMA_VLI_UNKNOWN.
* *
* \return Number of bytes of memory required for the given * \return Number of bytes of memory required for the given
* filter chain when encoding. If an error occurs, * filter chain when encoding or UINT64_MAX on error.
* for example due to unsupported filter chain,
* UINT64_MAX is returned.
*/ */
extern LZMA_API(uint64_t) lzma_raw_encoder_memusage(const lzma_filter *filters) extern LZMA_API(uint64_t) lzma_raw_encoder_memusage(const lzma_filter *filters)
lzma_nothrow lzma_attr_pure; lzma_nothrow lzma_attr_pure;
@ -175,9 +188,7 @@ extern LZMA_API(uint64_t) lzma_raw_encoder_memusage(const lzma_filter *filters)
* .id == LZMA_VLI_UNKNOWN. * .id == LZMA_VLI_UNKNOWN.
* *
* \return Number of bytes of memory required for the given * \return Number of bytes of memory required for the given
* filter chain when decoding. If an error occurs, * filter chain when decoding or UINT64_MAX on error.
* for example due to unsupported filter chain,
* UINT64_MAX is returned.
*/ */
extern LZMA_API(uint64_t) lzma_raw_decoder_memusage(const lzma_filter *filters) extern LZMA_API(uint64_t) lzma_raw_decoder_memusage(const lzma_filter *filters)
lzma_nothrow lzma_attr_pure; lzma_nothrow lzma_attr_pure;
@ -188,14 +199,16 @@ extern LZMA_API(uint64_t) lzma_raw_decoder_memusage(const lzma_filter *filters)
* *
* This function may be useful when implementing custom file formats. * This function may be useful when implementing custom file formats.
* *
* \param strm Pointer to properly prepared lzma_stream
* \param filters Array of lzma_filter structures. The end of the
* array must be marked with .id = LZMA_VLI_UNKNOWN.
*
* The `action' with lzma_code() can be LZMA_RUN, LZMA_SYNC_FLUSH (if the * The `action' with lzma_code() can be LZMA_RUN, LZMA_SYNC_FLUSH (if the
* filter chain supports it), or LZMA_FINISH. * filter chain supports it), or LZMA_FINISH.
* *
* \return - LZMA_OK * \param strm Pointer to lzma_stream that is at least
* initialized with LZMA_STREAM_INIT.
* \param filters Array of filters terminated with
* .id == LZMA_VLI_UNKNOWN.
*
* \return Possible lzma_ret values:
* - LZMA_OK
* - LZMA_MEM_ERROR * - LZMA_MEM_ERROR
* - LZMA_OPTIONS_ERROR * - LZMA_OPTIONS_ERROR
* - LZMA_PROG_ERROR * - LZMA_PROG_ERROR
@ -213,7 +226,13 @@ extern LZMA_API(lzma_ret) lzma_raw_encoder(
* The `action' with lzma_code() can be LZMA_RUN or LZMA_FINISH. Using * The `action' with lzma_code() can be LZMA_RUN or LZMA_FINISH. Using
* LZMA_FINISH is not required, it is supported just for convenience. * LZMA_FINISH is not required, it is supported just for convenience.
* *
* \return - LZMA_OK * \param strm Pointer to lzma_stream that is at least
* initialized with LZMA_STREAM_INIT.
* \param filters Array of filters terminated with
* .id == LZMA_VLI_UNKNOWN.
*
* \return Possible lzma_ret values:
* - LZMA_OK
* - LZMA_MEM_ERROR * - LZMA_MEM_ERROR
* - LZMA_OPTIONS_ERROR * - LZMA_OPTIONS_ERROR
* - LZMA_PROG_ERROR * - LZMA_PROG_ERROR
@ -249,7 +268,13 @@ extern LZMA_API(lzma_ret) lzma_raw_decoder(
* as if LZMA_FULL_FLUSH (Stream encoders) or LZMA_SYNC_FLUSH (Raw or Block * as if LZMA_FULL_FLUSH (Stream encoders) or LZMA_SYNC_FLUSH (Raw or Block
* encoder) had been used right before calling this function. * encoder) had been used right before calling this function.
* *
* \return - LZMA_OK * \param strm Pointer to lzma_stream that is at least
* initialized with LZMA_STREAM_INIT.
* \param filters Array of filters terminated with
* .id == LZMA_VLI_UNKNOWN.
*
* \return Possible lzma_ret values:
* - LZMA_OK
* - LZMA_MEM_ERROR * - LZMA_MEM_ERROR
* - LZMA_MEMLIMIT_ERROR * - LZMA_MEMLIMIT_ERROR
* - LZMA_OPTIONS_ERROR * - LZMA_OPTIONS_ERROR
@ -262,29 +287,30 @@ extern LZMA_API(lzma_ret) lzma_filters_update(
/** /**
* \brief Single-call raw encoder * \brief Single-call raw encoder
* *
* \param filters Array of lzma_filter structures. The end of the * \note There is no function to calculate how big output buffer
* array must be marked with .id = LZMA_VLI_UNKNOWN. * would surely be big enough. (lzma_stream_buffer_bound()
* works only for lzma_stream_buffer_encode(); raw encoder
* won't necessarily meet that bound.)
*
* \param filters Array of filters terminated with
* .id == LZMA_VLI_UNKNOWN.
* \param allocator lzma_allocator for custom allocator functions. * \param allocator lzma_allocator for custom allocator functions.
* Set to NULL to use malloc() and free(). * Set to NULL to use malloc() and free().
* \param in Beginning of the input buffer * \param in Beginning of the input buffer
* \param in_size Size of the input buffer * \param in_size Size of the input buffer
* \param out Beginning of the output buffer * \param[out] out Beginning of the output buffer
* \param out_pos The next byte will be written to out[*out_pos]. * \param[out] out_pos The next byte will be written to out[*out_pos].
* *out_pos is updated only if encoding succeeds. * *out_pos is updated only if encoding succeeds.
* \param out_size Size of the out buffer; the first byte into * \param out_size Size of the out buffer; the first byte into
* which no data is written to is out[out_size]. * which no data is written to is out[out_size].
* *
* \return - LZMA_OK: Encoding was successful. * \return Possible lzma_ret values:
* - LZMA_OK: Encoding was successful.
* - LZMA_BUF_ERROR: Not enough output buffer space. * - LZMA_BUF_ERROR: Not enough output buffer space.
* - LZMA_OPTIONS_ERROR * - LZMA_OPTIONS_ERROR
* - LZMA_MEM_ERROR * - LZMA_MEM_ERROR
* - LZMA_DATA_ERROR * - LZMA_DATA_ERROR
* - LZMA_PROG_ERROR * - LZMA_PROG_ERROR
*
* \note There is no function to calculate how big output buffer
* would surely be big enough. (lzma_stream_buffer_bound()
* works only for lzma_stream_buffer_encode(); raw encoder
* won't necessarily meet that bound.)
*/ */
extern LZMA_API(lzma_ret) lzma_raw_buffer_encode( extern LZMA_API(lzma_ret) lzma_raw_buffer_encode(
const lzma_filter *filters, const lzma_allocator *allocator, const lzma_filter *filters, const lzma_allocator *allocator,
@ -295,8 +321,8 @@ extern LZMA_API(lzma_ret) lzma_raw_buffer_encode(
/** /**
* \brief Single-call raw decoder * \brief Single-call raw decoder
* *
* \param filters Array of lzma_filter structures. The end of the * \param filters Array of filters terminated with
* array must be marked with .id = LZMA_VLI_UNKNOWN. * .id == LZMA_VLI_UNKNOWN.
* \param allocator lzma_allocator for custom allocator functions. * \param allocator lzma_allocator for custom allocator functions.
* Set to NULL to use malloc() and free(). * Set to NULL to use malloc() and free().
* \param in Beginning of the input buffer * \param in Beginning of the input buffer
@ -304,11 +330,19 @@ extern LZMA_API(lzma_ret) lzma_raw_buffer_encode(
* *in_pos is updated only if decoding succeeds. * *in_pos is updated only if decoding succeeds.
* \param in_size Size of the input buffer; the first byte that * \param in_size Size of the input buffer; the first byte that
* won't be read is in[in_size]. * won't be read is in[in_size].
* \param out Beginning of the output buffer * \param[out] out Beginning of the output buffer
* \param out_pos The next byte will be written to out[*out_pos]. * \param[out] out_pos The next byte will be written to out[*out_pos].
* *out_pos is updated only if encoding succeeds. * *out_pos is updated only if encoding succeeds.
* \param out_size Size of the out buffer; the first byte into * \param out_size Size of the out buffer; the first byte into
* which no data is written to is out[out_size]. * which no data is written to is out[out_size].
*
* \return Possible lzma_ret values:
* - LZMA_OK: Decoding was successful.
* - LZMA_BUF_ERROR: Not enough output buffer space.
* - LZMA_OPTIONS_ERROR
* - LZMA_MEM_ERROR
* - LZMA_DATA_ERROR
* - LZMA_PROG_ERROR
*/ */
extern LZMA_API(lzma_ret) lzma_raw_buffer_decode( extern LZMA_API(lzma_ret) lzma_raw_buffer_decode(
const lzma_filter *filters, const lzma_allocator *allocator, const lzma_filter *filters, const lzma_allocator *allocator,
@ -322,18 +356,19 @@ extern LZMA_API(lzma_ret) lzma_raw_buffer_decode(
* This function may be useful when implementing custom file formats * This function may be useful when implementing custom file formats
* using the raw encoder and decoder. * using the raw encoder and decoder.
* *
* \param size Pointer to uint32_t to hold the size of the properties
* \param filter Filter ID and options (the size of the properties may
* vary depending on the options)
*
* \return - LZMA_OK
* - LZMA_OPTIONS_ERROR
* - LZMA_PROG_ERROR
*
* \note This function validates the Filter ID, but does not * \note This function validates the Filter ID, but does not
* necessarily validate the options. Thus, it is possible * necessarily validate the options. Thus, it is possible
* that this returns LZMA_OK while the following call to * that this returns LZMA_OK while the following call to
* lzma_properties_encode() returns LZMA_OPTIONS_ERROR. * lzma_properties_encode() returns LZMA_OPTIONS_ERROR.
*
* \param[out] size Pointer to uint32_t to hold the size of the properties
* \param filter Filter ID and options (the size of the properties may
* vary depending on the options)
*
* \return Possible lzma_ret values:
* - LZMA_OK
* - LZMA_OPTIONS_ERROR
* - LZMA_PROG_ERROR
*/ */
extern LZMA_API(lzma_ret) lzma_properties_size( extern LZMA_API(lzma_ret) lzma_properties_size(
uint32_t *size, const lzma_filter *filter) lzma_nothrow; uint32_t *size, const lzma_filter *filter) lzma_nothrow;
@ -342,15 +377,6 @@ extern LZMA_API(lzma_ret) lzma_properties_size(
/** /**
* \brief Encode the Filter Properties field * \brief Encode the Filter Properties field
* *
* \param filter Filter ID and options
* \param props Buffer to hold the encoded options. The size of
* buffer must have been already determined with
* lzma_properties_size().
*
* \return - LZMA_OK
* - LZMA_OPTIONS_ERROR
* - LZMA_PROG_ERROR
*
* \note Even this function won't validate more options than actually * \note Even this function won't validate more options than actually
* necessary. Thus, it is possible that encoding the properties * necessary. Thus, it is possible that encoding the properties
* succeeds but using the same options to initialize the encoder * succeeds but using the same options to initialize the encoder
@ -360,6 +386,15 @@ extern LZMA_API(lzma_ret) lzma_properties_size(
* of the Filter Properties field is zero, calling * of the Filter Properties field is zero, calling
* lzma_properties_encode() is not required, but it * lzma_properties_encode() is not required, but it
* won't do any harm either. * won't do any harm either.
*
* \param filter Filter ID and options
* \param[out] props Buffer to hold the encoded options. The size of
* the buffer must have been already determined with
* lzma_properties_size().
*
* \return Possible lzma_ret values:
* - LZMA_OK
* - LZMA_PROG_ERROR
*/ */
extern LZMA_API(lzma_ret) lzma_properties_encode( extern LZMA_API(lzma_ret) lzma_properties_encode(
const lzma_filter *filter, uint8_t *props) lzma_nothrow; const lzma_filter *filter, uint8_t *props) lzma_nothrow;
@ -375,15 +410,16 @@ extern LZMA_API(lzma_ret) lzma_properties_encode(
* it's application's responsibility to free it when * it's application's responsibility to free it when
* appropriate. filter->options is set to NULL if * appropriate. filter->options is set to NULL if
* there are no properties or if an error occurs. * there are no properties or if an error occurs.
* \param allocator Custom memory allocator used to allocate the * \param allocator lzma_allocator for custom allocator functions.
* options. Set to NULL to use the default malloc(), * Set to NULL to use malloc() and free().
* and in case of an error, also free(). * and in case of an error, also free().
* \param props Input buffer containing the properties. * \param props Input buffer containing the properties.
* \param props_size Size of the properties. This must be the exact * \param props_size Size of the properties. This must be the exact
* size; giving too much or too little input will * size; giving too much or too little input will
* return LZMA_OPTIONS_ERROR. * return LZMA_OPTIONS_ERROR.
* *
* \return - LZMA_OK * \return Possible lzma_ret values:
* - LZMA_OK
* - LZMA_OPTIONS_ERROR * - LZMA_OPTIONS_ERROR
* - LZMA_MEM_ERROR * - LZMA_MEM_ERROR
*/ */
@ -398,18 +434,19 @@ extern LZMA_API(lzma_ret) lzma_properties_decode(
* Knowing the size of Filter Flags is useful to know when allocating * Knowing the size of Filter Flags is useful to know when allocating
* memory to hold the encoded Filter Flags. * memory to hold the encoded Filter Flags.
* *
* \param size Pointer to integer to hold the calculated size * \note If you need to calculate size of List of Filter Flags,
* you need to loop over every lzma_filter entry.
*
* \param[out] size Pointer to integer to hold the calculated size
* \param filter Filter ID and associated options whose encoded * \param filter Filter ID and associated options whose encoded
* size is to be calculated * size is to be calculated
* *
* \return - LZMA_OK: *size set successfully. Note that this doesn't * \return Possible lzma_ret values:
* - LZMA_OK: *size set successfully. Note that this doesn't
* guarantee that filter->options is valid, thus * guarantee that filter->options is valid, thus
* lzma_filter_flags_encode() may still fail. * lzma_filter_flags_encode() may still fail.
* - LZMA_OPTIONS_ERROR: Unknown Filter ID or unsupported options. * - LZMA_OPTIONS_ERROR: Unknown Filter ID or unsupported options.
* - LZMA_PROG_ERROR: Invalid options * - LZMA_PROG_ERROR: Invalid options
*
* \note If you need to calculate size of List of Filter Flags,
* you need to loop over every lzma_filter entry.
*/ */
extern LZMA_API(lzma_ret) lzma_filter_flags_size( extern LZMA_API(lzma_ret) lzma_filter_flags_size(
uint32_t *size, const lzma_filter *filter) uint32_t *size, const lzma_filter *filter)
@ -423,12 +460,13 @@ extern LZMA_API(lzma_ret) lzma_filter_flags_size(
* This is due to how this function is used internally by liblzma. * This is due to how this function is used internally by liblzma.
* *
* \param filter Filter ID and options to be encoded * \param filter Filter ID and options to be encoded
* \param out Beginning of the output buffer * \param[out] out Beginning of the output buffer
* \param out_pos out[*out_pos] is the next write position. This * \param[out] out_pos out[*out_pos] is the next write position. This
* is updated by the encoder. * is updated by the encoder.
* \param out_size out[out_size] is the first byte to not write. * \param out_size out[out_size] is the first byte to not write.
* *
* \return - LZMA_OK: Encoding was successful. * \return Possible lzma_ret values:
* - LZMA_OK: Encoding was successful.
* - LZMA_OPTIONS_ERROR: Invalid or unsupported options. * - LZMA_OPTIONS_ERROR: Invalid or unsupported options.
* - LZMA_PROG_ERROR: Invalid options or not enough output * - LZMA_PROG_ERROR: Invalid options or not enough output
* buffer space (you should have checked it with * buffer space (you should have checked it with
@ -443,11 +481,26 @@ extern LZMA_API(lzma_ret) lzma_filter_flags_encode(const lzma_filter *filter,
* \brief Decode Filter Flags from given buffer * \brief Decode Filter Flags from given buffer
* *
* The decoded result is stored into *filter. The old value of * The decoded result is stored into *filter. The old value of
* filter->options is not free()d. * filter->options is not free()d. If anything other than LZMA_OK
* is returned, filter->options is set to NULL.
* *
* \return - LZMA_OK * \param[out] filter Destination filter. The decoded Filter ID will
* be stored in filter->id. If options are needed
* they will be allocated and the pointer will be
* stored in filter->options.
* \param allocator lzma_allocator for custom allocator functions.
* Set to NULL to use malloc() and free().
* \param in Beginning of the input buffer
* \param[out] in_pos The next byte will be read from in[*in_pos].
* *in_pos is updated only if decoding succeeds.
* \param in_size Size of the input buffer; the first byte that
* won't be read is in[in_size].
*
* \return Possible lzma_ret values:
* - LZMA_OK
* - LZMA_OPTIONS_ERROR * - LZMA_OPTIONS_ERROR
* - LZMA_MEM_ERROR * - LZMA_MEM_ERROR
* - LZMA_DATA_ERROR
* - LZMA_PROG_ERROR * - LZMA_PROG_ERROR
*/ */
extern LZMA_API(lzma_ret) lzma_filter_flags_decode( extern LZMA_API(lzma_ret) lzma_filter_flags_decode(
@ -474,8 +527,9 @@ extern LZMA_API(lzma_ret) lzma_filter_flags_decode(
* *
* By default lzma_str_to_filters() can return an error if the filter chain * By default lzma_str_to_filters() can return an error if the filter chain
* as a whole isn't usable in the .xz format or in the raw encoder or decoder. * as a whole isn't usable in the .xz format or in the raw encoder or decoder.
* With this flag the validation is skipped (this doesn't affect the handling * With this flag, this validation is skipped. This flag doesn't affect the
* of the individual filter options). * handling of the individual filter options. To allow non-.xz filters also
* LZMA_STR_ALL_FILTERS is needed.
*/ */
#define LZMA_STR_NO_VALIDATION UINT32_C(0x02) #define LZMA_STR_NO_VALIDATION UINT32_C(0x02)
@ -573,34 +627,6 @@ extern LZMA_API(lzma_ret) lzma_filter_flags_decode(
* lzma_str_list_filters(). See the xz man page for the description * lzma_str_list_filters(). See the xz man page for the description
* of filter names and options. * of filter names and options.
* *
* \param str User-supplied string describing a preset or
* a filter chain. If a default value is needed and
* you don't know what would be good, use "6" since
* that is the default preset in xz too.
* \param error_pos If this isn't NULL, this value will be set on
* both success and on all errors. This tells the
* location of the error in the string. This is
* an int to make it straightforward to use this
* as printf() field width. The value is guaranteed
* to be in the range [0, INT_MAX] even if strlen(str)
* somehow was greater than INT_MAX.
* \param filters An array of lzma_filter structures. There must
* be LZMA_FILTERS_MAX + 1 (that is, five) elements
* in the array. The old contents are ignored so it
* doesn't need to be initialized. This array is
* modified only if this function returns LZMA_OK.
* Once the allocated filter options are no longer
* needed, lzma_filters_free() can be used to free the
* options (it doesn't free the filters array itself).
* \param flags Bitwise-or of zero or more of the flags
* LZMA_STR_ALL_FILTERS and LZMA_STR_NO_VALIDATION.
* \param allocator lzma_allocator for custom allocator functions.
* Set to NULL to use malloc() and free().
*
* \return On success, NULL is returned. On error, a statically-allocated
* error message is returned which together with the error_pos
* should give some idea what is wrong.
*
* For command line applications, below is an example how an error message * For command line applications, below is an example how an error message
* can be displayed. Note the use of an empty string for the field width. * can be displayed. Note the use of an empty string for the field width.
* If "^" was used there it would create an off-by-one error except at * If "^" was used there it would create an off-by-one error except at
@ -618,6 +644,34 @@ extern LZMA_API(lzma_ret) lzma_filter_flags_decode(
* printf("%s: %s\n", argv[0], msg); * printf("%s: %s\n", argv[0], msg);
* } * }
* \endcode * \endcode
*
* \param str User-supplied string describing a preset or
* a filter chain. If a default value is needed and
* you don't know what would be good, use "6" since
* that is the default preset in xz too.
* \param[out] error_pos If this isn't NULL, this value will be set on
* both success and on all errors. This tells the
* location of the error in the string. This is
* an int to make it straightforward to use this
* as printf() field width. The value is guaranteed
* to be in the range [0, INT_MAX] even if strlen(str)
* somehow was greater than INT_MAX.
* \param[out] filters An array of lzma_filter structures. There must
* be LZMA_FILTERS_MAX + 1 (that is, five) elements
* in the array. The old contents are ignored so it
* doesn't need to be initialized. This array is
* modified only if this function returns NULL.
* Once the allocated filter options are no longer
* needed, lzma_filters_free() can be used to free the
* options (it doesn't free the filters array itself).
* \param flags Bitwise-or of zero or more of the flags
* LZMA_STR_ALL_FILTERS and LZMA_STR_NO_VALIDATION.
* \param allocator lzma_allocator for custom allocator functions.
* Set to NULL to use malloc() and free().
*
* \return On success, NULL is returned. On error, a statically-allocated
* error message is returned which together with the error_pos
* should give some idea what is wrong.
*/ */
extern LZMA_API(const char *) lzma_str_to_filters( extern LZMA_API(const char *) lzma_str_to_filters(
const char *str, int *error_pos, lzma_filter *filters, const char *str, int *error_pos, lzma_filter *filters,
@ -646,19 +700,20 @@ extern LZMA_API(const char *) lzma_str_to_filters(
* specify "6" to lzma_str_to_filters() then lzma_str_from_filters() * specify "6" to lzma_str_to_filters() then lzma_str_from_filters()
* will produce a string containing "lzma2". * will produce a string containing "lzma2".
* *
* \param str On success *str will be set to point to an * \param[out] str On success *str will be set to point to an
* allocated string describing the given filter * allocated string describing the given filter
* chain. Old value is ignored. On error *str is * chain. Old value is ignored. On error *str is
* always set to NULL. * always set to NULL.
* \param filters Array of 1-4 filters and a terminating element * \param filters Array of filters terminated with
* with .id = LZMA_VLI_UNKNOWN. * .id == LZMA_VLI_UNKNOWN.
* \param flags Bitwise-or of zero or more of the flags * \param flags Bitwise-or of zero or more of the flags
* LZMA_STR_ENCODER, LZMA_STR_DECODER, * LZMA_STR_ENCODER, LZMA_STR_DECODER,
* LZMA_STR_GETOPT_LONG, and LZMA_STR_NO_SPACES. * LZMA_STR_GETOPT_LONG, and LZMA_STR_NO_SPACES.
* \param allocator lzma_allocator for custom allocator functions. * \param allocator lzma_allocator for custom allocator functions.
* Set to NULL to use malloc() and free(). * Set to NULL to use malloc() and free().
* *
* \return - LZMA_OK * \return Possible lzma_ret values:
* - LZMA_OK
* - LZMA_OPTIONS_ERROR: Empty filter chain * - LZMA_OPTIONS_ERROR: Empty filter chain
* (filters[0].id == LZMA_VLI_UNKNOWN) or the filter chain * (filters[0].id == LZMA_VLI_UNKNOWN) or the filter chain
* includes a Filter ID that is not supported by this function. * includes a Filter ID that is not supported by this function.
@ -687,7 +742,7 @@ extern LZMA_API(lzma_ret) lzma_str_from_filters(
* *
* - If LZMA_STR_ENCODER or LZMA_STR_DECODER is used then filters and * - If LZMA_STR_ENCODER or LZMA_STR_DECODER is used then filters and
* the supported options are listed one filter per line. There won't * the supported options are listed one filter per line. There won't
* be a '\n' after the last filter. * be a newline after the last filter.
* *
* - If LZMA_STR_ALL_FILTERS is used then the list will include also * - If LZMA_STR_ALL_FILTERS is used then the list will include also
* those filters that cannot be used in the .xz format (LZMA1). * those filters that cannot be used in the .xz format (LZMA1).
@ -703,7 +758,8 @@ extern LZMA_API(lzma_ret) lzma_str_from_filters(
* \param allocator lzma_allocator for custom allocator functions. * \param allocator lzma_allocator for custom allocator functions.
* Set to NULL to use malloc() and free(). * Set to NULL to use malloc() and free().
* *
* \return - LZMA_OK * \return Possible lzma_ret values:
* - LZMA_OK
* - LZMA_OPTIONS_ERROR: Unsupported filter_id or flags * - LZMA_OPTIONS_ERROR: Unsupported filter_id or flags
* - LZMA_MEM_ERROR * - LZMA_MEM_ERROR
* - LZMA_PROG_ERROR * - LZMA_PROG_ERROR

View File

@ -1,6 +1,7 @@
/** /**
* \file lzma/hardware.h * \file lzma/hardware.h
* \brief Hardware information * \brief Hardware information
* \note Never include this file directly. Use <lzma.h> instead.
* *
* Since liblzma can consume a lot of system resources, it also provides * Since liblzma can consume a lot of system resources, it also provides
* ways to limit the resource usage. Applications linking against liblzma * ways to limit the resource usage. Applications linking against liblzma
@ -25,8 +26,6 @@
* *
* This file has been put into the public domain. * This file has been put into the public domain.
* You can do whatever you want with this file. * You can do whatever you want with this file.
*
* See ../lzma.h for information about liblzma as a whole.
*/ */
#ifndef LZMA_H_INTERNAL #ifndef LZMA_H_INTERNAL

View File

@ -1,6 +1,7 @@
/** /**
* \file lzma/index.h * \file lzma/index.h
* \brief Handling of .xz Index and related information * \brief Handling of .xz Index and related information
* \note Never include this file directly. Use <lzma.h> instead.
*/ */
/* /*
@ -8,8 +9,6 @@
* *
* This file has been put into the public domain. * This file has been put into the public domain.
* You can do whatever you want with this file. * You can do whatever you want with this file.
*
* See ../lzma.h for information about liblzma as a whole.
*/ */
#ifndef LZMA_H_INTERNAL #ifndef LZMA_H_INTERNAL
@ -50,8 +49,13 @@ typedef struct {
*/ */
const lzma_stream_flags *flags; const lzma_stream_flags *flags;
/** \private Reserved member. */
const void *reserved_ptr1; const void *reserved_ptr1;
/** \private Reserved member. */
const void *reserved_ptr2; const void *reserved_ptr2;
/** \private Reserved member. */
const void *reserved_ptr3; const void *reserved_ptr3;
/** /**
@ -107,9 +111,17 @@ typedef struct {
*/ */
lzma_vli padding; lzma_vli padding;
/** \private Reserved member. */
lzma_vli reserved_vli1; lzma_vli reserved_vli1;
/** \private Reserved member. */
lzma_vli reserved_vli2; lzma_vli reserved_vli2;
/** \private Reserved member. */
lzma_vli reserved_vli3; lzma_vli reserved_vli3;
/** \private Reserved member. */
lzma_vli reserved_vli4; lzma_vli reserved_vli4;
} stream; } stream;
@ -196,25 +208,46 @@ typedef struct {
*/ */
lzma_vli total_size; lzma_vli total_size;
/** \private Reserved member. */
lzma_vli reserved_vli1; lzma_vli reserved_vli1;
/** \private Reserved member. */
lzma_vli reserved_vli2; lzma_vli reserved_vli2;
/** \private Reserved member. */
lzma_vli reserved_vli3; lzma_vli reserved_vli3;
/** \private Reserved member. */
lzma_vli reserved_vli4; lzma_vli reserved_vli4;
/** \private Reserved member. */
const void *reserved_ptr1; const void *reserved_ptr1;
/** \private Reserved member. */
const void *reserved_ptr2; const void *reserved_ptr2;
/** \private Reserved member. */
const void *reserved_ptr3; const void *reserved_ptr3;
/** \private Reserved member. */
const void *reserved_ptr4; const void *reserved_ptr4;
} block; } block;
/* /**
* \private Internal struct.
*
* Internal data which is used to store the state of the iterator. * Internal data which is used to store the state of the iterator.
* The exact format may vary between liblzma versions, so don't * The exact format may vary between liblzma versions, so don't
* touch these in any way. * touch these in any way.
*/ */
union { union {
/** \private Internal member. */
const void *p; const void *p;
/** \private Internal member. */
size_t s; size_t s;
/** \private Internal member. */
lzma_vli v; lzma_vli v;
} internal[6]; } internal[6];
} lzma_index_iter; } lzma_index_iter;
@ -272,16 +305,21 @@ typedef enum {
* \brief Calculate memory usage of lzma_index * \brief Calculate memory usage of lzma_index
* *
* On disk, the size of the Index field depends on both the number of Records * On disk, the size of the Index field depends on both the number of Records
* stored and how big values the Records store (due to variable-length integer * stored and the size of the Records (due to variable-length integer
* encoding). When the Index is kept in lzma_index structure, the memory usage * encoding). When the Index is kept in lzma_index structure, the memory usage
* depends only on the number of Records/Blocks stored in the Index(es), and * depends only on the number of Records/Blocks stored in the Index(es), and
* in case of concatenated lzma_indexes, the number of Streams. The size in * in case of concatenated lzma_indexes, the number of Streams. The size in
* RAM is almost always significantly bigger than in the encoded form on disk. * RAM is almost always significantly bigger than in the encoded form on disk.
* *
* This function calculates an approximate amount of memory needed hold * This function calculates an approximate amount of memory needed to hold
* the given number of Streams and Blocks in lzma_index structure. This * the given number of Streams and Blocks in lzma_index structure. This
* value may vary between CPU architectures and also between liblzma versions * value may vary between CPU architectures and also between liblzma versions
* if the internal implementation is modified. * if the internal implementation is modified.
*
* \param streams Number of Streams
* \param blocks Number of Blocks
*
* \return Approximate memory in bytes needed in a lzma_index structure.
*/ */
extern LZMA_API(uint64_t) lzma_index_memusage( extern LZMA_API(uint64_t) lzma_index_memusage(
lzma_vli streams, lzma_vli blocks) lzma_nothrow; lzma_vli streams, lzma_vli blocks) lzma_nothrow;
@ -292,6 +330,10 @@ extern LZMA_API(uint64_t) lzma_index_memusage(
* *
* This is a shorthand for lzma_index_memusage(lzma_index_stream_count(i), * This is a shorthand for lzma_index_memusage(lzma_index_stream_count(i),
* lzma_index_block_count(i)). * lzma_index_block_count(i)).
*
* \param i Pointer to lzma_index structure
*
* \return Approximate memory in bytes used by the lzma_index structure.
*/ */
extern LZMA_API(uint64_t) lzma_index_memused(const lzma_index *i) extern LZMA_API(uint64_t) lzma_index_memused(const lzma_index *i)
lzma_nothrow; lzma_nothrow;
@ -300,6 +342,9 @@ extern LZMA_API(uint64_t) lzma_index_memused(const lzma_index *i)
/** /**
* \brief Allocate and initialize a new lzma_index structure * \brief Allocate and initialize a new lzma_index structure
* *
* \param allocator lzma_allocator for custom allocator functions.
* Set to NULL to use malloc() and free().
*
* \return On success, a pointer to an empty initialized lzma_index is * \return On success, a pointer to an empty initialized lzma_index is
* returned. If allocation fails, NULL is returned. * returned. If allocation fails, NULL is returned.
*/ */
@ -311,6 +356,10 @@ extern LZMA_API(lzma_index *) lzma_index_init(const lzma_allocator *allocator)
* \brief Deallocate lzma_index * \brief Deallocate lzma_index
* *
* If i is NULL, this does nothing. * If i is NULL, this does nothing.
*
* \param i Pointer to lzma_index structure to deallocate
* \param allocator lzma_allocator for custom allocator functions.
* Set to NULL to use malloc() and free().
*/ */
extern LZMA_API(void) lzma_index_end( extern LZMA_API(void) lzma_index_end(
lzma_index *i, const lzma_allocator *allocator) lzma_nothrow; lzma_index *i, const lzma_allocator *allocator) lzma_nothrow;
@ -320,8 +369,9 @@ extern LZMA_API(void) lzma_index_end(
* \brief Add a new Block to lzma_index * \brief Add a new Block to lzma_index
* *
* \param i Pointer to a lzma_index structure * \param i Pointer to a lzma_index structure
* \param allocator Pointer to lzma_allocator, or NULL to * \param allocator lzma_allocator for custom allocator
* use malloc() * functions. Set to NULL to use malloc()
* and free().
* \param unpadded_size Unpadded Size of a Block. This can be * \param unpadded_size Unpadded Size of a Block. This can be
* calculated with lzma_block_unpadded_size() * calculated with lzma_block_unpadded_size()
* after encoding or decoding the Block. * after encoding or decoding the Block.
@ -334,7 +384,8 @@ extern LZMA_API(void) lzma_index_end(
* lzma_index_append() it is possible to read the next Block with * lzma_index_append() it is possible to read the next Block with
* an existing iterator. * an existing iterator.
* *
* \return - LZMA_OK * \return Possible lzma_ret values:
* - LZMA_OK
* - LZMA_MEM_ERROR * - LZMA_MEM_ERROR
* - LZMA_DATA_ERROR: Compressed or uncompressed size of the * - LZMA_DATA_ERROR: Compressed or uncompressed size of the
* Stream or size of the Index field would grow too big. * Stream or size of the Index field would grow too big.
@ -354,11 +405,15 @@ extern LZMA_API(lzma_ret) lzma_index_append(
* lzma_index, because to decode Blocks, knowing the integrity check type * lzma_index, because to decode Blocks, knowing the integrity check type
* is needed. * is needed.
* *
* The given Stream Flags are copied into internal preallocated structure * \param i Pointer to lzma_index structure
* in the lzma_index, thus the caller doesn't need to keep the *stream_flags * \param stream_flags Pointer to lzma_stream_flags structure. This
* available after calling this function. * is copied into the internal preallocated
* structure, so the caller doesn't need to keep
* the flags' data available after calling this
* function.
* *
* \return - LZMA_OK * \return Possible lzma_ret values:
* - LZMA_OK
* - LZMA_OPTIONS_ERROR: Unsupported stream_flags->version. * - LZMA_OPTIONS_ERROR: Unsupported stream_flags->version.
* - LZMA_PROG_ERROR * - LZMA_PROG_ERROR
*/ */
@ -376,6 +431,10 @@ extern LZMA_API(lzma_ret) lzma_index_stream_flags(
* showing the Check types to the user. * showing the Check types to the user.
* *
* The bitmask is 1 << check_id, e.g. CRC32 is 1 << 1 and SHA-256 is 1 << 10. * The bitmask is 1 << check_id, e.g. CRC32 is 1 << 1 and SHA-256 is 1 << 10.
*
* \param i Pointer to lzma_index structure
*
* \return Bitmask indicating which Check types are used in the lzma_index
*/ */
extern LZMA_API(uint32_t) lzma_index_checks(const lzma_index *i) extern LZMA_API(uint32_t) lzma_index_checks(const lzma_index *i)
lzma_nothrow lzma_attr_pure; lzma_nothrow lzma_attr_pure;
@ -390,7 +449,8 @@ extern LZMA_API(uint32_t) lzma_index_checks(const lzma_index *i)
* *
* By default, the amount of Stream Padding is assumed to be zero bytes. * By default, the amount of Stream Padding is assumed to be zero bytes.
* *
* \return - LZMA_OK * \return Possible lzma_ret values:
* - LZMA_OK
* - LZMA_DATA_ERROR: The file size would grow too big. * - LZMA_DATA_ERROR: The file size would grow too big.
* - LZMA_PROG_ERROR * - LZMA_PROG_ERROR
*/ */
@ -401,6 +461,10 @@ extern LZMA_API(lzma_ret) lzma_index_stream_padding(
/** /**
* \brief Get the number of Streams * \brief Get the number of Streams
*
* \param i Pointer to lzma_index structure
*
* \return Number of Streams in the lzma_index
*/ */
extern LZMA_API(lzma_vli) lzma_index_stream_count(const lzma_index *i) extern LZMA_API(lzma_vli) lzma_index_stream_count(const lzma_index *i)
lzma_nothrow lzma_attr_pure; lzma_nothrow lzma_attr_pure;
@ -411,6 +475,10 @@ extern LZMA_API(lzma_vli) lzma_index_stream_count(const lzma_index *i)
* *
* This returns the total number of Blocks in lzma_index. To get number * This returns the total number of Blocks in lzma_index. To get number
* of Blocks in individual Streams, use lzma_index_iter. * of Blocks in individual Streams, use lzma_index_iter.
*
* \param i Pointer to lzma_index structure
*
* \return Number of blocks in the lzma_index
*/ */
extern LZMA_API(lzma_vli) lzma_index_block_count(const lzma_index *i) extern LZMA_API(lzma_vli) lzma_index_block_count(const lzma_index *i)
lzma_nothrow lzma_attr_pure; lzma_nothrow lzma_attr_pure;
@ -420,6 +488,10 @@ extern LZMA_API(lzma_vli) lzma_index_block_count(const lzma_index *i)
* \brief Get the size of the Index field as bytes * \brief Get the size of the Index field as bytes
* *
* This is needed to verify the Backward Size field in the Stream Footer. * This is needed to verify the Backward Size field in the Stream Footer.
*
* \param i Pointer to lzma_index structure
*
* \return Size in bytes of the Index
*/ */
extern LZMA_API(lzma_vli) lzma_index_size(const lzma_index *i) extern LZMA_API(lzma_vli) lzma_index_size(const lzma_index *i)
lzma_nothrow lzma_attr_pure; lzma_nothrow lzma_attr_pure;
@ -431,6 +503,11 @@ extern LZMA_API(lzma_vli) lzma_index_size(const lzma_index *i)
* If multiple lzma_indexes have been combined, this works as if the Blocks * If multiple lzma_indexes have been combined, this works as if the Blocks
* were in a single Stream. This is useful if you are going to combine * were in a single Stream. This is useful if you are going to combine
* Blocks from multiple Streams into a single new Stream. * Blocks from multiple Streams into a single new Stream.
*
* \param i Pointer to lzma_index structure
*
* \return Size in bytes of the Stream (if all Blocks are combined
* into one Stream).
*/ */
extern LZMA_API(lzma_vli) lzma_index_stream_size(const lzma_index *i) extern LZMA_API(lzma_vli) lzma_index_stream_size(const lzma_index *i)
lzma_nothrow lzma_attr_pure; lzma_nothrow lzma_attr_pure;
@ -441,6 +518,10 @@ extern LZMA_API(lzma_vli) lzma_index_stream_size(const lzma_index *i)
* *
* This doesn't include the Stream Header, Stream Footer, Stream Padding, * This doesn't include the Stream Header, Stream Footer, Stream Padding,
* or Index fields. * or Index fields.
*
* \param i Pointer to lzma_index structure
*
* \return Size in bytes of all Blocks in the Stream(s)
*/ */
extern LZMA_API(lzma_vli) lzma_index_total_size(const lzma_index *i) extern LZMA_API(lzma_vli) lzma_index_total_size(const lzma_index *i)
lzma_nothrow lzma_attr_pure; lzma_nothrow lzma_attr_pure;
@ -453,6 +534,10 @@ extern LZMA_API(lzma_vli) lzma_index_total_size(const lzma_index *i)
* no Stream Padding, this function is identical to lzma_index_stream_size(). * no Stream Padding, this function is identical to lzma_index_stream_size().
* If multiple lzma_indexes have been combined, this includes also the headers * If multiple lzma_indexes have been combined, this includes also the headers
* of each separate Stream and the possible Stream Padding fields. * of each separate Stream and the possible Stream Padding fields.
*
* \param i Pointer to lzma_index structure
*
* \return Total size of the .xz file in bytes
*/ */
extern LZMA_API(lzma_vli) lzma_index_file_size(const lzma_index *i) extern LZMA_API(lzma_vli) lzma_index_file_size(const lzma_index *i)
lzma_nothrow lzma_attr_pure; lzma_nothrow lzma_attr_pure;
@ -460,6 +545,10 @@ extern LZMA_API(lzma_vli) lzma_index_file_size(const lzma_index *i)
/** /**
* \brief Get the uncompressed size of the file * \brief Get the uncompressed size of the file
*
* \param i Pointer to lzma_index structure
*
* \return Size in bytes of the uncompressed data in the file
*/ */
extern LZMA_API(lzma_vli) lzma_index_uncompressed_size(const lzma_index *i) extern LZMA_API(lzma_vli) lzma_index_uncompressed_size(const lzma_index *i)
lzma_nothrow lzma_attr_pure; lzma_nothrow lzma_attr_pure;
@ -468,9 +557,6 @@ extern LZMA_API(lzma_vli) lzma_index_uncompressed_size(const lzma_index *i)
/** /**
* \brief Initialize an iterator * \brief Initialize an iterator
* *
* \param iter Pointer to a lzma_index_iter structure
* \param i lzma_index to which the iterator will be associated
*
* This function associates the iterator with the given lzma_index, and calls * This function associates the iterator with the given lzma_index, and calls
* lzma_index_iter_rewind() on the iterator. * lzma_index_iter_rewind() on the iterator.
* *
@ -483,6 +569,9 @@ extern LZMA_API(lzma_vli) lzma_index_uncompressed_size(const lzma_index *i)
* *
* It is safe to make copies of an initialized lzma_index_iter, for example, * It is safe to make copies of an initialized lzma_index_iter, for example,
* to easily restart reading at some particular position. * to easily restart reading at some particular position.
*
* \param iter Pointer to a lzma_index_iter structure
* \param i lzma_index to which the iterator will be associated
*/ */
extern LZMA_API(void) lzma_index_iter_init( extern LZMA_API(void) lzma_index_iter_init(
lzma_index_iter *iter, const lzma_index *i) lzma_nothrow; lzma_index_iter *iter, const lzma_index *i) lzma_nothrow;
@ -493,6 +582,8 @@ extern LZMA_API(void) lzma_index_iter_init(
* *
* Rewind the iterator so that next call to lzma_index_iter_next() will * Rewind the iterator so that next call to lzma_index_iter_next() will
* return the first Block or Stream. * return the first Block or Stream.
*
* \param iter Pointer to a lzma_index_iter structure
*/ */
extern LZMA_API(void) lzma_index_iter_rewind(lzma_index_iter *iter) extern LZMA_API(void) lzma_index_iter_rewind(lzma_index_iter *iter)
lzma_nothrow; lzma_nothrow;
@ -505,11 +596,11 @@ extern LZMA_API(void) lzma_index_iter_rewind(lzma_index_iter *iter)
* \param mode Specify what kind of information the caller wants * \param mode Specify what kind of information the caller wants
* to get. See lzma_index_iter_mode for details. * to get. See lzma_index_iter_mode for details.
* *
* \return If next Block or Stream matching the mode was found, *iter * \return lzma_bool:
* is updated and this function returns false. If no Block or * - true if no Block or Stream matching the mode is found.
* Stream matching the mode is found, *iter is not modified * *iter is not updated (failure).
* and this function returns true. If mode is set to an unknown * - false if the next Block or Stream matching the mode was
* value, *iter is not modified and this function returns true. * found. *iter is updated (success).
*/ */
extern LZMA_API(lzma_bool) lzma_index_iter_next( extern LZMA_API(lzma_bool) lzma_index_iter_next(
lzma_index_iter *iter, lzma_index_iter_mode mode) lzma_index_iter *iter, lzma_index_iter_mode mode)
@ -523,21 +614,26 @@ extern LZMA_API(lzma_bool) lzma_index_iter_next(
* the Index field(s) and use lzma_index_iter_locate() to do random-access * the Index field(s) and use lzma_index_iter_locate() to do random-access
* reading with granularity of Block size. * reading with granularity of Block size.
* *
* \param iter Iterator that was earlier initialized with
* lzma_index_iter_init().
* \param target Uncompressed target offset which the caller would
* like to locate from the Stream
*
* If the target is smaller than the uncompressed size of the Stream (can be * If the target is smaller than the uncompressed size of the Stream (can be
* checked with lzma_index_uncompressed_size()): * checked with lzma_index_uncompressed_size()):
* - Information about the Stream and Block containing the requested * - Information about the Stream and Block containing the requested
* uncompressed offset is stored into *iter. * uncompressed offset is stored into *iter.
* - Internal state of the iterator is adjusted so that * - Internal state of the iterator is adjusted so that
* lzma_index_iter_next() can be used to read subsequent Blocks or Streams. * lzma_index_iter_next() can be used to read subsequent Blocks or Streams.
* - This function returns false.
* *
* If target is greater than the uncompressed size of the Stream, *iter * If the target is greater than the uncompressed size of the Stream, *iter
* is not modified, and this function returns true. * is not modified.
*
* \param iter Iterator that was earlier initialized with
* lzma_index_iter_init().
* \param target Uncompressed target offset which the caller would
* like to locate from the Stream
*
* \return lzma_bool:
* - true if the target is greater than or equal to the
* uncompressed size of the Stream (failure)
* - false if the target is smaller than the uncompressed size
* of the Stream (success)
*/ */
extern LZMA_API(lzma_bool) lzma_index_iter_locate( extern LZMA_API(lzma_bool) lzma_index_iter_locate(
lzma_index_iter *iter, lzma_vli target) lzma_nothrow; lzma_index_iter *iter, lzma_vli target) lzma_nothrow;
@ -550,15 +646,16 @@ extern LZMA_API(lzma_bool) lzma_index_iter_locate(
* multi-Stream .xz file, or when combining multiple Streams into single * multi-Stream .xz file, or when combining multiple Streams into single
* Stream. * Stream.
* *
* \param dest lzma_index after which src is appended * \param[out] dest lzma_index after which src is appended
* \param src lzma_index to be appended after dest. If this * \param src lzma_index to be appended after dest. If this
* function succeeds, the memory allocated for src * function succeeds, the memory allocated for src
* is freed or moved to be part of dest, and all * is freed or moved to be part of dest, and all
* iterators pointing to src will become invalid. * iterators pointing to src will become invalid.
* \param allocator Custom memory allocator; can be NULL to use * \param allocator lzma_allocator for custom allocator functions.
* malloc() and free(). * Set to NULL to use malloc() and free().
* *
* \return - LZMA_OK: lzma_indexes were concatenated successfully. * \return Possible lzma_ret values:
* - LZMA_OK: lzma_indexes were concatenated successfully.
* src is now a dangling pointer. * src is now a dangling pointer.
* - LZMA_DATA_ERROR: *dest would grow too big. * - LZMA_DATA_ERROR: *dest would grow too big.
* - LZMA_MEM_ERROR * - LZMA_MEM_ERROR
@ -572,6 +669,10 @@ extern LZMA_API(lzma_ret) lzma_index_cat(lzma_index *dest, lzma_index *src,
/** /**
* \brief Duplicate lzma_index * \brief Duplicate lzma_index
* *
* \param i Pointer to lzma_index structure to be duplicated
* \param allocator lzma_allocator for custom allocator functions.
* Set to NULL to use malloc() and free().
*
* \return A copy of the lzma_index, or NULL if memory allocation failed. * \return A copy of the lzma_index, or NULL if memory allocation failed.
*/ */
extern LZMA_API(lzma_index *) lzma_index_dup( extern LZMA_API(lzma_index *) lzma_index_dup(
@ -588,7 +689,8 @@ extern LZMA_API(lzma_index *) lzma_index_dup(
* The valid `action' values for lzma_code() are LZMA_RUN and LZMA_FINISH. * The valid `action' values for lzma_code() are LZMA_RUN and LZMA_FINISH.
* It is enough to use only one of them (you can choose freely). * It is enough to use only one of them (you can choose freely).
* *
* \return - LZMA_OK: Initialization succeeded, continue with lzma_code(). * \return Possible lzma_ret values:
* - LZMA_OK: Initialization succeeded, continue with lzma_code().
* - LZMA_MEM_ERROR * - LZMA_MEM_ERROR
* - LZMA_PROG_ERROR * - LZMA_PROG_ERROR
*/ */
@ -601,7 +703,7 @@ extern LZMA_API(lzma_ret) lzma_index_encoder(
* \brief Initialize .xz Index decoder * \brief Initialize .xz Index decoder
* *
* \param strm Pointer to properly prepared lzma_stream * \param strm Pointer to properly prepared lzma_stream
* \param i The decoded Index will be made available via * \param[out] i The decoded Index will be made available via
* this pointer. Initially this function will * this pointer. Initially this function will
* set *i to NULL (the old value is ignored). If * set *i to NULL (the old value is ignored). If
* decoding succeeds (lzma_code() returns * decoding succeeds (lzma_code() returns
@ -617,11 +719,12 @@ extern LZMA_API(lzma_ret) lzma_index_encoder(
* There is no need to use LZMA_FINISH, but it's allowed because it may * There is no need to use LZMA_FINISH, but it's allowed because it may
* simplify certain types of applications. * simplify certain types of applications.
* *
* \return - LZMA_OK: Initialization succeeded, continue with lzma_code(). * \return Possible lzma_ret values:
* - LZMA_OK: Initialization succeeded, continue with lzma_code().
* - LZMA_MEM_ERROR * - LZMA_MEM_ERROR
* - LZMA_PROG_ERROR * - LZMA_PROG_ERROR
* *
* liblzma 5.2.3 and older list also LZMA_MEMLIMIT_ERROR here * \note liblzma 5.2.3 and older list also LZMA_MEMLIMIT_ERROR here
* but that error code has never been possible from this * but that error code has never been possible from this
* initialization function. * initialization function.
*/ */
@ -633,21 +736,23 @@ extern LZMA_API(lzma_ret) lzma_index_decoder(
/** /**
* \brief Single-call .xz Index encoder * \brief Single-call .xz Index encoder
* *
* \note This function doesn't take allocator argument since all
* the internal data is allocated on stack.
*
* \param i lzma_index to be encoded * \param i lzma_index to be encoded
* \param out Beginning of the output buffer * \param[out] out Beginning of the output buffer
* \param out_pos The next byte will be written to out[*out_pos]. * \param[out] out_pos The next byte will be written to out[*out_pos].
* *out_pos is updated only if encoding succeeds. * *out_pos is updated only if encoding succeeds.
* \param out_size Size of the out buffer; the first byte into * \param out_size Size of the out buffer; the first byte into
* which no data is written to is out[out_size]. * which no data is written to is out[out_size].
* *
* \return - LZMA_OK: Encoding was successful. * \return Possible lzma_ret values:
* - LZMA_OK: Encoding was successful.
* - LZMA_BUF_ERROR: Output buffer is too small. Use * - LZMA_BUF_ERROR: Output buffer is too small. Use
* lzma_index_size() to find out how much output * lzma_index_size() to find out how much output
* space is needed. * space is needed.
* - LZMA_PROG_ERROR * - LZMA_PROG_ERROR
* *
* \note This function doesn't take allocator argument since all
* the internal data is allocated on stack.
*/ */
extern LZMA_API(lzma_ret) lzma_index_buffer_encode(const lzma_index *i, extern LZMA_API(lzma_ret) lzma_index_buffer_encode(const lzma_index *i,
uint8_t *out, size_t *out_pos, size_t out_size) lzma_nothrow; uint8_t *out, size_t *out_pos, size_t out_size) lzma_nothrow;
@ -656,24 +761,26 @@ extern LZMA_API(lzma_ret) lzma_index_buffer_encode(const lzma_index *i,
/** /**
* \brief Single-call .xz Index decoder * \brief Single-call .xz Index decoder
* *
* \param i If decoding succeeds, *i will point to a new * \param[out] i If decoding succeeds, *i will point to a new
* lzma_index, which the application has to * lzma_index, which the application has to
* later free with lzma_index_end(). If an error * later free with lzma_index_end(). If an error
* occurs, *i will be NULL. The old value of *i * occurs, *i will be NULL. The old value of *i
* is always ignored and thus doesn't need to be * is always ignored and thus doesn't need to be
* initialized by the caller. * initialized by the caller.
* \param memlimit Pointer to how much memory the resulting * \param[out] memlimit Pointer to how much memory the resulting
* lzma_index is allowed to require. The value * lzma_index is allowed to require. The value
* pointed by this pointer is modified if and only * pointed by this pointer is modified if and only
* if LZMA_MEMLIMIT_ERROR is returned. * if LZMA_MEMLIMIT_ERROR is returned.
* \param allocator Pointer to lzma_allocator, or NULL to use malloc() * \param allocator lzma_allocator for custom allocator functions.
* Set to NULL to use malloc() and free().
* \param in Beginning of the input buffer * \param in Beginning of the input buffer
* \param in_pos The next byte will be read from in[*in_pos]. * \param in_pos The next byte will be read from in[*in_pos].
* *in_pos is updated only if decoding succeeds. * *in_pos is updated only if decoding succeeds.
* \param in_size Size of the input buffer; the first byte that * \param in_size Size of the input buffer; the first byte that
* won't be read is in[in_size]. * won't be read is in[in_size].
* *
* \return - LZMA_OK: Decoding was successful. * \return Possible lzma_ret values:
* - LZMA_OK: Decoding was successful.
* - LZMA_MEM_ERROR * - LZMA_MEM_ERROR
* - LZMA_MEMLIMIT_ERROR: Memory usage limit was reached. * - LZMA_MEMLIMIT_ERROR: Memory usage limit was reached.
* The minimum required memlimit value was stored to *memlimit. * The minimum required memlimit value was stored to *memlimit.
@ -689,15 +796,6 @@ extern LZMA_API(lzma_ret) lzma_index_buffer_decode(lzma_index **i,
/** /**
* \brief Initialize a .xz file information decoder * \brief Initialize a .xz file information decoder
* *
* \param strm Pointer to a properly prepared lzma_stream
* \param dest_index Pointer to a pointer where the decoder will put
* the decoded lzma_index. The old value
* of *dest_index is ignored (not freed).
* \param memlimit How much memory the resulting lzma_index is
* allowed to require. Use UINT64_MAX to
* effectively disable the limiter.
* \param file_size Size of the input .xz file
*
* This decoder decodes the Stream Header, Stream Footer, Index, and * This decoder decodes the Stream Header, Stream Footer, Index, and
* Stream Padding field(s) from the input .xz file and stores the resulting * Stream Padding field(s) from the input .xz file and stores the resulting
* combined index in *dest_index. This information can be used to get the * combined index in *dest_index. This information can be used to get the
@ -742,7 +840,17 @@ extern LZMA_API(lzma_ret) lzma_index_buffer_decode(lzma_index **i,
* - LZMA_MEMLIMIT_ERROR * - LZMA_MEMLIMIT_ERROR
* - LZMA_PROG_ERROR * - LZMA_PROG_ERROR
* *
* \return - LZMA_OK * \param strm Pointer to a properly prepared lzma_stream
* \param[out] dest_index Pointer to a pointer where the decoder will put
* the decoded lzma_index. The old value
* of *dest_index is ignored (not freed).
* \param memlimit How much memory the resulting lzma_index is
* allowed to require. Use UINT64_MAX to
* effectively disable the limiter.
* \param file_size Size of the input .xz file
*
* \return Possible lzma_ret values:
* - LZMA_OK
* - LZMA_MEM_ERROR * - LZMA_MEM_ERROR
* - LZMA_PROG_ERROR * - LZMA_PROG_ERROR
*/ */

View File

@ -1,6 +1,7 @@
/** /**
* \file lzma/index_hash.h * \file lzma/index_hash.h
* \brief Validate Index by using a hash function * \brief Validate Index by using a hash function
* \note Never include this file directly. Use <lzma.h> instead.
* *
* Hashing makes it possible to use constant amount of memory to validate * Hashing makes it possible to use constant amount of memory to validate
* Index of arbitrary size. * Index of arbitrary size.
@ -11,8 +12,6 @@
* *
* This file has been put into the public domain. * This file has been put into the public domain.
* You can do whatever you want with this file. * You can do whatever you want with this file.
*
* See ../lzma.h for information about liblzma as a whole.
*/ */
#ifndef LZMA_H_INTERNAL #ifndef LZMA_H_INTERNAL
@ -28,13 +27,21 @@ typedef struct lzma_index_hash_s lzma_index_hash;
/** /**
* \brief Allocate and initialize a new lzma_index_hash structure * \brief Allocate and initialize a new lzma_index_hash structure
* *
* If index_hash is NULL, a new lzma_index_hash structure is allocated, * If index_hash is NULL, this function allocates and initializes a new
* initialized, and a pointer to it returned. If allocation fails, NULL * lzma_index_hash structure and returns a pointer to it. If allocation
* is returned. * fails, NULL is returned.
* *
* If index_hash is non-NULL, it is reinitialized and the same pointer * If index_hash is non-NULL, this function reinitializes the lzma_index_hash
* returned. In this case, return value cannot be NULL or a different * structure and returns the same pointer. In this case, return value cannot
* pointer than the index_hash that was given as an argument. * be NULL or a different pointer than the index_hash that was given as
* an argument.
*
* \param index_hash Pointer to a lzma_index_hash structure or NULL.
* \param allocator lzma_allocator for custom allocator functions.
* Set to NULL to use malloc() and free().
*
* \return Initialized lzma_index_hash structure on success or
* NULL on failure.
*/ */
extern LZMA_API(lzma_index_hash *) lzma_index_hash_init( extern LZMA_API(lzma_index_hash *) lzma_index_hash_init(
lzma_index_hash *index_hash, const lzma_allocator *allocator) lzma_index_hash *index_hash, const lzma_allocator *allocator)
@ -43,6 +50,10 @@ extern LZMA_API(lzma_index_hash *) lzma_index_hash_init(
/** /**
* \brief Deallocate lzma_index_hash structure * \brief Deallocate lzma_index_hash structure
*
* \param index_hash Pointer to a lzma_index_hash structure to free.
* \param allocator lzma_allocator for custom allocator functions.
* Set to NULL to use malloc() and free().
*/ */
extern LZMA_API(void) lzma_index_hash_end( extern LZMA_API(void) lzma_index_hash_end(
lzma_index_hash *index_hash, const lzma_allocator *allocator) lzma_index_hash *index_hash, const lzma_allocator *allocator)
@ -56,7 +67,8 @@ extern LZMA_API(void) lzma_index_hash_end(
* \param unpadded_size Unpadded Size of a Block * \param unpadded_size Unpadded Size of a Block
* \param uncompressed_size Uncompressed Size of a Block * \param uncompressed_size Uncompressed Size of a Block
* *
* \return - LZMA_OK * \return Possible lzma_ret values:
* - LZMA_OK
* - LZMA_DATA_ERROR: Compressed or uncompressed size of the * - LZMA_DATA_ERROR: Compressed or uncompressed size of the
* Stream or size of the Index field would grow too big. * Stream or size of the Index field would grow too big.
* - LZMA_PROG_ERROR: Invalid arguments or this function is being * - LZMA_PROG_ERROR: Invalid arguments or this function is being
@ -81,10 +93,11 @@ extern LZMA_API(lzma_ret) lzma_index_hash_append(lzma_index_hash *index_hash,
* *
* \param index_hash Pointer to a lzma_index_hash structure * \param index_hash Pointer to a lzma_index_hash structure
* \param in Pointer to the beginning of the input buffer * \param in Pointer to the beginning of the input buffer
* \param in_pos in[*in_pos] is the next byte to process * \param[out] in_pos in[*in_pos] is the next byte to process
* \param in_size in[in_size] is the first byte not to process * \param in_size in[in_size] is the first byte not to process
* *
* \return - LZMA_OK: So far good, but more input is needed. * \return Possible lzma_ret values:
* - LZMA_OK: So far good, but more input is needed.
* - LZMA_STREAM_END: Index decoded successfully and it matches * - LZMA_STREAM_END: Index decoded successfully and it matches
* the Records given with lzma_index_hash_append(). * the Records given with lzma_index_hash_append().
* - LZMA_DATA_ERROR: Index is corrupt or doesn't match the * - LZMA_DATA_ERROR: Index is corrupt or doesn't match the
@ -101,6 +114,10 @@ extern LZMA_API(lzma_ret) lzma_index_hash_decode(lzma_index_hash *index_hash,
* \brief Get the size of the Index field as bytes * \brief Get the size of the Index field as bytes
* *
* This is needed to verify the Backward Size field in the Stream Footer. * This is needed to verify the Backward Size field in the Stream Footer.
*
* \param index_hash Pointer to a lzma_index_hash structure
*
* \return Size of the Index field in bytes.
*/ */
extern LZMA_API(lzma_vli) lzma_index_hash_size( extern LZMA_API(lzma_vli) lzma_index_hash_size(
const lzma_index_hash *index_hash) const lzma_index_hash *index_hash)

View File

@ -1,6 +1,7 @@
/** /**
* \file lzma/lzma12.h * \file lzma/lzma12.h
* \brief LZMA1 and LZMA2 filters * \brief LZMA1 and LZMA2 filters
* \note Never include this file directly. Use <lzma.h> instead.
*/ */
/* /*
@ -8,8 +9,6 @@
* *
* This file has been put into the public domain. * This file has been put into the public domain.
* You can do whatever you want with this file. * You can do whatever you want with this file.
*
* See ../lzma.h for information about liblzma as a whole.
*/ */
#ifndef LZMA_H_INTERNAL #ifndef LZMA_H_INTERNAL
@ -137,16 +136,20 @@ typedef enum {
/** /**
* \brief Test if given match finder is supported * \brief Test if given match finder is supported
* *
* Return true if the given match finder is supported by this liblzma build. * It is safe to call this with a value that isn't listed in
* Otherwise false is returned. It is safe to call this with a value that * lzma_match_finder enumeration; the return value will be false.
* isn't listed in lzma_match_finder enumeration; the return value will be
* false.
* *
* There is no way to list which match finders are available in this * There is no way to list which match finders are available in this
* particular liblzma version and build. It would be useless, because * particular liblzma version and build. It would be useless, because
* a new match finder, which the application developer wasn't aware, * a new match finder, which the application developer wasn't aware,
* could require giving additional options to the encoder that the older * could require giving additional options to the encoder that the older
* match finders don't need. * match finders don't need.
*
* \param match_finder Match finder ID
*
* \return lzma_bool:
* - true if the match finder is supported by this liblzma build.
* - false otherwise.
*/ */
extern LZMA_API(lzma_bool) lzma_mf_is_supported(lzma_match_finder match_finder) extern LZMA_API(lzma_bool) lzma_mf_is_supported(lzma_match_finder match_finder)
lzma_nothrow lzma_attr_const; lzma_nothrow lzma_attr_const;
@ -181,14 +184,20 @@ typedef enum {
/** /**
* \brief Test if given compression mode is supported * \brief Test if given compression mode is supported
* *
* Return true if the given compression mode is supported by this liblzma * It is safe to call this with a value that isn't listed in lzma_mode
* build. Otherwise false is returned. It is safe to call this with a value * enumeration; the return value will be false.
* that isn't listed in lzma_mode enumeration; the return value will be false.
* *
* There is no way to list which modes are available in this particular * There is no way to list which modes are available in this particular
* liblzma version and build. It would be useless, because a new compression * liblzma version and build. It would be useless, because a new compression
* mode, which the application developer wasn't aware, could require giving * mode, which the application developer wasn't aware, could require giving
* additional options to the encoder that the older modes don't need. * additional options to the encoder that the older modes don't need.
*
* \param mode Mode ID.
*
* \return lzma_bool:
* - true if the compression mode is supported by this liblzma
* build.
* - false otherwise.
*/ */
extern LZMA_API(lzma_bool) lzma_mode_is_supported(lzma_mode mode) extern LZMA_API(lzma_bool) lzma_mode_is_supported(lzma_mode mode)
lzma_nothrow lzma_attr_const; lzma_nothrow lzma_attr_const;
@ -480,16 +489,38 @@ typedef struct {
* with the currently supported options, so it is safe to leave these * with the currently supported options, so it is safe to leave these
* uninitialized. * uninitialized.
*/ */
/** \private Reserved member. */
uint32_t reserved_int4; uint32_t reserved_int4;
/** \private Reserved member. */
uint32_t reserved_int5; uint32_t reserved_int5;
/** \private Reserved member. */
uint32_t reserved_int6; uint32_t reserved_int6;
/** \private Reserved member. */
uint32_t reserved_int7; uint32_t reserved_int7;
/** \private Reserved member. */
uint32_t reserved_int8; uint32_t reserved_int8;
/** \private Reserved member. */
lzma_reserved_enum reserved_enum1; lzma_reserved_enum reserved_enum1;
/** \private Reserved member. */
lzma_reserved_enum reserved_enum2; lzma_reserved_enum reserved_enum2;
/** \private Reserved member. */
lzma_reserved_enum reserved_enum3; lzma_reserved_enum reserved_enum3;
/** \private Reserved member. */
lzma_reserved_enum reserved_enum4; lzma_reserved_enum reserved_enum4;
/** \private Reserved member. */
void *reserved_ptr1; void *reserved_ptr1;
/** \private Reserved member. */
void *reserved_ptr2; void *reserved_ptr2;
} lzma_options_lzma; } lzma_options_lzma;
@ -517,13 +548,22 @@ do { \
* The flags are defined in container.h, because the flags are used also * The flags are defined in container.h, because the flags are used also
* with lzma_easy_encoder(). * with lzma_easy_encoder().
* *
* The preset values are subject to changes between liblzma versions. * The preset levels are subject to changes between liblzma versions.
* *
* This function is available only if LZMA1 or LZMA2 encoder has been enabled * This function is available only if LZMA1 or LZMA2 encoder has been enabled
* when building liblzma. * when building liblzma.
* *
* \return On success, false is returned. If the preset is not * If features (like certain match finders) have been disabled at build time,
* supported, true is returned. * then the function may return success (false) even though the resulting
* LZMA1/LZMA2 options may not be usable for encoder initialization
* (LZMA_OPTIONS_ERROR).
*
* \param[out] options Pointer to LZMA1 or LZMA2 options to be filled
* \param preset Preset level bitwse-ORed with preset flags
*
* \return lzma_bool:
* - true if the preset is not supported (failure).
* - false otherwise (success).
*/ */
extern LZMA_API(lzma_bool) lzma_lzma_preset( extern LZMA_API(lzma_bool) lzma_lzma_preset(
lzma_options_lzma *options, uint32_t preset) lzma_nothrow; lzma_options_lzma *options, uint32_t preset) lzma_nothrow;

View File

@ -1,6 +1,7 @@
/** /**
* \file lzma/stream_flags.h * \file lzma/stream_flags.h
* \brief .xz Stream Header and Stream Footer encoder and decoder * \brief .xz Stream Header and Stream Footer encoder and decoder
* \note Never include this file directly. Use <lzma.h> instead.
*/ */
/* /*
@ -8,8 +9,6 @@
* *
* This file has been put into the public domain. * This file has been put into the public domain.
* You can do whatever you want with this file. * You can do whatever you want with this file.
*
* See ../lzma.h for information about liblzma as a whole.
*/ */
#ifndef LZMA_H_INTERNAL #ifndef LZMA_H_INTERNAL
@ -36,7 +35,7 @@ typedef struct {
* *
* To prevent API and ABI breakages if new features are needed in * To prevent API and ABI breakages if new features are needed in
* Stream Header or Stream Footer, a version number is used to * Stream Header or Stream Footer, a version number is used to
* indicate which fields in this structure are in use. For now, * indicate which members in this structure are in use. For now,
* version must always be zero. With non-zero version, the * version must always be zero. With non-zero version, the
* lzma_stream_header_encode() and lzma_stream_footer_encode() * lzma_stream_header_encode() and lzma_stream_footer_encode()
* will return LZMA_OPTIONS_ERROR. * will return LZMA_OPTIONS_ERROR.
@ -67,7 +66,15 @@ typedef struct {
* Footer have been decoded. * Footer have been decoded.
*/ */
lzma_vli backward_size; lzma_vli backward_size;
/**
* \brief Minimum value for lzma_stream_flags.backward_size
*/
# define LZMA_BACKWARD_SIZE_MIN 4 # define LZMA_BACKWARD_SIZE_MIN 4
/**
* \brief Maximum value for lzma_stream_flags.backward_size
*/
# define LZMA_BACKWARD_SIZE_MAX (LZMA_VLI_C(1) << 34) # define LZMA_BACKWARD_SIZE_MAX (LZMA_VLI_C(1) << 34)
/** /**
@ -87,19 +94,47 @@ typedef struct {
* is just two bytes plus Backward Size of four bytes. But it's * is just two bytes plus Backward Size of four bytes. But it's
* nice to have the proper types when they are needed.) * nice to have the proper types when they are needed.)
*/ */
/** \private Reserved member. */
lzma_reserved_enum reserved_enum1; lzma_reserved_enum reserved_enum1;
/** \private Reserved member. */
lzma_reserved_enum reserved_enum2; lzma_reserved_enum reserved_enum2;
/** \private Reserved member. */
lzma_reserved_enum reserved_enum3; lzma_reserved_enum reserved_enum3;
/** \private Reserved member. */
lzma_reserved_enum reserved_enum4; lzma_reserved_enum reserved_enum4;
/** \private Reserved member. */
lzma_bool reserved_bool1; lzma_bool reserved_bool1;
/** \private Reserved member. */
lzma_bool reserved_bool2; lzma_bool reserved_bool2;
/** \private Reserved member. */
lzma_bool reserved_bool3; lzma_bool reserved_bool3;
/** \private Reserved member. */
lzma_bool reserved_bool4; lzma_bool reserved_bool4;
/** \private Reserved member. */
lzma_bool reserved_bool5; lzma_bool reserved_bool5;
/** \private Reserved member. */
lzma_bool reserved_bool6; lzma_bool reserved_bool6;
/** \private Reserved member. */
lzma_bool reserved_bool7; lzma_bool reserved_bool7;
/** \private Reserved member. */
lzma_bool reserved_bool8; lzma_bool reserved_bool8;
/** \private Reserved member. */
uint32_t reserved_int1; uint32_t reserved_int1;
/** \private Reserved member. */
uint32_t reserved_int2; uint32_t reserved_int2;
} lzma_stream_flags; } lzma_stream_flags;
@ -111,10 +146,11 @@ typedef struct {
* \param options Stream Header options to be encoded. * \param options Stream Header options to be encoded.
* options->backward_size is ignored and doesn't * options->backward_size is ignored and doesn't
* need to be initialized. * need to be initialized.
* \param out Beginning of the output buffer of * \param[out] out Beginning of the output buffer of
* LZMA_STREAM_HEADER_SIZE bytes. * LZMA_STREAM_HEADER_SIZE bytes.
* *
* \return - LZMA_OK: Encoding was successful. * \return Possible lzma_ret values:
* - LZMA_OK: Encoding was successful.
* - LZMA_OPTIONS_ERROR: options->version is not supported by * - LZMA_OPTIONS_ERROR: options->version is not supported by
* this liblzma version. * this liblzma version.
* - LZMA_PROG_ERROR: Invalid options. * - LZMA_PROG_ERROR: Invalid options.
@ -128,10 +164,11 @@ extern LZMA_API(lzma_ret) lzma_stream_header_encode(
* \brief Encode Stream Footer * \brief Encode Stream Footer
* *
* \param options Stream Footer options to be encoded. * \param options Stream Footer options to be encoded.
* \param out Beginning of the output buffer of * \param[out] out Beginning of the output buffer of
* LZMA_STREAM_HEADER_SIZE bytes. * LZMA_STREAM_HEADER_SIZE bytes.
* *
* \return - LZMA_OK: Encoding was successful. * \return Possible lzma_ret values:
* - LZMA_OK: Encoding was successful.
* - LZMA_OPTIONS_ERROR: options->version is not supported by * - LZMA_OPTIONS_ERROR: options->version is not supported by
* this liblzma version. * this liblzma version.
* - LZMA_PROG_ERROR: Invalid options. * - LZMA_PROG_ERROR: Invalid options.
@ -144,32 +181,33 @@ extern LZMA_API(lzma_ret) lzma_stream_footer_encode(
/** /**
* \brief Decode Stream Header * \brief Decode Stream Header
* *
* \param options Target for the decoded Stream Header options.
* \param in Beginning of the input buffer of
* LZMA_STREAM_HEADER_SIZE bytes.
*
* options->backward_size is always set to LZMA_VLI_UNKNOWN. This is to * options->backward_size is always set to LZMA_VLI_UNKNOWN. This is to
* help comparing Stream Flags from Stream Header and Stream Footer with * help comparing Stream Flags from Stream Header and Stream Footer with
* lzma_stream_flags_compare(). * lzma_stream_flags_compare().
* *
* \return - LZMA_OK: Decoding was successful. * \note When decoding .xz files that contain multiple Streams, it may
* make sense to print "file format not recognized" only if
* decoding of the Stream Header of the \a first Stream gives
* LZMA_FORMAT_ERROR. If non-first Stream Header gives
* LZMA_FORMAT_ERROR, the message used for LZMA_DATA_ERROR is
* probably more appropriate.
* For example, the Stream decoder in liblzma uses
* LZMA_DATA_ERROR if LZMA_FORMAT_ERROR is returned by
* lzma_stream_header_decode() when decoding non-first Stream.
*
* \param[out] options Target for the decoded Stream Header options.
* \param in Beginning of the input buffer of
* LZMA_STREAM_HEADER_SIZE bytes.
*
*
* \return Possible lzma_ret values:
* - LZMA_OK: Decoding was successful.
* - LZMA_FORMAT_ERROR: Magic bytes don't match, thus the given * - LZMA_FORMAT_ERROR: Magic bytes don't match, thus the given
* buffer cannot be Stream Header. * buffer cannot be Stream Header.
* - LZMA_DATA_ERROR: CRC32 doesn't match, thus the header * - LZMA_DATA_ERROR: CRC32 doesn't match, thus the header
* is corrupt. * is corrupt.
* - LZMA_OPTIONS_ERROR: Unsupported options are present * - LZMA_OPTIONS_ERROR: Unsupported options are present
* in the header. * in the header.
*
* \note When decoding .xz files that contain multiple Streams, it may
* make sense to print "file format not recognized" only if
* decoding of the Stream Header of the _first_ Stream gives
* LZMA_FORMAT_ERROR. If non-first Stream Header gives
* LZMA_FORMAT_ERROR, the message used for LZMA_DATA_ERROR is
* probably more appropriate.
*
* For example, Stream decoder in liblzma uses LZMA_DATA_ERROR if
* LZMA_FORMAT_ERROR is returned by lzma_stream_header_decode()
* when decoding non-first Stream.
*/ */
extern LZMA_API(lzma_ret) lzma_stream_header_decode( extern LZMA_API(lzma_ret) lzma_stream_header_decode(
lzma_stream_flags *options, const uint8_t *in) lzma_stream_flags *options, const uint8_t *in)
@ -179,24 +217,25 @@ extern LZMA_API(lzma_ret) lzma_stream_header_decode(
/** /**
* \brief Decode Stream Footer * \brief Decode Stream Footer
* *
* \param options Target for the decoded Stream Header options. * \note If Stream Header was already decoded successfully, but
* decoding Stream Footer returns LZMA_FORMAT_ERROR, the
* application should probably report some other error message
* than "file format not recognized". The file likely
* is corrupt (possibly truncated). The Stream decoder in liblzma
* uses LZMA_DATA_ERROR in this situation.
*
* \param[out] options Target for the decoded Stream Footer options.
* \param in Beginning of the input buffer of * \param in Beginning of the input buffer of
* LZMA_STREAM_HEADER_SIZE bytes. * LZMA_STREAM_HEADER_SIZE bytes.
* *
* \return - LZMA_OK: Decoding was successful. * \return Possible lzma_ret values:
* - LZMA_OK: Decoding was successful.
* - LZMA_FORMAT_ERROR: Magic bytes don't match, thus the given * - LZMA_FORMAT_ERROR: Magic bytes don't match, thus the given
* buffer cannot be Stream Footer. * buffer cannot be Stream Footer.
* - LZMA_DATA_ERROR: CRC32 doesn't match, thus the Stream Footer * - LZMA_DATA_ERROR: CRC32 doesn't match, thus the Stream Footer
* is corrupt. * is corrupt.
* - LZMA_OPTIONS_ERROR: Unsupported options are present * - LZMA_OPTIONS_ERROR: Unsupported options are present
* in Stream Footer. * in Stream Footer.
*
* \note If Stream Header was already decoded successfully, but
* decoding Stream Footer returns LZMA_FORMAT_ERROR, the
* application should probably report some other error message
* than "file format not recognized", since the file more likely
* is corrupt (possibly truncated). Stream decoder in liblzma
* uses LZMA_DATA_ERROR in this situation.
*/ */
extern LZMA_API(lzma_ret) lzma_stream_footer_decode( extern LZMA_API(lzma_ret) lzma_stream_footer_decode(
lzma_stream_flags *options, const uint8_t *in) lzma_stream_flags *options, const uint8_t *in)
@ -209,7 +248,11 @@ extern LZMA_API(lzma_ret) lzma_stream_footer_decode(
* backward_size values are compared only if both are not * backward_size values are compared only if both are not
* LZMA_VLI_UNKNOWN. * LZMA_VLI_UNKNOWN.
* *
* \return - LZMA_OK: Both are equal. If either had backward_size set * \param a Pointer to lzma_stream_flags structure
* \param b Pointer to lzma_stream_flags structure
*
* \return Possible lzma_ret values:
* - LZMA_OK: Both are equal. If either had backward_size set
* to LZMA_VLI_UNKNOWN, backward_size values were not * to LZMA_VLI_UNKNOWN, backward_size values were not
* compared or validated. * compared or validated.
* - LZMA_DATA_ERROR: The structures differ. * - LZMA_DATA_ERROR: The structures differ.

View File

@ -1,6 +1,7 @@
/** /**
* \file lzma/version.h * \file lzma/version.h
* \brief Version number * \brief Version number
* \note Never include this file directly. Use <lzma.h> instead.
*/ */
/* /*
@ -8,8 +9,6 @@
* *
* This file has been put into the public domain. * This file has been put into the public domain.
* You can do whatever you want with this file. * You can do whatever you want with this file.
*
* See ../lzma.h for information about liblzma as a whole.
*/ */
#ifndef LZMA_H_INTERNAL #ifndef LZMA_H_INTERNAL
@ -17,14 +16,26 @@
#endif #endif
/* /** \brief Major version number of the liblzma release. */
* Version number split into components
*/
#define LZMA_VERSION_MAJOR 5 #define LZMA_VERSION_MAJOR 5
/** \brief Minor version number of the liblzma release. */
#define LZMA_VERSION_MINOR 4 #define LZMA_VERSION_MINOR 4
#define LZMA_VERSION_PATCH 1
/** \brief Patch version number of the liblzma release. */
#define LZMA_VERSION_PATCH 2
/**
* \brief Version stability marker
*
* This will always be one of three values:
* - LZMA_VERSION_STABILITY_ALPHA
* - LZMA_VERSION_STABILITY_BETA
* - LZMA_VERSION_STABILITY_STABLE
*/
#define LZMA_VERSION_STABILITY LZMA_VERSION_STABILITY_STABLE #define LZMA_VERSION_STABILITY LZMA_VERSION_STABILITY_STABLE
/** \brief Commit version number of the liblzma release */
#ifndef LZMA_VERSION_COMMIT #ifndef LZMA_VERSION_COMMIT
# define LZMA_VERSION_COMMIT "" # define LZMA_VERSION_COMMIT ""
#endif #endif
@ -101,9 +112,10 @@
/** /**
* \brief Run-time version number as an integer * \brief Run-time version number as an integer
* *
* Return the value of LZMA_VERSION macro at the compile time of liblzma. * This allows an application to compare if it was built against the same,
* This allows the application to compare if it was built against the same,
* older, or newer version of liblzma that is currently running. * older, or newer version of liblzma that is currently running.
*
* \return The value of LZMA_VERSION macro at the compile time of liblzma
*/ */
extern LZMA_API(uint32_t) lzma_version_number(void) extern LZMA_API(uint32_t) lzma_version_number(void)
lzma_nothrow lzma_attr_const; lzma_nothrow lzma_attr_const;
@ -112,8 +124,10 @@ extern LZMA_API(uint32_t) lzma_version_number(void)
/** /**
* \brief Run-time version as a string * \brief Run-time version as a string
* *
* This function may be useful if you want to display which version of * This function may be useful to display which version of liblzma an
* liblzma your application is currently using. * application is currently using.
*
* \return Run-time version of liblzma
*/ */
extern LZMA_API(const char *) lzma_version_string(void) extern LZMA_API(const char *) lzma_version_string(void)
lzma_nothrow lzma_attr_const; lzma_nothrow lzma_attr_const;

View File

@ -1,6 +1,7 @@
/** /**
* \file lzma/vli.h * \file lzma/vli.h
* \brief Variable-length integer handling * \brief Variable-length integer handling
* \note Never include this file directly. Use <lzma.h> instead.
* *
* In the .xz format, most integers are encoded in a variable-length * In the .xz format, most integers are encoded in a variable-length
* representation, which is sometimes called little endian base-128 encoding. * representation, which is sometimes called little endian base-128 encoding.
@ -19,8 +20,6 @@
* *
* This file has been put into the public domain. * This file has been put into the public domain.
* You can do whatever you want with this file. * You can do whatever you want with this file.
*
* See ../lzma.h for information about liblzma as a whole.
*/ */
#ifndef LZMA_H_INTERNAL #ifndef LZMA_H_INTERNAL
@ -70,7 +69,8 @@ typedef uint64_t lzma_vli;
* for example in the uncompressed_size and compressed_size variables. * for example in the uncompressed_size and compressed_size variables.
* *
* \return True if the integer is representable as VLI or if it * \return True if the integer is representable as VLI or if it
* indicates unknown value. * indicates unknown value. False if the integer cannot be
* represented as VLI.
*/ */
#define lzma_vli_is_valid(vli) \ #define lzma_vli_is_valid(vli) \
((vli) <= LZMA_VLI_MAX || (vli) == LZMA_VLI_UNKNOWN) ((vli) <= LZMA_VLI_MAX || (vli) == LZMA_VLI_UNKNOWN)
@ -86,12 +86,12 @@ typedef uint64_t lzma_vli;
* integer has been encoded. * integer has been encoded.
* *
* \param vli Integer to be encoded * \param vli Integer to be encoded
* \param vli_pos How many VLI-encoded bytes have already been written * \param[out] vli_pos How many VLI-encoded bytes have already been written
* out. When starting to encode a new integer in * out. When starting to encode a new integer in
* multi-call mode, *vli_pos must be set to zero. * multi-call mode, *vli_pos must be set to zero.
* To use single-call encoding, set vli_pos to NULL. * To use single-call encoding, set vli_pos to NULL.
* \param out Beginning of the output buffer * \param[out] out Beginning of the output buffer
* \param out_pos The next byte will be written to out[*out_pos]. * \param[out] out_pos The next byte will be written to out[*out_pos].
* \param out_size Size of the out buffer; the first byte into * \param out_size Size of the out buffer; the first byte into
* which no data is written to is out[out_size]. * which no data is written to is out[out_size].
* *
@ -121,15 +121,15 @@ extern LZMA_API(lzma_ret) lzma_vli_encode(lzma_vli vli, size_t *vli_pos,
* *
* Like lzma_vli_encode(), this function has single-call and multi-call modes. * Like lzma_vli_encode(), this function has single-call and multi-call modes.
* *
* \param vli Pointer to decoded integer. The decoder will * \param[out] vli Pointer to decoded integer. The decoder will
* initialize it to zero when *vli_pos == 0, so * initialize it to zero when *vli_pos == 0, so
* application isn't required to initialize *vli. * application isn't required to initialize *vli.
* \param vli_pos How many bytes have already been decoded. When * \param[out] vli_pos How many bytes have already been decoded. When
* starting to decode a new integer in multi-call * starting to decode a new integer in multi-call
* mode, *vli_pos must be initialized to zero. To * mode, *vli_pos must be initialized to zero. To
* use single-call decoding, set vli_pos to NULL. * use single-call decoding, set vli_pos to NULL.
* \param in Beginning of the input buffer * \param in Beginning of the input buffer
* \param in_pos The next byte will be read from in[*in_pos]. * \param[out] in_pos The next byte will be read from in[*in_pos].
* \param in_size Size of the input buffer; the first byte that * \param in_size Size of the input buffer; the first byte that
* won't be read is in[in_size]. * won't be read is in[in_size].
* *

View File

@ -108,10 +108,6 @@ extern const uint64_t lzma_crc64_table[4][256];
/// \brief Initialize *check depending on type /// \brief Initialize *check depending on type
///
/// \return LZMA_OK on success. LZMA_UNSUPPORTED_CHECK if the type is not
/// supported by the current version or build of liblzma.
/// LZMA_PROG_ERROR if type > LZMA_CHECK_ID_MAX.
extern void lzma_check_init(lzma_check_state *check, lzma_check type); extern void lzma_check_init(lzma_check_state *check, lzma_check type);
/// Update the check state /// Update the check state

View File

@ -256,7 +256,7 @@ crc64_clmul(const uint8_t *buf, size_t size, uint64_t crc)
// C = buf + size == aligned_buf + size2 // C = buf + size == aligned_buf + size2
// D = buf + size + skip_end == aligned_buf + size2 + skip_end // D = buf + size + skip_end == aligned_buf + size2 + skip_end
const size_t skip_start = (size_t)((uintptr_t)buf & 15); const size_t skip_start = (size_t)((uintptr_t)buf & 15);
const size_t skip_end = (size_t)(-(uintptr_t)(buf + size) & 15); const size_t skip_end = (size_t)((0U - (uintptr_t)(buf + size)) & 15);
const __m128i *aligned_buf = (const __m128i *)( const __m128i *aligned_buf = (const __m128i *)(
(uintptr_t)buf & ~(uintptr_t)15); (uintptr_t)buf & ~(uintptr_t)15);

View File

@ -123,7 +123,10 @@ block_decode(void *coder_ptr, const lzma_allocator *allocator,
return LZMA_DATA_ERROR; return LZMA_DATA_ERROR;
} }
if (!coder->ignore_check) // Don't waste time updating the integrity check if it will be
// ignored. Also skip it if no new output was produced. This
// avoids null pointer + 0 (undefined behavior) when out == 0.
if (!coder->ignore_check && out_used > 0)
lzma_check_update(&coder->check, coder->block->check, lzma_check_update(&coder->check, coder->block->check,
out + out_start, out_used); out + out_start, out_used);

View File

@ -77,8 +77,11 @@ block_encode(void *coder_ptr, const lzma_allocator *allocator,
// checked it at the beginning of this function. // checked it at the beginning of this function.
coder->uncompressed_size += in_used; coder->uncompressed_size += in_used;
lzma_check_update(&coder->check, coder->block->check, // Call lzma_check_update() only if input was consumed. This
in + in_start, in_used); // avoids null pointer + 0 (undefined behavior) when in == 0.
if (in_used > 0)
lzma_check_update(&coder->check, coder->block->check,
in + in_start, in_used);
if (ret != LZMA_STREAM_END || action == LZMA_SYNC_FLUSH) if (ret != LZMA_STREAM_END || action == LZMA_SYNC_FLUSH)
return ret; return ret;

View File

@ -288,13 +288,21 @@ lzma_code(lzma_stream *strm, lzma_action action)
strm->next_in, &in_pos, strm->avail_in, strm->next_in, &in_pos, strm->avail_in,
strm->next_out, &out_pos, strm->avail_out, action); strm->next_out, &out_pos, strm->avail_out, action);
strm->next_in += in_pos; // Updating next_in and next_out has to be skipped when they are NULL
strm->avail_in -= in_pos; // to avoid null pointer + 0 (undefined behavior). Do this by checking
strm->total_in += in_pos; // in_pos > 0 and out_pos > 0 because this way NULL + non-zero (a bug)
// will get caught one way or other.
if (in_pos > 0) {
strm->next_in += in_pos;
strm->avail_in -= in_pos;
strm->total_in += in_pos;
}
strm->next_out += out_pos; if (out_pos > 0) {
strm->avail_out -= out_pos; strm->next_out += out_pos;
strm->total_out += out_pos; strm->avail_out -= out_pos;
strm->total_out += out_pos;
}
strm->internal->avail_in = strm->avail_in; strm->internal->avail_in = strm->avail_in;

View File

@ -203,9 +203,16 @@ index_decode(void *coder_ptr, const lzma_allocator *allocator,
} }
out: out:
// Update the CRC32, // Update the CRC32.
coder->crc32 = lzma_crc32(in + in_start, //
*in_pos - in_start, coder->crc32); // Avoid null pointer + 0 (undefined behavior) in "in + in_start".
// In such a case we had no input and thus in_used == 0.
{
const size_t in_used = *in_pos - in_start;
if (in_used > 0)
coder->crc32 = lzma_crc32(in + in_start,
in_used, coder->crc32);
}
return ret; return ret;
} }

View File

@ -153,8 +153,15 @@ index_encode(void *coder_ptr,
out: out:
// Update the CRC32. // Update the CRC32.
coder->crc32 = lzma_crc32(out + out_start, //
*out_pos - out_start, coder->crc32); // Avoid null pointer + 0 (undefined behavior) in "out + out_start".
// In such a case we had no input and thus out_used == 0.
{
const size_t out_used = *out_pos - out_start;
if (out_used > 0)
coder->crc32 = lzma_crc32(out + out_start,
out_used, coder->crc32);
}
return ret; return ret;
} }

View File

@ -328,9 +328,16 @@ lzma_index_hash_decode(lzma_index_hash *index_hash, const uint8_t *in,
} }
out: out:
// Update the CRC32, // Update the CRC32.
index_hash->crc32 = lzma_crc32(in + in_start, //
*in_pos - in_start, index_hash->crc32); // Avoid null pointer + 0 (undefined behavior) in "in + in_start".
// In such a case we had no input and thus in_used == 0.
{
const size_t in_used = *in_pos - in_start;
if (in_used > 0)
index_hash->crc32 = lzma_crc32(in + in_start,
in_used, index_hash->crc32);
}
return ret; return ret;
} }

View File

@ -262,7 +262,11 @@ lzip_decode(void *coder_ptr, const lzma_allocator *allocator,
coder->member_size += *in_pos - in_start; coder->member_size += *in_pos - in_start;
coder->uncompressed_size += out_used; coder->uncompressed_size += out_used;
if (!coder->ignore_check) // Don't update the CRC32 if the integrity check will be
// ignored or if there was no new output. The latter is
// important in case out == NULL to avoid null pointer + 0
// which is undefined behavior.
if (!coder->ignore_check && out_used > 0)
coder->crc32 = lzma_crc32(out + out_start, out_used, coder->crc32 = lzma_crc32(out + out_start, out_used,
coder->crc32); coder->crc32);

View File

@ -1358,9 +1358,11 @@ stream_decode_mt(void *coder_ptr, const lzma_allocator *allocator,
// values after we read these as those changes can only be // values after we read these as those changes can only be
// towards more favorable conditions (less memory in use, // towards more favorable conditions (less memory in use,
// more in cache). // more in cache).
uint64_t mem_in_use; //
uint64_t mem_cached; // These are initalized to silence warnings.
struct worker_thread *thr = NULL; // Init to silence warning. uint64_t mem_in_use = 0;
uint64_t mem_cached = 0;
struct worker_thread *thr = NULL;
mythread_sync(coder->mutex) { mythread_sync(coder->mutex) {
mem_in_use = coder->mem_in_use; mem_in_use = coder->mem_in_use;

View File

@ -645,7 +645,7 @@ stream_encode_in(lzma_stream_coder *coder, const lzma_allocator *allocator,
} }
if (block_error) { if (block_error) {
lzma_ret ret; lzma_ret ret = LZMA_OK; // Init to silence a warning.
mythread_sync(coder->mutex) { mythread_sync(coder->mutex) {
ret = coder->thread_error; ret = coder->thread_error;

View File

@ -316,7 +316,7 @@ parse_lzma12_preset(const char **const str, const char *str_end,
assert(*str < str_end); assert(*str < str_end);
*preset = (uint32_t)(**str - '0'); *preset = (uint32_t)(**str - '0');
// NOTE: Remember to update LZMA_PRESET_STR if this is modified! // NOTE: Remember to update LZMA12_PRESET_STR if this is modified!
while (++*str < str_end) { while (++*str < str_end) {
switch (**str) { switch (**str) {
case 'e': case 'e':
@ -667,7 +667,7 @@ parse_options(const char **const str, const char *str_end,
&& *p >= '0' && *p <= '9'); && *p >= '0' && *p <= '9');
if (p < name_eq_value_end) { if (p < name_eq_value_end) {
// Remember this position so that it an be // Remember this position so that it can be
// used for error messages that are // used for error messages that are
// specifically about the suffix. (Out of // specifically about the suffix. (Out of
// range values are about the whole value // range values are about the whole value
@ -1131,6 +1131,13 @@ lzma_str_from_filters(char **output_str, const lzma_filter *filters,
const char *opt_delim = (flags & LZMA_STR_GETOPT_LONG) ? "=" : ":"; const char *opt_delim = (flags & LZMA_STR_GETOPT_LONG) ? "=" : ":";
for (size_t i = 0; filters[i].id != LZMA_VLI_UNKNOWN; ++i) { for (size_t i = 0; filters[i].id != LZMA_VLI_UNKNOWN; ++i) {
// If we reach LZMA_FILTERS_MAX, then the filters array
// is too large since the ID cannot be LZMA_VLI_UNKNOWN here.
if (i == LZMA_FILTERS_MAX) {
str_free(&dest, allocator);
return LZMA_OPTIONS_ERROR;
}
// Don't add a space between filters if the caller // Don't add a space between filters if the caller
// doesn't want them. // doesn't want them.
if (i > 0 && !(flags & LZMA_STR_NO_SPACES)) if (i > 0 && !(flags & LZMA_STR_NO_SPACES))

View File

@ -42,7 +42,12 @@ delta_decode(void *coder_ptr, const lzma_allocator *allocator,
in, in_pos, in_size, out, out_pos, out_size, in, in_pos, in_size, out, out_pos, out_size,
action); action);
decode_buffer(coder, out + out_start, *out_pos - out_start); // out might be NULL. In that case size == 0. Null pointer + 0 is
// undefined behavior so skip the call in that case as it would
// do nothing anyway.
const size_t size = *out_pos - out_start;
if (size > 0)
decode_buffer(coder, out + out_start, size);
return ret; return ret;
} }

View File

@ -63,7 +63,12 @@ delta_encode(void *coder_ptr, const lzma_allocator *allocator,
const size_t out_avail = out_size - *out_pos; const size_t out_avail = out_size - *out_pos;
const size_t size = my_min(in_avail, out_avail); const size_t size = my_min(in_avail, out_avail);
copy_and_encode(coder, in + *in_pos, out + *out_pos, size); // in and out might be NULL. In such cases size == 0.
// Null pointer + 0 is undefined behavior so skip
// the call in that case as it would do nothing anyway.
if (size > 0)
copy_and_encode(coder, in + *in_pos, out + *out_pos,
size);
*in_pos += size; *in_pos += size;
*out_pos += size; *out_pos += size;
@ -78,7 +83,10 @@ delta_encode(void *coder_ptr, const lzma_allocator *allocator,
in, in_pos, in_size, out, out_pos, out_size, in, in_pos, in_size, out, out_pos, out_size,
action); action);
encode_in_place(coder, out + out_start, *out_pos - out_start); // Like above, avoid null pointer + 0.
const size_t size = *out_pos - out_start;
if (size > 0)
encode_in_place(coder, out + out_start, size);
} }
return ret; return ret;

View File

@ -220,10 +220,11 @@ move_pending(lzma_mf *mf)
/// of matches found. /// of matches found.
#define call_find(func, len_best) \ #define call_find(func, len_best) \
do { \ do { \
matches_count = func(len_limit, pos, cur, cur_match, mf->depth, \ matches_count = (uint32_t)(func(len_limit, pos, cur, cur_match, \
mf->son, mf->cyclic_pos, mf->cyclic_size, \ mf->depth, mf->son, \
mf->cyclic_pos, mf->cyclic_size, \
matches + matches_count, len_best) \ matches + matches_count, len_best) \
- matches; \ - matches); \
move_pos(mf); \ move_pos(mf); \
return matches_count; \ return matches_count; \
} while (0) } while (0)
@ -242,8 +243,8 @@ do { \
/// \param cur_match Start position of the current match candidate /// \param cur_match Start position of the current match candidate
/// \param depth Maximum length of the hash chain /// \param depth Maximum length of the hash chain
/// \param son lzma_mf.son (contains the hash chain) /// \param son lzma_mf.son (contains the hash chain)
/// \param cyclic_pos /// \param cyclic_pos lzma_mf.cyclic_pos
/// \param cyclic_size /// \param cyclic_size lzma_mf_cyclic_size
/// \param matches Array to hold the matches. /// \param matches Array to hold the matches.
/// \param len_best The length of the longest match found so far. /// \param len_best The length of the longest match found so far.
static lzma_match * static lzma_match *

View File

@ -139,9 +139,11 @@ simple_code(void *coder_ptr, const lzma_allocator *allocator,
return ret; return ret;
} }
// Filter out[]. // Filter out[] unless there is nothing to filter.
// This way we avoid null pointer + 0 (undefined behavior)
// when out == NULL.
const size_t size = *out_pos - out_start; const size_t size = *out_pos - out_start;
const size_t filtered = call_filter( const size_t filtered = size == 0 ? 0 : call_filter(
coder, out + out_start, size); coder, out + out_start, size);
const size_t unfiltered = size - filtered; const size_t unfiltered = size - filtered;

View File

@ -720,9 +720,18 @@ args_parse(args_info *args, int argc, char **argv)
// be done also when uncompressing raw data, since for raw decoding // be done also when uncompressing raw data, since for raw decoding
// the options given on the command line are used to know what kind // the options given on the command line are used to know what kind
// of raw data we are supposed to decode. // of raw data we are supposed to decode.
if (opt_mode == MODE_COMPRESS || opt_format == FORMAT_RAW) if (opt_mode == MODE_COMPRESS || (opt_format == FORMAT_RAW
&& opt_mode != MODE_LIST))
coder_set_compression_settings(); coder_set_compression_settings();
// If raw format is used and a custom suffix is not provided,
// then only stdout mode can be used when compressing or decompressing.
if (opt_format == FORMAT_RAW && !suffix_is_set() && !opt_stdout
&& (opt_mode == MODE_COMPRESS
|| opt_mode == MODE_DECOMPRESS))
message_fatal(_("With --format=raw, --suffix=.SUF is "
"required unless writing to stdout"));
// If no filenames are given, use stdin. // If no filenames are given, use stdin.
if (argv[optind] == NULL && args->files_name == NULL) { if (argv[optind] == NULL && args->files_name == NULL) {
// We don't modify or free() the "-" constant. The caller // We don't modify or free() the "-" constant. The caller

View File

@ -66,7 +66,8 @@ extern void coder_set_extreme(void);
/// Add a filter to the custom filter chain /// Add a filter to the custom filter chain
extern void coder_add_filter(lzma_vli id, void *options); extern void coder_add_filter(lzma_vli id, void *options);
/// /// Set and partially validate compression settings. This can also be used
/// in decompression or test mode with the raw format.
extern void coder_set_compression_settings(void); extern void coder_set_compression_settings(void);
/// Compress or decompress the given file /// Compress or decompress the given file

View File

@ -140,7 +140,7 @@ io_write_to_user_abort_pipe(void)
// handler. So ignore the errors and try to avoid warnings with // handler. So ignore the errors and try to avoid warnings with
// GCC and glibc when _FORTIFY_SOURCE=2 is used. // GCC and glibc when _FORTIFY_SOURCE=2 is used.
uint8_t b = '\0'; uint8_t b = '\0';
const int ret = write(user_abort_pipe[1], &b, 1); const ssize_t ret = write(user_abort_pipe[1], &b, 1);
(void)ret; (void)ret;
return; return;
} }
@ -192,25 +192,32 @@ io_sandbox_enter(int src_fd)
// Capsicum needs FreeBSD 10.0 or later. // Capsicum needs FreeBSD 10.0 or later.
cap_rights_t rights; cap_rights_t rights;
if (cap_enter())
goto error;
if (cap_rights_limit(src_fd, cap_rights_init(&rights, if (cap_rights_limit(src_fd, cap_rights_init(&rights,
CAP_EVENT, CAP_FCNTL, CAP_LOOKUP, CAP_READ, CAP_SEEK)) < 0 && CAP_EVENT, CAP_FCNTL, CAP_LOOKUP, CAP_READ, CAP_SEEK)))
errno != ENOSYS) goto error;
if (src_fd != STDIN_FILENO && cap_rights_limit(
STDIN_FILENO, cap_rights_clear(&rights)))
goto error; goto error;
if (cap_rights_limit(STDOUT_FILENO, cap_rights_init(&rights, if (cap_rights_limit(STDOUT_FILENO, cap_rights_init(&rights,
CAP_EVENT, CAP_FCNTL, CAP_FSTAT, CAP_LOOKUP, CAP_EVENT, CAP_FCNTL, CAP_FSTAT, CAP_LOOKUP,
CAP_WRITE, CAP_SEEK)) < 0 && errno != ENOSYS) CAP_WRITE, CAP_SEEK)))
goto error;
if (cap_rights_limit(STDERR_FILENO, cap_rights_init(&rights,
CAP_WRITE)))
goto error; goto error;
if (cap_rights_limit(user_abort_pipe[0], cap_rights_init(&rights, if (cap_rights_limit(user_abort_pipe[0], cap_rights_init(&rights,
CAP_EVENT)) < 0 && errno != ENOSYS) CAP_EVENT)))
goto error; goto error;
if (cap_rights_limit(user_abort_pipe[1], cap_rights_init(&rights, if (cap_rights_limit(user_abort_pipe[1], cap_rights_init(&rights,
CAP_WRITE)) < 0 && errno != ENOSYS) CAP_WRITE)))
goto error;
if (cap_enter() < 0 && errno != ENOSYS)
goto error; goto error;
#elif defined(HAVE_PLEDGE) #elif defined(HAVE_PLEDGE)
@ -233,6 +240,15 @@ io_sandbox_enter(int src_fd)
return; return;
error: error:
#ifdef HAVE_CAPSICUM
// If a kernel is configured without capability mode support or
// used in an emulator that does not implement the capability
// system calls, then the Capsicum system calls will fail and set
// errno to ENOSYS. In that case xz will silently run without
// the sandbox.
if (errno == ENOSYS)
return;
#endif
message_fatal(_("Failed to enable the sandbox")); message_fatal(_("Failed to enable the sandbox"));
} }
#endif // ENABLE_SANDBOX #endif // ENABLE_SANDBOX

View File

@ -276,7 +276,7 @@ init_headings(void)
// If the translated string is wider than the minimum width // If the translated string is wider than the minimum width
// set at compile time, increase the width. // set at compile time, increase the width.
if ((size_t)(headings[HEADING_CHECK].columns) < w) if ((size_t)(headings[HEADING_CHECK].columns) < w)
headings[HEADING_CHECK].columns = w; headings[HEADING_CHECK].columns = (int)w;
} }
for (unsigned i = 0; i < ARRAY_SIZE(headings); ++i) { for (unsigned i = 0; i < ARRAY_SIZE(headings); ++i) {
@ -291,7 +291,7 @@ init_headings(void)
// If the translated string is wider than the minimum width // If the translated string is wider than the minimum width
// set at compile time, increase the width. // set at compile time, increase the width.
if ((size_t)(headings[i].columns) < w) if ((size_t)(headings[i].columns) < w)
headings[i].columns = w; headings[i].columns = (int)w;
// Calculate the field width for printf("%*s") so that // Calculate the field width for printf("%*s") so that
// the string uses .columns number of columns on a terminal. // the string uses .columns number of columns on a terminal.

View File

@ -49,13 +49,13 @@ typedef struct {
/// is called, which should update the given value to filter-specific /// is called, which should update the given value to filter-specific
/// options structure. /// options structure.
/// ///
/// This returns only if no errors occur.
///
/// \param str String containing the options from the command line /// \param str String containing the options from the command line
/// \param opts Filter-specific option map /// \param opts Filter-specific option map
/// \param set Filter-specific function to update filter_options /// \param set Filter-specific function to update filter_options
/// \param filter_options Pointer to filter-specific options structure /// \param filter_options Pointer to filter-specific options structure
/// ///
/// \return Returns only if no errors occur.
///
static void static void
parse_options(const char *str, const option_map *opts, parse_options(const char *str, const option_map *opts,
void (*set)(void *filter_options, void (*set)(void *filter_options,

View File

@ -131,15 +131,7 @@ uncompressed_name(const char *src_name, const size_t src_len)
const char *new_suffix = ""; const char *new_suffix = "";
size_t new_len = 0; size_t new_len = 0;
if (opt_format == FORMAT_RAW) { if (opt_format != FORMAT_RAW) {
// Don't check for known suffixes when --format=raw was used.
if (custom_suffix == NULL) {
message_error(_("%s: With --format=raw, "
"--suffix=.SUF is required unless "
"writing to stdout"), src_name);
return NULL;
}
} else {
for (size_t i = 0; i < ARRAY_SIZE(suffixes); ++i) { for (size_t i = 0; i < ARRAY_SIZE(suffixes); ++i) {
new_len = test_suffix(suffixes[i].compressed, new_len = test_suffix(suffixes[i].compressed,
src_name, src_len); src_name, src_len);
@ -262,15 +254,6 @@ compressed_name(const char *src_name, size_t src_len)
} }
} }
// TODO: Hmm, maybe it would be better to validate this in args.c,
// since the suffix handling when decoding is weird now.
if (opt_format == FORMAT_RAW && custom_suffix == NULL) {
message_error(_("%s: With --format=raw, "
"--suffix=.SUF is required unless "
"writing to stdout"), src_name);
return NULL;
}
const char *suffix = custom_suffix != NULL const char *suffix = custom_suffix != NULL
? custom_suffix : suffixes[0]; ? custom_suffix : suffixes[0];
size_t suffix_len = strlen(suffix); size_t suffix_len = strlen(suffix);
@ -409,3 +392,10 @@ suffix_set(const char *suffix)
custom_suffix = xstrdup(suffix); custom_suffix = xstrdup(suffix);
return; return;
} }
extern bool
suffix_is_set(void)
{
return custom_suffix != NULL;
}

View File

@ -26,3 +26,11 @@ extern char *suffix_get_dest_name(const char *src_name);
/// suffix, thus if this is called multiple times, the old suffixes are freed /// suffix, thus if this is called multiple times, the old suffixes are freed
/// and forgotten. /// and forgotten.
extern void suffix_set(const char *suffix); extern void suffix_set(const char *suffix);
/// \brief Check if a custom suffix has been set
///
/// Returns true if the internal tracking of the suffix string has been set
/// and false if the string has not been set. This will keep the suffix
/// string encapsulated instead of extern-ing the variable.
extern bool suffix_is_set(void);

View File

@ -3017,4 +3017,4 @@ XZ Utils: <https://tukaani.org/xz/>
.br .br
XZ Embedded: <https://tukaani.org/xz/embedded.html> XZ Embedded: <https://tukaani.org/xz/embedded.html>
.br .br
LZMA SDK: <http://7-zip.org/sdk.html> LZMA SDK: <https://7-zip.org/sdk.html>

View File

@ -379,7 +379,7 @@
#define PACKAGE_NAME "XZ Utils" #define PACKAGE_NAME "XZ Utils"
/* Define to the full name and version of this package. */ /* Define to the full name and version of this package. */
#define PACKAGE_STRING "XZ Utils 5.4.1" #define PACKAGE_STRING "XZ Utils 5.4.2"
/* Define to the one symbol short name of this package. */ /* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "xz" #define PACKAGE_TARNAME "xz"
@ -388,7 +388,7 @@
#define PACKAGE_URL "https://tukaani.org/xz/" #define PACKAGE_URL "https://tukaani.org/xz/"
/* Define to the version of this package. */ /* Define to the version of this package. */
#define PACKAGE_VERSION "5.4.1" #define PACKAGE_VERSION "5.4.2"
/* Define to necessary symbol if this constant uses a non-standard name on /* Define to necessary symbol if this constant uses a non-standard name on
your system. */ your system. */
@ -549,7 +549,7 @@
/* Version number of package */ /* Version number of package */
#define VERSION "5.4.1" #define VERSION "5.4.2"
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
significant byte first (like Motorola and SPARC, unlike Intel). */ significant byte first (like Motorola and SPARC, unlike Intel). */