aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/lzma/liblzma/common
diff options
context:
space:
mode:
authorrobot-contrib <robot-contrib@yandex-team.com>2024-02-06 01:15:14 +0300
committerAlexander Smirnov <alex@ydb.tech>2024-02-09 19:18:11 +0300
commitd8dda255108e56bd45c714be6b3a479cb49823c6 (patch)
treea3da500650f69164b8a2e78c64b1e36dce79c50b /contrib/libs/lzma/liblzma/common
parentc29b5e57643acd331dfdacd1e3ab836b6e4b018d (diff)
downloadydb-d8dda255108e56bd45c714be6b3a479cb49823c6.tar.gz
Update contrib/libs/lzma to 5.4.6
Diffstat (limited to 'contrib/libs/lzma/liblzma/common')
-rw-r--r--contrib/libs/lzma/liblzma/common/alone_encoder.c11
-rw-r--r--contrib/libs/lzma/liblzma/common/block_buffer_encoder.c2
-rw-r--r--contrib/libs/lzma/liblzma/common/block_decoder.c5
-rw-r--r--contrib/libs/lzma/liblzma/common/block_encoder.c7
-rw-r--r--contrib/libs/lzma/liblzma/common/common.c26
-rw-r--r--contrib/libs/lzma/liblzma/common/common.h38
-rw-r--r--contrib/libs/lzma/liblzma/common/file_info.c2
-rw-r--r--contrib/libs/lzma/liblzma/common/filter_encoder.c15
-rw-r--r--contrib/libs/lzma/liblzma/common/index.c7
-rw-r--r--contrib/libs/lzma/liblzma/common/index.h14
-rw-r--r--contrib/libs/lzma/liblzma/common/index_decoder.c15
-rw-r--r--contrib/libs/lzma/liblzma/common/index_decoder.h1
-rw-r--r--contrib/libs/lzma/liblzma/common/index_encoder.c13
-rw-r--r--contrib/libs/lzma/liblzma/common/index_hash.c17
-rw-r--r--contrib/libs/lzma/liblzma/common/lzip_decoder.c8
-rw-r--r--contrib/libs/lzma/liblzma/common/memcmplen.h21
-rw-r--r--contrib/libs/lzma/liblzma/common/microlzma_encoder.c3
-rw-r--r--contrib/libs/lzma/liblzma/common/stream_buffer_encoder.c1
-rw-r--r--contrib/libs/lzma/liblzma/common/stream_decoder.c3
-rw-r--r--contrib/libs/lzma/liblzma/common/stream_decoder_mt.c16
-rw-r--r--contrib/libs/lzma/liblzma/common/stream_encoder_mt.c4
-rw-r--r--contrib/libs/lzma/liblzma/common/stream_flags_common.h3
-rw-r--r--contrib/libs/lzma/liblzma/common/string_conversion.c21
23 files changed, 179 insertions, 74 deletions
diff --git a/contrib/libs/lzma/liblzma/common/alone_encoder.c b/contrib/libs/lzma/liblzma/common/alone_encoder.c
index c9392f3769..7d3812fa6e 100644
--- a/contrib/libs/lzma/liblzma/common/alone_encoder.c
+++ b/contrib/libs/lzma/liblzma/common/alone_encoder.c
@@ -75,7 +75,6 @@ alone_encoder_end(void *coder_ptr, const lzma_allocator *allocator)
}
-// At least for now, this is not used by any internal function.
static lzma_ret
alone_encoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
const lzma_options_lzma *options)
@@ -141,16 +140,6 @@ alone_encoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
}
-/*
-extern lzma_ret
-lzma_alone_encoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
- const lzma_options_alone *options)
-{
- lzma_next_coder_init(&alone_encoder_init, next, allocator, options);
-}
-*/
-
-
extern LZMA_API(lzma_ret)
lzma_alone_encoder(lzma_stream *strm, const lzma_options_lzma *options)
{
diff --git a/contrib/libs/lzma/liblzma/common/block_buffer_encoder.c b/contrib/libs/lzma/liblzma/common/block_buffer_encoder.c
index a47342efd0..fdef02de89 100644
--- a/contrib/libs/lzma/liblzma/common/block_buffer_encoder.c
+++ b/contrib/libs/lzma/liblzma/common/block_buffer_encoder.c
@@ -277,7 +277,7 @@ block_buffer_encode(lzma_block *block, const lzma_allocator *allocator,
if (ret != LZMA_BUF_ERROR)
return ret;
- // The data was uncompressible (at least with the options
+ // The data was incompressible (at least with the options
// given to us) or the output buffer was too small. Use the
// uncompressed chunks of LZMA2 to wrap the data into a valid
// Block. If we haven't been given enough output space, even
diff --git a/contrib/libs/lzma/liblzma/common/block_decoder.c b/contrib/libs/lzma/liblzma/common/block_decoder.c
index 4827e0f046..be647d4855 100644
--- a/contrib/libs/lzma/liblzma/common/block_decoder.c
+++ b/contrib/libs/lzma/liblzma/common/block_decoder.c
@@ -123,7 +123,10 @@ block_decode(void *coder_ptr, const lzma_allocator *allocator,
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,
out + out_start, out_used);
diff --git a/contrib/libs/lzma/liblzma/common/block_encoder.c b/contrib/libs/lzma/liblzma/common/block_encoder.c
index 520ecc5a49..4a136ef65e 100644
--- a/contrib/libs/lzma/liblzma/common/block_encoder.c
+++ b/contrib/libs/lzma/liblzma/common/block_encoder.c
@@ -77,8 +77,11 @@ block_encode(void *coder_ptr, const lzma_allocator *allocator,
// checked it at the beginning of this function.
coder->uncompressed_size += in_used;
- lzma_check_update(&coder->check, coder->block->check,
- in + in_start, in_used);
+ // Call lzma_check_update() only if input was consumed. This
+ // 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)
return ret;
diff --git a/contrib/libs/lzma/liblzma/common/common.c b/contrib/libs/lzma/liblzma/common/common.c
index a708fdf187..adb50d785d 100644
--- a/contrib/libs/lzma/liblzma/common/common.c
+++ b/contrib/libs/lzma/liblzma/common/common.c
@@ -35,7 +35,8 @@ lzma_version_string(void)
// Memory allocation //
///////////////////////
-extern void * lzma_attribute((__malloc__)) lzma_attr_alloc_size(1)
+lzma_attr_alloc_size(1)
+extern void *
lzma_alloc(size_t size, const lzma_allocator *allocator)
{
// Some malloc() variants return NULL if called with size == 0.
@@ -53,7 +54,8 @@ lzma_alloc(size_t size, const lzma_allocator *allocator)
}
-extern void * lzma_attribute((__malloc__)) lzma_attr_alloc_size(1)
+lzma_attr_alloc_size(1)
+extern void *
lzma_alloc_zero(size_t size, const lzma_allocator *allocator)
{
// Some calloc() variants return NULL if called with size == 0.
@@ -288,13 +290,21 @@ lzma_code(lzma_stream *strm, lzma_action action)
strm->next_in, &in_pos, strm->avail_in,
strm->next_out, &out_pos, strm->avail_out, action);
- strm->next_in += in_pos;
- strm->avail_in -= in_pos;
- strm->total_in += in_pos;
+ // Updating next_in and next_out has to be skipped when they are NULL
+ // to avoid null pointer + 0 (undefined behavior). Do this by checking
+ // 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;
- strm->avail_out -= out_pos;
- strm->total_out += out_pos;
+ if (out_pos > 0) {
+ strm->next_out += out_pos;
+ strm->avail_out -= out_pos;
+ strm->total_out += out_pos;
+ }
strm->internal->avail_in = strm->avail_in;
diff --git a/contrib/libs/lzma/liblzma/common/common.h b/contrib/libs/lzma/liblzma/common/common.h
index 11fec52c59..378923e401 100644
--- a/contrib/libs/lzma/liblzma/common/common.h
+++ b/contrib/libs/lzma/liblzma/common/common.h
@@ -17,17 +17,28 @@
#include "mythread.h"
#include "tuklib_integer.h"
+// LZMA_API_EXPORT is used to mark the exported API functions.
+// It's used to define the LZMA_API macro.
+//
+// lzma_attr_visibility_hidden is used for marking *declarations* of extern
+// variables that are internal to liblzma (-fvisibility=hidden alone is
+// enough to hide the *definitions*). Such markings allow slightly more
+// efficient code to accesses those variables in ELF shared libraries.
#if defined(_WIN32) || defined(__CYGWIN__)
# ifdef DLL_EXPORT
# define LZMA_API_EXPORT __declspec(dllexport)
# else
# define LZMA_API_EXPORT
# endif
+# define lzma_attr_visibility_hidden
// Don't use ifdef or defined() below.
#elif HAVE_VISIBILITY
# define LZMA_API_EXPORT __attribute__((__visibility__("default")))
+# define lzma_attr_visibility_hidden \
+ __attribute__((__visibility__("hidden")))
#else
# define LZMA_API_EXPORT
+# define lzma_attr_visibility_hidden
#endif
#define LZMA_API(type) LZMA_API_EXPORT type LZMA_API_CALL
@@ -47,7 +58,7 @@
// to 2 then symbol versioning is done only if also PIC is defined.
// By default Libtool defines PIC when building a shared library and
// doesn't define it when building a static library but it can be
-// overriden with --with-pic and --without-pic. configure let's rely
+// overridden with --with-pic and --without-pic. configure let's rely
// on PIC if neither --with-pic or --without-pic was used.
#if defined(HAVE_SYMBOL_VERSIONS_LINUX) \
&& (HAVE_SYMBOL_VERSIONS_LINUX == 2 && !defined(PIC))
@@ -87,6 +98,23 @@
# endif
#endif
+// MSVC has __forceinline which shouldn't be combined with the inline keyword
+// (results in a warning).
+//
+// GCC 3.1 added always_inline attribute so we don't need to check
+// for __GNUC__ version. Similarly, all relevant Clang versions
+// support it (at least Clang 3.0.0 does already).
+// Other compilers might support too which also support __has_attribute
+// (Solaris Studio) so do that check too.
+#if defined(_MSC_VER)
+# define lzma_always_inline __forceinline
+#elif defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER) \
+ || lzma_has_attribute(__always_inline__)
+# define lzma_always_inline inline __attribute__((__always_inline__))
+#else
+# define lzma_always_inline inline
+#endif
+
// These allow helping the compiler in some often-executed branches, whose
// result is almost always the same.
#ifdef __GNUC__
@@ -297,14 +325,14 @@ struct lzma_internal_s {
/// Allocates memory
-extern void *lzma_alloc(size_t size, const lzma_allocator *allocator)
- lzma_attribute((__malloc__)) lzma_attr_alloc_size(1);
+lzma_attr_alloc_size(1)
+extern void *lzma_alloc(size_t size, const lzma_allocator *allocator);
/// Allocates memory and zeroes it (like calloc()). This can be faster
/// than lzma_alloc() + memzero() while being backward compatible with
/// custom allocators.
-extern void * lzma_attribute((__malloc__)) lzma_attr_alloc_size(1)
- lzma_alloc_zero(size_t size, const lzma_allocator *allocator);
+lzma_attr_alloc_size(1)
+extern void *lzma_alloc_zero(size_t size, const lzma_allocator *allocator);
/// Frees memory
extern void lzma_free(void *ptr, const lzma_allocator *allocator);
diff --git a/contrib/libs/lzma/liblzma/common/file_info.c b/contrib/libs/lzma/liblzma/common/file_info.c
index a6b7e145ae..799bb024fe 100644
--- a/contrib/libs/lzma/liblzma/common/file_info.c
+++ b/contrib/libs/lzma/liblzma/common/file_info.c
@@ -350,7 +350,7 @@ file_info_decode(void *coder_ptr, const lzma_allocator *allocator,
// coder->temp[coder->temp_size - LZMA_STREAM_HEADER_SIZE].
//
// Otherwise we will need to seek. The seeking is done so
- // that Stream Footer wil be at the end of coder->temp.
+ // that Stream Footer will be at the end of coder->temp.
// This way it's likely that we also get a complete Index
// field into coder->temp without needing a separate seek
// for that (unless the Index field is big).
diff --git a/contrib/libs/lzma/liblzma/common/filter_encoder.c b/contrib/libs/lzma/liblzma/common/filter_encoder.c
index 978b7a6bb5..c7777dfef8 100644
--- a/contrib/libs/lzma/liblzma/common/filter_encoder.c
+++ b/contrib/libs/lzma/liblzma/common/filter_encoder.c
@@ -37,9 +37,12 @@ typedef struct {
uint64_t (*block_size)(const void *options);
/// Tells the size of the Filter Properties field. If options are
- /// invalid, UINT32_MAX is returned. If this is NULL, props_size_fixed
- /// is used.
+ /// invalid, LZMA_OPTIONS_ERROR is returned and size is set to
+ /// UINT32_MAX.
lzma_ret (*props_size_get)(uint32_t *size, const void *options);
+
+ /// Some filters will always have the same size Filter Properties
+ /// field. If props_size_get is NULL, this value is used.
uint32_t props_size_fixed;
/// Encodes Filter Properties.
@@ -216,17 +219,17 @@ lzma_filters_update(lzma_stream *strm, const lzma_filter *filters)
extern lzma_ret
lzma_raw_encoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
- const lzma_filter *options)
+ const lzma_filter *filters)
{
return lzma_raw_coder_init(next, allocator,
- options, (lzma_filter_find)(&encoder_find), true);
+ filters, (lzma_filter_find)(&encoder_find), true);
}
extern LZMA_API(lzma_ret)
-lzma_raw_encoder(lzma_stream *strm, const lzma_filter *options)
+lzma_raw_encoder(lzma_stream *strm, const lzma_filter *filters)
{
- lzma_next_strm_init(lzma_raw_coder_init, strm, options,
+ lzma_next_strm_init(lzma_raw_coder_init, strm, filters,
(lzma_filter_find)(&encoder_find), true);
strm->internal->supported_actions[LZMA_RUN] = true;
diff --git a/contrib/libs/lzma/liblzma/common/index.c b/contrib/libs/lzma/liblzma/common/index.c
index 24ec3c10c2..8a35f4398d 100644
--- a/contrib/libs/lzma/liblzma/common/index.c
+++ b/contrib/libs/lzma/liblzma/common/index.c
@@ -10,6 +10,7 @@
//
///////////////////////////////////////////////////////////////////////////////
+#include "common.h"
#include "index.h"
#include "stream_flags_common.h"
@@ -660,6 +661,12 @@ lzma_index_append(lzma_index *i, const lzma_allocator *allocator,
if (uncompressed_base + uncompressed_size > LZMA_VLI_MAX)
return LZMA_DATA_ERROR;
+ // Check that the new unpadded sum will not overflow. This is
+ // checked again in index_file_size(), but the unpadded sum is
+ // passed to vli_ceil4() which expects a valid lzma_vli value.
+ if (compressed_base + unpadded_size > UNPADDED_SIZE_MAX)
+ return LZMA_DATA_ERROR;
+
// Check that the file size will stay within limits.
if (index_file_size(s->node.compressed_base,
compressed_base + unpadded_size, s->record_count + 1,
diff --git a/contrib/libs/lzma/liblzma/common/index.h b/contrib/libs/lzma/liblzma/common/index.h
index 64e97247dd..7b27d7004c 100644
--- a/contrib/libs/lzma/liblzma/common/index.h
+++ b/contrib/libs/lzma/liblzma/common/index.h
@@ -2,6 +2,13 @@
//
/// \file index.h
/// \brief Handling of Index
+/// \note This header file does not include common.h or lzma.h because
+/// this file is needed by both liblzma internally and by the
+/// tests. Including common.h will include and define many things
+/// the tests do not need and prevents issues with header file
+/// include order. This way, if lzma.h or common.h are not
+/// included before this file it will break on every OS instead
+/// of causing more subtle errors.
//
// Author: Lasse Collin
//
@@ -13,8 +20,6 @@
#ifndef LZMA_INDEX_H
#define LZMA_INDEX_H
-#include "common.h"
-
/// Minimum Unpadded Size
#define UNPADDED_SIZE_MIN LZMA_VLI_C(5)
@@ -22,6 +27,9 @@
/// Maximum Unpadded Size
#define UNPADDED_SIZE_MAX (LZMA_VLI_MAX & ~LZMA_VLI_C(3))
+/// Index Indicator based on xz specification
+#define INDEX_INDICATOR 0
+
/// Get the size of the Index Padding field. This is needed by Index encoder
/// and decoder, but applications should have no use for this.
@@ -38,7 +46,7 @@ extern void lzma_index_prealloc(lzma_index *i, lzma_vli records);
static inline lzma_vli
vli_ceil4(lzma_vli vli)
{
- assert(vli <= LZMA_VLI_MAX);
+ assert(vli <= UNPADDED_SIZE_MAX);
return (vli + 3) & ~LZMA_VLI_C(3);
}
diff --git a/contrib/libs/lzma/liblzma/common/index_decoder.c b/contrib/libs/lzma/liblzma/common/index_decoder.c
index b268988533..19a31b3e94 100644
--- a/contrib/libs/lzma/liblzma/common/index_decoder.c
+++ b/contrib/libs/lzma/liblzma/common/index_decoder.c
@@ -80,7 +80,7 @@ index_decode(void *coder_ptr, const lzma_allocator *allocator,
// format". One could argue that the application should
// verify the Index Indicator before trying to decode the
// Index, but well, I suppose it is simpler this way.
- if (in[(*in_pos)++] != 0x00)
+ if (in[(*in_pos)++] != INDEX_INDICATOR)
return LZMA_DATA_ERROR;
coder->sequence = SEQ_COUNT;
@@ -203,9 +203,16 @@ index_decode(void *coder_ptr, const lzma_allocator *allocator,
}
out:
- // Update the CRC32,
- coder->crc32 = lzma_crc32(in + in_start,
- *in_pos - in_start, coder->crc32);
+ // Update the 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;
}
diff --git a/contrib/libs/lzma/liblzma/common/index_decoder.h b/contrib/libs/lzma/liblzma/common/index_decoder.h
index 1af433b58b..3fec483331 100644
--- a/contrib/libs/lzma/liblzma/common/index_decoder.h
+++ b/contrib/libs/lzma/liblzma/common/index_decoder.h
@@ -13,6 +13,7 @@
#ifndef LZMA_INDEX_DECODER_H
#define LZMA_INDEX_DECODER_H
+#include "common.h"
#include "index.h"
diff --git a/contrib/libs/lzma/liblzma/common/index_encoder.c b/contrib/libs/lzma/liblzma/common/index_encoder.c
index ac97d0cebf..204490cc19 100644
--- a/contrib/libs/lzma/liblzma/common/index_encoder.c
+++ b/contrib/libs/lzma/liblzma/common/index_encoder.c
@@ -65,7 +65,7 @@ index_encode(void *coder_ptr,
while (*out_pos < out_size)
switch (coder->sequence) {
case SEQ_INDICATOR:
- out[*out_pos] = 0x00;
+ out[*out_pos] = INDEX_INDICATOR;
++*out_pos;
coder->sequence = SEQ_COUNT;
break;
@@ -153,8 +153,15 @@ index_encode(void *coder_ptr,
out:
// 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;
}
diff --git a/contrib/libs/lzma/liblzma/common/index_hash.c b/contrib/libs/lzma/liblzma/common/index_hash.c
index 34df85d72f..52c3d65077 100644
--- a/contrib/libs/lzma/liblzma/common/index_hash.c
+++ b/contrib/libs/lzma/liblzma/common/index_hash.c
@@ -145,7 +145,7 @@ lzma_index_hash_append(lzma_index_hash *index_hash, lzma_vli unpadded_size,
lzma_vli uncompressed_size)
{
// Validate the arguments.
- if (index_hash->sequence != SEQ_BLOCK
+ if (index_hash == NULL || index_hash->sequence != SEQ_BLOCK
|| unpadded_size < UNPADDED_SIZE_MIN
|| unpadded_size > UNPADDED_SIZE_MAX
|| uncompressed_size > LZMA_VLI_MAX)
@@ -190,7 +190,7 @@ lzma_index_hash_decode(lzma_index_hash *index_hash, const uint8_t *in,
switch (index_hash->sequence) {
case SEQ_BLOCK:
// Check the Index Indicator is present.
- if (in[(*in_pos)++] != 0x00)
+ if (in[(*in_pos)++] != INDEX_INDICATOR)
return LZMA_DATA_ERROR;
index_hash->sequence = SEQ_COUNT;
@@ -328,9 +328,16 @@ lzma_index_hash_decode(lzma_index_hash *index_hash, const uint8_t *in,
}
out:
- // Update the CRC32,
- index_hash->crc32 = lzma_crc32(in + in_start,
- *in_pos - in_start, index_hash->crc32);
+ // Update the 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;
}
diff --git a/contrib/libs/lzma/liblzma/common/lzip_decoder.c b/contrib/libs/lzma/liblzma/common/lzip_decoder.c
index 20794f9466..88cc7ffd23 100644
--- a/contrib/libs/lzma/liblzma/common/lzip_decoder.c
+++ b/contrib/libs/lzma/liblzma/common/lzip_decoder.c
@@ -186,7 +186,7 @@ lzip_decode(void *coder_ptr, const lzma_allocator *allocator,
// The five lowest bits are for the base-2 logarithm of
// the dictionary size and the highest three bits are
// the fractional part (0/16 to 7/16) that will be
- // substracted to get the final value.
+ // subtracted to get the final value.
//
// For example, with 0xB5:
// b2log = 21
@@ -262,7 +262,11 @@ lzip_decode(void *coder_ptr, const lzma_allocator *allocator,
coder->member_size += *in_pos - in_start;
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);
diff --git a/contrib/libs/lzma/liblzma/common/memcmplen.h b/contrib/libs/lzma/liblzma/common/memcmplen.h
index 5a481a02c9..99d9c519cc 100644
--- a/contrib/libs/lzma/liblzma/common/memcmplen.h
+++ b/contrib/libs/lzma/liblzma/common/memcmplen.h
@@ -19,6 +19,16 @@
# include <immintrin.h>
#endif
+// Only include <intrin.h> if it is needed. The header is only needed
+// on Windows when using an MSVC compatible compiler. The Intel compiler
+// can use the intrinsics without the header file.
+#if defined(TUKLIB_FAST_UNALIGNED_ACCESS) \
+ && defined(_MSC_VER) \
+ && defined(_M_X64) \
+ && !defined(__INTEL_COMPILER)
+# include <intrin.h>
+#endif
+
/// Find out how many equal bytes the two buffers have.
///
@@ -39,7 +49,7 @@
/// It's rounded up to 2^n. This extra amount needs to be
/// allocated in the buffers being used. It needs to be
/// initialized too to keep Valgrind quiet.
-static inline uint32_t lzma_attribute((__always_inline__))
+static lzma_always_inline uint32_t
lzma_memcmplen(const uint8_t *buf1, const uint8_t *buf2,
uint32_t len, uint32_t limit)
{
@@ -59,11 +69,13 @@ lzma_memcmplen(const uint8_t *buf1, const uint8_t *buf2,
while (len < limit) {
const uint64_t x = read64ne(buf1 + len) - read64ne(buf2 + len);
if (x != 0) {
-# if defined(_M_X64) // MSVC or Intel C compiler on Windows
+ // MSVC or Intel C compiler on Windows
+# if (defined(_MSC_VER) || defined(__INTEL_COMPILER)) && defined(_M_X64)
unsigned long tmp;
_BitScanForward64(&tmp, x);
len += (uint32_t)tmp >> 3;
-# else // GCC, clang, or Intel C compiler
+ // GCC, Clang, or Intel C compiler
+# else
len += (uint32_t)__builtin_ctzll(x) >> 3;
# endif
return my_min(len, limit);
@@ -89,7 +101,8 @@ lzma_memcmplen(const uint8_t *buf1, const uint8_t *buf2,
// version isn't used on x86-64.
# define LZMA_MEMCMPLEN_EXTRA 16
while (len < limit) {
- const uint32_t x = 0xFFFF ^ _mm_movemask_epi8(_mm_cmpeq_epi8(
+ const uint32_t x = 0xFFFF ^ (uint32_t)_mm_movemask_epi8(
+ _mm_cmpeq_epi8(
_mm_loadu_si128((const __m128i *)(buf1 + len)),
_mm_loadu_si128((const __m128i *)(buf2 + len))));
diff --git a/contrib/libs/lzma/liblzma/common/microlzma_encoder.c b/contrib/libs/lzma/liblzma/common/microlzma_encoder.c
index d3ef0632dd..a787ca25b8 100644
--- a/contrib/libs/lzma/liblzma/common/microlzma_encoder.c
+++ b/contrib/libs/lzma/liblzma/common/microlzma_encoder.c
@@ -111,7 +111,8 @@ microlzma_encoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
// Encode the properties byte. Bitwise-negation of it will be the
// first output byte.
- return_if_error(lzma_lzma_lclppb_encode(options, &coder->props));
+ if (lzma_lzma_lclppb_encode(options, &coder->props))
+ return LZMA_OPTIONS_ERROR;
// Initialize the LZMA encoder.
const lzma_filter_info filters[2] = {
diff --git a/contrib/libs/lzma/liblzma/common/stream_buffer_encoder.c b/contrib/libs/lzma/liblzma/common/stream_buffer_encoder.c
index af49554a6b..73157590e6 100644
--- a/contrib/libs/lzma/liblzma/common/stream_buffer_encoder.c
+++ b/contrib/libs/lzma/liblzma/common/stream_buffer_encoder.c
@@ -10,6 +10,7 @@
//
///////////////////////////////////////////////////////////////////////////////
+#include "common.h"
#include "index.h"
diff --git a/contrib/libs/lzma/liblzma/common/stream_decoder.c b/contrib/libs/lzma/liblzma/common/stream_decoder.c
index dcf7c1499f..64283812f2 100644
--- a/contrib/libs/lzma/liblzma/common/stream_decoder.c
+++ b/contrib/libs/lzma/liblzma/common/stream_decoder.c
@@ -12,6 +12,7 @@
#include "stream_decoder.h"
#include "block_decoder.h"
+#include "index.h"
typedef struct {
@@ -164,7 +165,7 @@ stream_decode(void *coder_ptr, const lzma_allocator *allocator,
if (coder->pos == 0) {
// Detect if it's Index.
- if (in[*in_pos] == 0x00) {
+ if (in[*in_pos] == INDEX_INDICATOR) {
coder->sequence = SEQ_INDEX;
break;
}
diff --git a/contrib/libs/lzma/liblzma/common/stream_decoder_mt.c b/contrib/libs/lzma/liblzma/common/stream_decoder_mt.c
index 5733c76489..76212b46da 100644
--- a/contrib/libs/lzma/liblzma/common/stream_decoder_mt.c
+++ b/contrib/libs/lzma/liblzma/common/stream_decoder_mt.c
@@ -629,7 +629,7 @@ get_thread(struct lzma_stream_coder *coder, const lzma_allocator *allocator)
coder->thr = coder->threads_free;
coder->threads_free = coder->threads_free->next;
- // The thread is no longer in the cache so substract
+ // The thread is no longer in the cache so subtract
// it from the cached memory usage. Don't add it
// to mem_in_use though; the caller will handle it
// since it knows how much memory it will actually
@@ -887,7 +887,7 @@ decode_block_header(struct lzma_stream_coder *coder,
if (coder->pos == 0) {
// Detect if it's Index.
- if (in[*in_pos] == 0x00)
+ if (in[*in_pos] == INDEX_INDICATOR)
return LZMA_INDEX_DETECTED;
// Calculate the size of the Block Header. Note that
@@ -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
// towards more favorable conditions (less memory in use,
// more in cache).
- uint64_t mem_in_use;
- uint64_t mem_cached;
- struct worker_thread *thr = NULL; // Init to silence warning.
+ //
+ // These are initialized to silence warnings.
+ uint64_t mem_in_use = 0;
+ uint64_t mem_cached = 0;
+ struct worker_thread *thr = NULL;
mythread_sync(coder->mutex) {
mem_in_use = coder->mem_in_use;
@@ -1423,7 +1425,7 @@ stream_decode_mt(void *coder_ptr, const lzma_allocator *allocator,
}
// Update the memory usage counters. Note that coder->mem_*
- // may have changed since we read them so we must substract
+ // may have changed since we read them so we must subtract
// or add the changes.
mythread_sync(coder->mutex) {
coder->mem_cached -= mem_freed;
@@ -1436,7 +1438,7 @@ stream_decode_mt(void *coder_ptr, const lzma_allocator *allocator,
// coder->mem_cached might count the same thing twice.
// If so, this will get corrected in get_thread() when
// a worker_thread is picked from coder->free_threads
- // and its memory usage is substracted from mem_cached.
+ // and its memory usage is subtracted from mem_cached.
coder->mem_in_use += coder->mem_next_in
+ coder->mem_next_filters;
}
diff --git a/contrib/libs/lzma/liblzma/common/stream_encoder_mt.c b/contrib/libs/lzma/liblzma/common/stream_encoder_mt.c
index f4497c10b9..f64de9bdbc 100644
--- a/contrib/libs/lzma/liblzma/common/stream_encoder_mt.c
+++ b/contrib/libs/lzma/liblzma/common/stream_encoder_mt.c
@@ -645,7 +645,7 @@ stream_encode_in(lzma_stream_coder *coder, const lzma_allocator *allocator,
}
if (block_error) {
- lzma_ret ret;
+ lzma_ret ret = LZMA_OK; // Init to silence a warning.
mythread_sync(coder->mutex) {
ret = coder->thread_error;
@@ -743,7 +743,7 @@ stream_encode_mt(void *coder_ptr, const lzma_allocator *allocator,
// These are for wait_for_work().
bool has_blocked = false;
- mythread_condtime wait_abs;
+ mythread_condtime wait_abs = { 0 };
while (true) {
mythread_sync(coder->mutex) {
diff --git a/contrib/libs/lzma/liblzma/common/stream_flags_common.h b/contrib/libs/lzma/liblzma/common/stream_flags_common.h
index 9f3122a3b1..84e96ba1ff 100644
--- a/contrib/libs/lzma/liblzma/common/stream_flags_common.h
+++ b/contrib/libs/lzma/liblzma/common/stream_flags_common.h
@@ -18,7 +18,10 @@
/// Size of the Stream Flags field
#define LZMA_STREAM_FLAGS_SIZE 2
+lzma_attr_visibility_hidden
extern const uint8_t lzma_header_magic[6];
+
+lzma_attr_visibility_hidden
extern const uint8_t lzma_footer_magic[2];
diff --git a/contrib/libs/lzma/liblzma/common/string_conversion.c b/contrib/libs/lzma/liblzma/common/string_conversion.c
index 53fdff2a62..d2c1e80936 100644
--- a/contrib/libs/lzma/liblzma/common/string_conversion.c
+++ b/contrib/libs/lzma/liblzma/common/string_conversion.c
@@ -197,7 +197,7 @@ typedef struct {
/// (default is uint32_t).
///
/// Stringifying a filter is done by processing a given number of options
-/// in oder from the beginning of an option_map array. The integer is
+/// in order from the beginning of an option_map array. The integer is
/// read from filter_options at .offset using the type from .type.
///
/// If the integer is zero and .flags has OPTMAP_NO_STRFY_ZERO then the
@@ -316,7 +316,7 @@ parse_lzma12_preset(const char **const str, const char *str_end,
assert(*str < str_end);
*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) {
switch (**str) {
case 'e':
@@ -466,9 +466,9 @@ static const struct {
/// If the flag LZMA_STR_ENCODER is used then the first
/// strfy_encoder elements of optmap are stringified.
/// With LZMA_STR_DECODER strfy_decoder is used.
- /// Currently encoders use all flags that decoders do but if
+ /// Currently encoders use all options that decoders do but if
/// that changes then this needs to be changed too, for example,
- /// add a new OPTMAP flag to skip printing some decoder-only flags.
+ /// add a new OPTMAP flag to skip printing some decoder-only options.
const option_map *optmap;
uint8_t strfy_encoder;
uint8_t strfy_decoder;
@@ -538,7 +538,7 @@ static const struct {
///
/// The input string starts at *str and the address in str_end is the first
/// char that is not part of the string anymore. So no '\0' terminator is
-/// used. *str is advanced everytime something has been decoded successfully.
+/// used. *str is advanced every time something has been decoded successfully.
static const char *
parse_options(const char **const str, const char *str_end,
void *filter_options,
@@ -667,7 +667,7 @@ parse_options(const char **const str, const char *str_end,
&& *p >= '0' && *p <= '9');
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
// specifically about the suffix. (Out of
// range values are about the whole value
@@ -844,7 +844,7 @@ parse_filter(const char **const str, const char *str_end, lzma_filter *filter,
/// Converts the string to a filter chain (array of lzma_filter structures).
///
-/// *str is advanced everytime something has been decoded successfully.
+/// *str is advanced every time something has been decoded successfully.
/// This way the caller knows where in the string a possible error occurred.
static const char *
str_to_filters(const char **const str, lzma_filter *filters, uint32_t flags,
@@ -1131,6 +1131,13 @@ lzma_str_from_filters(char **output_str, const lzma_filter *filters,
const char *opt_delim = (flags & LZMA_STR_GETOPT_LONG) ? "=" : ":";
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
// doesn't want them.
if (i > 0 && !(flags & LZMA_STR_NO_SPACES))