fix CVE-2020-8927

From: @jlwwlsqc
Reviewed-by: @hanxinke
Signed-off-by: @hanxinke
This commit is contained in:
openeuler-ci-bot 2020-10-19 19:06:40 +08:00 committed by wangjie
commit 94a23cac25
11 changed files with 15192 additions and 2 deletions

View File

@ -0,0 +1,182 @@
From ca21dac8e58177a5f6c7e8e177afd371aa66da0a Mon Sep 17 00:00:00 2001
From: Eugene Kliuchnikov <eustas.ru@gmail.com>
Date: Wed, 7 Aug 2019 10:51:55 +0200
Subject: [PATCH] Add an option to avoid building shared libraries. (#766)
Add an option to avoid building shared libraries (for building with EMCC)
Drive-by:
* maven: ramp up java level to minimal required
* travis: replace deprecated clang-5.0 with clang-7
* maven: fallback to jdk10 to void javadoc bug
---
.travis.yml | 33 ++++++++++++++++++---------------
CMakeLists.txt | 22 ++++++++++++++++------
java/org/brotli/pom.xml | 4 ++--
3 files changed, 36 insertions(+), 23 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index 5cfeafc..930bd63 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -44,27 +44,27 @@ matrix:
## Test that fuzzer is compiling / working.
###
- os: linux
- env: BUILD_SYSTEM=fuzz C_COMPILER=clang-5.0 CXX_COMPILER=clang++-5.0 ASAN_OPTIONS=detect_leaks=0
+ env: BUILD_SYSTEM=fuzz C_COMPILER=clang-7 CXX_COMPILER=clang++-7 ASAN_OPTIONS=detect_leaks=0
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- - llvm-toolchain-trusty-5.0
+ - llvm-toolchain-xenial-7
packages:
- - clang-5.0
+ - clang-7
###
## clang on Linux
###
- os: linux
- env: BUILD_SYSTEM=cmake C_COMPILER=clang-5.0 CXX_COMPILER=clang++-5.0
+ env: BUILD_SYSTEM=cmake C_COMPILER=clang-7 CXX_COMPILER=clang++-7
addons:
apt:
sources:
- - llvm-toolchain-trusty-5.0
+ - llvm-toolchain-xenial-7
- ubuntu-toolchain-r-test
packages:
- - clang-5.0
+ - clang-7
- os: linux
env: BUILD_SYSTEM=cmake C_COMPILER=clang-3.5 CXX_COMPILER=clang++-3.5
addons:
@@ -145,35 +145,38 @@ matrix:
## Sanitizers
###
- os: linux
- env: BUILD_SYSTEM=cmake C_COMPILER=clang-5.0 CXX_COMPILER=clang++-5.0 SANITIZER=address ASAN_OPTIONS=detect_leaks=0
+ env: BUILD_SYSTEM=cmake C_COMPILER=clang-7 CXX_COMPILER=clang++-7 SANITIZER=address ASAN_OPTIONS=detect_leaks=0
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- - llvm-toolchain-trusty-5.0
+ - llvm-toolchain-xenial-7
packages:
- - clang-5.0
+ - clang-7
- os: linux
- env: BUILD_SYSTEM=cmake C_COMPILER=clang-5.0 CXX_COMPILER=clang++-5.0 SANITIZER=thread
+ env: BUILD_SYSTEM=cmake C_COMPILER=clang-7 CXX_COMPILER=clang++-7 SANITIZER=thread
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- - llvm-toolchain-trusty-5.0
+ - llvm-toolchain-xenial-7
packages:
- - clang-5.0
+ - clang-7
- os: linux
- env: BUILD_SYSTEM=cmake C_COMPILER=clang-5.0 CXX_COMPILER=clang++-5.0 SANITIZER=undefined CFLAGS="-fno-sanitize-recover=undefined,integer"
+ env: BUILD_SYSTEM=cmake C_COMPILER=clang-7 CXX_COMPILER=clang++-7 SANITIZER=undefined CFLAGS="-fno-sanitize-recover=undefined,integer"
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- - llvm-toolchain-trusty-5.0
+ - llvm-toolchain-xenial-7
packages:
- - clang-5.0
+ - clang-7
- os: linux
env: BUILD_SYSTEM=maven
+ jdk:
+ # maven + jdk11 + javadoc == trouble
+ - openjdk10
language: java
- os: linux
diff --git a/CMakeLists.txt b/CMakeLists.txt
index fc45f80..3427802 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,6 +6,8 @@ cmake_minimum_required(VERSION 2.8.6)
project(brotli C)
+option(BROTLI_DISABLE_SHARED "do not build shared libraries")
+
# If Brotli is being bundled in another project, we don't want to
# install anything. However, we want to let people override this, so
# we'll use the BROTLI_BUNDLED_MODE variable to let them do that; just
@@ -137,10 +139,16 @@ endfunction()
transform_sources_list("scripts/sources.lst" "${CMAKE_CURRENT_BINARY_DIR}/sources.lst.cmake")
include("${CMAKE_CURRENT_BINARY_DIR}/sources.lst.cmake")
-add_library(brotlicommon SHARED ${BROTLI_COMMON_C})
-add_library(brotlidec SHARED ${BROTLI_DEC_C})
-add_library(brotlienc SHARED ${BROTLI_ENC_C})
+if(BROTLI_DISABLE_SHARED)
+ set(BROTLI_SHARED_LIBS "")
+else()
+ set(BROTLI_SHARED_LIBS brotlicommon brotlidec brotlienc)
+ add_library(brotlicommon SHARED ${BROTLI_COMMON_C})
+ add_library(brotlidec SHARED ${BROTLI_DEC_C})
+ add_library(brotlienc SHARED ${BROTLI_ENC_C})
+endif()
+set(BROTLI_STATIC_LIBS brotlicommon-static brotlidec-static brotlienc-static)
add_library(brotlicommon-static STATIC ${BROTLI_COMMON_C})
add_library(brotlidec-static STATIC ${BROTLI_DEC_C})
add_library(brotlienc-static STATIC ${BROTLI_ENC_C})
@@ -148,13 +156,13 @@ add_library(brotlienc-static STATIC ${BROTLI_ENC_C})
# Older CMake versions does not understand INCLUDE_DIRECTORIES property.
include_directories(${BROTLI_INCLUDE_DIRS})
-foreach(lib brotlicommon brotlidec brotlienc)
+foreach(lib IN LISTS BROTLI_SHARED_LIBS)
target_compile_definitions(${lib} PUBLIC "BROTLI_SHARED_COMPILATION" )
string(TOUPPER "${lib}" LIB)
- set_target_properties (${lib} PROPERTIES DEFINE_SYMBOL "${LIB}_SHARED_COMPILATION" )
+ set_target_properties (${lib} PROPERTIES DEFINE_SYMBOL "${LIB}_SHARED_COMPILATION")
endforeach()
-foreach(lib brotlicommon brotlidec brotlienc brotlicommon-static brotlidec-static brotlienc-static)
+foreach(lib IN LISTS BROTLI_SHARED_LIBS BROTLI_STATIC_LIBS)
target_link_libraries(${lib} ${LIBM_LIBRARY})
set_property(TARGET ${lib} APPEND PROPERTY INCLUDE_DIRECTORIES ${BROTLI_INCLUDE_DIRS})
set_target_properties(${lib} PROPERTIES
@@ -164,8 +172,10 @@ foreach(lib brotlicommon brotlidec brotlienc brotlicommon-static brotlidec-stati
set_property(TARGET ${lib} APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${BROTLI_INCLUDE_DIRS}")
endforeach()
+if(NOT BROTLI_DISABLE_SHARED)
target_link_libraries(brotlidec brotlicommon)
target_link_libraries(brotlienc brotlicommon)
+endif()
target_link_libraries(brotlidec-static brotlicommon-static)
target_link_libraries(brotlienc-static brotlicommon-static)
diff --git a/java/org/brotli/pom.xml b/java/org/brotli/pom.xml
index bb4a5a3..9a7abd0 100644
--- a/java/org/brotli/pom.xml
+++ b/java/org/brotli/pom.xml
@@ -80,8 +80,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
- <source>1.5</source>
- <target>1.5</target>
+ <source>1.6</source>
+ <target>1.6</target>
</configuration>
</plugin>
<plugin>
--
2.6.1.windows.1

View File

@ -0,0 +1,76 @@
From 4b5771bee7995d3d606221caa455c044d80434df Mon Sep 17 00:00:00 2001
From: agrieve <agrieve@chromium.org>
Date: Thu, 19 Dec 2019 18:15:58 -0500
Subject: [PATCH] Add missing "const" to a couple of kConstants (#780)
These showed up in a Chromium audit:
https://bugs.chromium.org/p/chromium/issues/detail?id=747064#c8
Although already effectively const, adding "const" causes the symbols to
be moved into the read-only section of the binary.
---
c/common/dictionary.c | 11 ++++++++++-
c/common/transform.c | 2 +-
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/c/common/dictionary.c b/c/common/dictionary.c
index 64822a3..f9e3041 100644
--- a/c/common/dictionary.c
+++ b/c/common/dictionary.c
@@ -5,12 +5,13 @@
*/
#include "./dictionary.h"
+#include "./platform.h"
#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif
-#ifndef BROTLI_EXTERNAL_DICTIONARY_DATA
+#if !defined(BROTLI_EXTERNAL_DICTIONARY_DATA)
static const uint8_t kBrotliDictionaryData[] =
{
116,105,109,101,100,111,119,110,108,105,102,101,108,101,102,116,98,97,99,107,99,
@@ -5862,7 +5863,11 @@ static const uint8_t kBrotliDictionaryData[] =
;
#endif /* !BROTLI_EXTERNAL_DICTIONARY_DATA */
+#if !defined(BROTLI_EXTERNAL_DICTIONARY_DATA)
+static const BrotliDictionary kBrotliDictionary = {
+#else
static BrotliDictionary kBrotliDictionary = {
+#endif
/* size_bits_by_length */
{
0, 0, 0, 0, 10, 10, 11, 11,
@@ -5895,9 +5900,13 @@ const BrotliDictionary* BrotliGetDictionary() {
}
void BrotliSetDictionaryData(const uint8_t* data) {
+#if defined(BROTLI_EXTERNAL_DICTIONARY_DATA)
if (!!data && !kBrotliDictionary.data) {
kBrotliDictionary.data = data;
}
+#else
+ BROTLI_UNUSED(data); // Appease -Werror=unused-parameter
+#endif
}
#if defined(__cplusplus) || defined(c_plusplus)
diff --git a/c/common/transform.c b/c/common/transform.c
index c44f671..f8fa433 100755
--- a/c/common/transform.c
+++ b/c/common/transform.c
@@ -160,7 +160,7 @@ static const uint8_t kTransformsData[] = {
0, BROTLI_TRANSFORM_UPPERCASE_FIRST, 34,
};
-static BrotliTransforms kBrotliTransforms = {
+static const BrotliTransforms kBrotliTransforms = {
sizeof(kPrefixSuffix),
(const uint8_t*)kPrefixSuffix,
kPrefixSuffixMap,
--
2.6.1.windows.1

1197
CVE-2020-8927.patch Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,99 @@
From 35ef5c554d888bef217d449346067de05e269b30 Mon Sep 17 00:00:00 2001
From: Eugene Kliuchnikov <eustas.ru@gmail.com>
Date: Tue, 13 Aug 2019 15:23:04 +0200
Subject: [PATCH] Disable PIC in EMCC mode. (#768)
---
CMakeLists.txt | 31 ++++++++++++++++++++++++-------
1 file changed, 24 insertions(+), 7 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3427802..a8ea872 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,7 +6,18 @@ cmake_minimum_required(VERSION 2.8.6)
project(brotli C)
-option(BROTLI_DISABLE_SHARED "do not build shared libraries")
+include(CheckCSourceCompiles)
+check_c_source_compiles(
+ "#if defined(__EMSCRIPTEN__)
+ int main() {return 0;}
+ #endif"
+ BROTLI_EMSCRIPTEN
+)
+if (BROTLI_EMSCRIPTEN)
+ message("-- Compiler is EMSCRIPTEN")
+else()
+ message("-- Compiler is not EMSCRIPTEN")
+endif()
# If Brotli is being bundled in another project, we don't want to
# install anything. However, we want to let people override this, so
@@ -139,7 +150,7 @@ endfunction()
transform_sources_list("scripts/sources.lst" "${CMAKE_CURRENT_BINARY_DIR}/sources.lst.cmake")
include("${CMAKE_CURRENT_BINARY_DIR}/sources.lst.cmake")
-if(BROTLI_DISABLE_SHARED)
+if(BROTLI_EMSCRIPTEN)
set(BROTLI_SHARED_LIBS "")
else()
set(BROTLI_SHARED_LIBS brotlicommon brotlidec brotlienc)
@@ -167,12 +178,14 @@ foreach(lib IN LISTS BROTLI_SHARED_LIBS BROTLI_STATIC_LIBS)
set_property(TARGET ${lib} APPEND PROPERTY INCLUDE_DIRECTORIES ${BROTLI_INCLUDE_DIRS})
set_target_properties(${lib} PROPERTIES
VERSION "${BROTLI_ABI_COMPATIBILITY}.${BROTLI_ABI_AGE}.${BROTLI_ABI_REVISION}"
- SOVERSION "${BROTLI_ABI_COMPATIBILITY}"
- POSITION_INDEPENDENT_CODE TRUE)
+ SOVERSION "${BROTLI_ABI_COMPATIBILITY}")
+ if(NOT BROTLI_EMSCRIPTEN)
+ set_target_properties(${lib} PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
+ endif()
set_property(TARGET ${lib} APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${BROTLI_INCLUDE_DIRS}")
endforeach()
-if(NOT BROTLI_DISABLE_SHARED)
+if(NOT BROTLI_EMSCRIPTEN)
target_link_libraries(brotlidec brotlicommon)
target_link_libraries(brotlienc brotlicommon)
endif()
@@ -196,6 +209,7 @@ add_executable(brotli ${BROTLI_CLI_C})
target_link_libraries(brotli ${BROTLI_LIBRARIES_STATIC})
# Installation
+if(NOT BROTLI_EMSCRIPTEN)
if(NOT BROTLI_BUNDLED_MODE)
install(
TARGETS brotli
@@ -220,7 +234,8 @@ if(NOT BROTLI_BUNDLED_MODE)
DIRECTORY ${BROTLI_INCLUDE_DIRS}/brotli
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
-endif()
+endif() # BROTLI_BUNDLED_MODE
+endif() # BROTLI_EMSCRIPTEN
# Tests
@@ -376,6 +391,7 @@ transform_pc_file("scripts/libbrotlidec.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/libb
transform_pc_file("scripts/libbrotlienc.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/libbrotlienc.pc" "${BROTLI_VERSION}")
+if(NOT BROTLI_EMSCRIPTEN)
if(NOT BROTLI_BUNDLED_MODE)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libbrotlicommon.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
@@ -383,7 +399,8 @@ if(NOT BROTLI_BUNDLED_MODE)
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libbrotlienc.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
-endif()
+endif() # BROTLI_BUNDLED_MODE
+endif() # BROTLI_EMSCRIPTEN
if (ENABLE_COVERAGE STREQUAL "yes")
SETUP_TARGET_FOR_COVERAGE(coverage test coverage)
--
2.6.1.windows.1

View File

@ -0,0 +1,76 @@
From 5805f99a533a8f8118699c0100d8c102f3605f65 Mon Sep 17 00:00:00 2001
From: Justin Ridgewell <justin@ridgewell.name>
Date: Mon, 12 Nov 2018 04:36:00 -0500
Subject: [PATCH] Ensure decompression consumes all input (#730)
* Ensure decompression consumes all input
If not, it's a corrupt stream.
* Use byte strings
---
python/_brotli.cc | 4 ++--
python/tests/decompress_test.py | 4 ++++
python/tests/decompressor_test.py | 9 +++++++++
3 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/python/_brotli.cc b/python/_brotli.cc
index a6f925e..5e1828e 100644
--- a/python/_brotli.cc
+++ b/python/_brotli.cc
@@ -414,7 +414,7 @@ static BROTLI_BOOL decompress_stream(BrotliDecoderState* dec,
(*output).insert((*output).end(), buffer, buffer + buffer_length);
}
}
- ok = result != BROTLI_DECODER_RESULT_ERROR;
+ ok = result != BROTLI_DECODER_RESULT_ERROR && !available_in;
Py_END_ALLOW_THREADS
return ok;
@@ -672,7 +672,7 @@ static PyObject* brotli_decompress(PyObject *self, PyObject *args, PyObject *key
if (available_out != 0)
output.insert(output.end(), next_out, next_out + available_out);
}
- ok = result == BROTLI_DECODER_RESULT_SUCCESS;
+ ok = result == BROTLI_DECODER_RESULT_SUCCESS && !available_in;
BrotliDecoderDestroyInstance(state);
Py_END_ALLOW_THREADS
diff --git a/python/tests/decompress_test.py b/python/tests/decompress_test.py
index 7a9e9e3..814e563 100644
--- a/python/tests/decompress_test.py
+++ b/python/tests/decompress_test.py
@@ -31,6 +31,10 @@ class TestDecompress(_test_utils.TestCase):
self._decompress(test_data)
self._check_decompression(test_data)
+ def test_garbage_appended(self):
+ with self.assertRaises(brotli.error):
+ brotli.decompress(brotli.compress(b'a') + b'a')
+
_test_utils.generate_test_methods(TestDecompress, for_decompression=True)
diff --git a/python/tests/decompressor_test.py b/python/tests/decompressor_test.py
index 99667bc..05918ad 100644
--- a/python/tests/decompressor_test.py
+++ b/python/tests/decompressor_test.py
@@ -43,6 +43,15 @@ class TestDecompressor(_test_utils.TestCase):
self._decompress(test_data)
self._check_decompression(test_data)
+ def test_garbage_appended(self):
+ with self.assertRaises(brotli.error):
+ self.decompressor.process(brotli.compress(b'a') + b'a')
+
+ def test_already_finished(self):
+ self.decompressor.process(brotli.compress(b'a'))
+ with self.assertRaises(brotli.error):
+ self.decompressor.process(b'a')
+
_test_utils.generate_test_methods(TestDecompressor, for_decompression=True)
--
2.6.1.windows.1

View File

@ -0,0 +1,25 @@
From 3d1767186da60c29086f61be24f8292876afa871 Mon Sep 17 00:00:00 2001
From: Eugene Kliuchnikov <eustas.ru@gmail.com>
Date: Tue, 30 Jul 2019 10:01:21 +0200
Subject: [PATCH] Fix include for EMCC build (#765)
---
c/common/platform.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/c/common/platform.h b/c/common/platform.h
index b6d634e..2633e04 100755
--- a/c/common/platform.h
+++ b/c/common/platform.h
@@ -29,7 +29,7 @@
#include <brotli/port.h>
#include <brotli/types.h>
-#if defined(OS_LINUX) || defined(OS_CYGWIN)
+#if defined(OS_LINUX) || defined(OS_CYGWIN) || defined(__EMSCRIPTEN__)
#include <endian.h>
#elif defined(OS_FREEBSD)
#include <machine/endian.h>
--
2.6.1.windows.1

View File

@ -0,0 +1,107 @@
From 924b2b2b9dc54005edbcd85a1b872330948cdd9e Mon Sep 17 00:00:00 2001
From: Clinton Ingram <clinton.ingram@outlook.com>
Date: Thu, 19 Mar 2020 03:57:56 -0700
Subject: [PATCH] Move TZCNT and BSR intrinsics to platform.h, add MSVC
versions (#636)
---
c/common/platform.h | 34 ++++++++++++++++++++++++++++++++++
c/enc/fast_log.h | 6 ++----
c/enc/find_match_length.h | 5 ++---
3 files changed, 38 insertions(+), 7 deletions(-)
diff --git a/c/common/platform.h b/c/common/platform.h
index 2633e04..ca79359 100755
--- a/c/common/platform.h
+++ b/c/common/platform.h
@@ -41,6 +41,10 @@
#define BROTLI_X_BIG_ENDIAN BIG_ENDIAN
#endif
+#if BROTLI_MSVC_VERSION_CHECK(12, 0, 0)
+#include <intrin.h>
+#endif
+
#if defined(BROTLI_ENABLE_LOG) || defined(BROTLI_DEBUG)
#include <assert.h>
#include <stdio.h>
@@ -522,6 +526,36 @@ BROTLI_MIN_MAX(size_t) BROTLI_MIN_MAX(uint32_t) BROTLI_MIN_MAX(uint8_t)
(A)[(J)] = __brotli_swap_tmp; \
}
+#if BROTLI_64_BITS
+#if BROTLI_GNUC_HAS_BUILTIN(__builtin_ctzll, 3, 4, 0) || \
+ BROTLI_INTEL_VERSION_CHECK(16, 0, 0)
+#define BROTLI_TZCNT64 __builtin_ctzll
+#elif BROTLI_MSVC_VERSION_CHECK(12, 0, 0)
+#if defined(BROTLI_TARGET_X64)
+#define BROTLI_TZCNT64 _tzcnt_u64
+#else /* BROTLI_TARGET_X64 */
+static BROTLI_INLINE uint32_t BrotliBsf64Msvc(uint64_t x) {
+ uint32_t lsb;
+ _BitScanForward64(&lsb, x);
+ return lsb;
+}
+#define BROTLI_TZCNT64 BrotliBsf64Msvc
+#endif /* BROTLI_TARGET_X64 */
+#endif /* __builtin_ctzll */
+#endif /* BROTLI_64_BITS */
+
+#if BROTLI_GNUC_HAS_BUILTIN(__builtin_clz, 3, 4, 0) || \
+ BROTLI_INTEL_VERSION_CHECK(16, 0, 0)
+#define BROTLI_BSR32(x) (31u ^ (uint32_t)__builtin_clz(x))
+#elif BROTLI_MSVC_VERSION_CHECK(12, 0, 0)
+static BROTLI_INLINE uint32_t BrotliBsr32Msvc(uint32_t x) {
+ uint32_t msb;
+ _BitScanReverse(&msb, x);
+ return msb;
+}
+#define BROTLI_BSR32 BrotliBsr32Msvc
+#endif /* __builtin_clz */
+
/* Default brotli_alloc_func */
static void* BrotliDefaultAllocFunc(void* opaque, size_t size) {
BROTLI_UNUSED(opaque);
diff --git a/c/enc/fast_log.h b/c/enc/fast_log.h
index b1268e0..eca58e8 100644
--- a/c/enc/fast_log.h
+++ b/c/enc/fast_log.h
@@ -19,10 +19,8 @@ extern "C" {
#endif
static BROTLI_INLINE uint32_t Log2FloorNonZero(size_t n) {
- /* TODO: generalize and move to platform.h */
-#if BROTLI_GNUC_HAS_BUILTIN(__builtin_clz, 3, 4, 0) || \
- BROTLI_INTEL_VERSION_CHECK(16, 0, 0)
- return 31u ^ (uint32_t)__builtin_clz((uint32_t)n);
+#if defined(BROTLI_BSR32)
+ return BROTLI_BSR32((uint32_t)n);
#else
uint32_t result = 0;
while (n >>= 1) result++;
diff --git a/c/enc/find_match_length.h b/c/enc/find_match_length.h
index bc428cf..f8853a7 100644
--- a/c/enc/find_match_length.h
+++ b/c/enc/find_match_length.h
@@ -17,8 +17,7 @@ extern "C" {
#endif
/* Separate implementation for little-endian 64-bit targets, for speed. */
-#if defined(__GNUC__) && defined(_LP64) && defined(BROTLI_LITTLE_ENDIAN)
-
+#if defined(BROTLI_TZCNT64) && BROTLI_64_BITS && BROTLI_LITTLE_ENDIAN
static BROTLI_INLINE size_t FindMatchLengthWithLimit(const uint8_t* s1,
const uint8_t* s2,
size_t limit) {
@@ -32,7 +31,7 @@ static BROTLI_INLINE size_t FindMatchLengthWithLimit(const uint8_t* s1,
} else {
uint64_t x = BROTLI_UNALIGNED_LOAD64LE(s2) ^
BROTLI_UNALIGNED_LOAD64LE(s1 + matched);
- size_t matching_bits = (size_t)__builtin_ctzll(x);
+ size_t matching_bits = (size_t)BROTLI_TZCNT64(x);
matched += matching_bits >> 3;
return matched;
}
--
2.6.1.windows.1

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
Name: brotli
Version: 1.0.7
Release: 1
Release: 3
Summary: Lossless compression algorithm
License: MIT
@ -9,6 +9,17 @@ Source0: https://github.com/google/brotli/archive/v%{version}.tar.gz
BuildRequires: python2-devel python3-devel gcc-c++ gcc cmake
Patch6000: Verbose-CLI-start-pulling-Shared-Brotli.patch
Patch6001: Ensure-decompression-consumes-all-input.patch
Patch6002: fix-MSVC-configuration-and-c++-compilation-fails.patch
Patch6003: fix-executable-mode-of-decode-js.patch
Patch6004: Fix-include-for-EMCC-build.patch
Patch6005: Add-an-option-to-avoid-building-shared-libraries.patch
Patch6006: Disable-PIC-in-EMCC-mode.patch
Patch6007: Add-missing-const-to-a-couple-of-kConstants.patch
Patch6008: Move-TZCNT-and-BSR-intrinsics-and-add-MSVC-versions.patch
Patch6009: CVE-2020-8927.patch
%description
Brotli is a generic-purpose lossless compression algorithm that compresses
data using a combination of a modern variant of the LZ77 algorithm, Huffman
@ -42,7 +53,7 @@ This package installs the development files
%package_help
%prep
%autosetup -n %{name}-%{version}
%autosetup -n %{name}-%{version} -p1
%{__chmod} 644 c/enc/*.[ch]
%{__chmod} 644 c/include/brotli/*.h
@ -103,6 +114,27 @@ popd
%{_mandir}/man3/*
%changelog
* Mon Oct 19 2020 wangjie<wangjie294@huawei.com> -1.0.7-3
- Type:CVE
- CVE:CVE-2020-8927
- SUG:NA
- DESC:fix CVE-2020-8927
* Mon Oct 19 2020 wangjie<wangjie294@huawei.com> -1.0.7-2
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:Synchronize patches from community
Verbose-CLI-start-pulling-Shared-Brotli.patch
Ensure-decompression-consumes-all-input.patch
fix-MSVC-configuration-and-c++-compilation-fails.patch
fix-executable-mode-of-decode-js.patch
Fix-include-for-EMCC-build.patch
Add-an-option-to-avoid-building-shared-libraries.patch
Disable-PIC-in-EMCC-mode.patch
Add-missing-const-to-a-couple-of-kConstants.patch
Move-TZCNT-and-BSR-intrinsics-and-add-MSVC-versions.patch
* Thu Apr 16 2020 chengquan<chengquan3@huawei.com> -1.0.7-1
- Type:enhancement
- ID:NA

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,623 @@
From 78e7bbc3c34bb85ecc9a912929e8b3b224973b05 Mon Sep 17 00:00:00 2001
From: Eugene Kliuchnikov <eustas@google.com>
Date: Fri, 3 May 2019 11:51:11 +0200
Subject: [PATCH] Update (#753)
* fix executable mode of decode.js
* explain clang-analyser about non-nullability
* fix "dead assignment"
* rename proguard.cfg -> proguard.pgcfg
---
c/dec/decode.c | 3 ++-
c/enc/backward_references_hq.c | 12 +++++++-----
c/enc/block_splitter.c | 6 +++---
c/enc/block_splitter_inc.h | 21 ++++++++++++++------
c/enc/brotli_bit_stream.c | 8 ++++----
c/enc/cluster_inc.h | 9 ++++++---
c/enc/encode.c | 31 ++++++++++++++++++-----------
c/enc/hash.h | 2 +-
c/enc/hash_longest_match_quickly_inc.h | 14 ++++++-------
c/enc/hash_rolling_inc.h | 2 +-
c/enc/memory.h | 36 ++++++++++++++++++++++------------
c/enc/metablock.c | 22 ++++++++++-----------
c/enc/metablock_inc.h | 2 +-
c/enc/ringbuffer.h | 2 +-
java/org/brotli/dec/BUILD | 2 +-
java/org/brotli/dec/proguard.cfg | 6 ------
java/org/brotli/dec/proguard.pgcfg | 6 ++++++
js/decode.js | 0
18 files changed, 110 insertions(+), 74 deletions(-)
delete mode 100644 java/org/brotli/dec/proguard.cfg
create mode 100644 java/org/brotli/dec/proguard.pgcfg
mode change 100755 => 100644 js/decode.js
diff --git a/c/dec/decode.c b/c/dec/decode.c
index bde4795..9c10f50 100644
--- a/c/dec/decode.c
+++ b/c/dec/decode.c
@@ -41,7 +41,8 @@ extern "C" {
/* We need the slack region for the following reasons:
- doing up to two 16-byte copies for fast backward copying
- - inserting transformed dictionary word (5 prefix + 24 base + 8 suffix) */
+ - inserting transformed dictionary word:
+ 5 prefix + 24 base + 8 suffix */
static const uint32_t kRingBufferWriteAheadSlack = 42;
static const uint8_t kCodeLengthCodeOrder[BROTLI_CODE_LENGTH_CODES] = {
diff --git a/c/enc/backward_references_hq.c b/c/enc/backward_references_hq.c
index cd6bb70..c42744b 100644
--- a/c/enc/backward_references_hq.c
+++ b/c/enc/backward_references_hq.c
@@ -724,9 +724,8 @@ void BrotliCreateZopfliBackwardReferences(MemoryManager* m, size_t num_bytes,
ContextLut literal_context_lut, const BrotliEncoderParams* params,
Hasher* hasher, int* dist_cache, size_t* last_insert_len,
Command* commands, size_t* num_commands, size_t* num_literals) {
- ZopfliNode* nodes;
- nodes = BROTLI_ALLOC(m, ZopfliNode, num_bytes + 1);
- if (BROTLI_IS_OOM(m)) return;
+ ZopfliNode* nodes = BROTLI_ALLOC(m, ZopfliNode, num_bytes + 1);
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(nodes)) return;
BrotliInitZopfliNodes(nodes, num_bytes + 1);
*num_commands += BrotliZopfliComputeShortestPath(m, num_bytes,
position, ringbuffer, ringbuffer_mask, literal_context_lut, params,
@@ -760,7 +759,10 @@ void BrotliCreateHqZopfliBackwardReferences(MemoryManager* m, size_t num_bytes,
BROTLI_UNUSED(literal_context_lut);
size_t gap = 0;
size_t shadow_matches = 0;
- if (BROTLI_IS_OOM(m)) return;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(num_matches) ||
+ BROTLI_IS_NULL(matches)) {
+ return;
+ }
for (i = 0; i + HashTypeLengthH10() - 1 < num_bytes; ++i) {
const size_t pos = position + i;
size_t max_distance = BROTLI_MIN(size_t, pos, max_backward_limit);
@@ -807,7 +809,7 @@ void BrotliCreateHqZopfliBackwardReferences(MemoryManager* m, size_t num_bytes,
memcpy(orig_dist_cache, dist_cache, 4 * sizeof(dist_cache[0]));
orig_num_commands = *num_commands;
nodes = BROTLI_ALLOC(m, ZopfliNode, num_bytes + 1);
- if (BROTLI_IS_OOM(m)) return;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(nodes)) return;
InitZopfliCostModel(m, &model, &params->dist, num_bytes);
if (BROTLI_IS_OOM(m)) return;
for (i = 0; i < 2; i++) {
diff --git a/c/enc/block_splitter.c b/c/enc/block_splitter.c
index d308eca..deb7c2e 100644
--- a/c/enc/block_splitter.c
+++ b/c/enc/block_splitter.c
@@ -132,7 +132,7 @@ void BrotliSplitBlock(MemoryManager* m,
{
size_t literals_count = CountLiterals(cmds, num_commands);
uint8_t* literals = BROTLI_ALLOC(m, uint8_t, literals_count);
- if (BROTLI_IS_OOM(m)) return;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(literals)) return;
/* Create a continuous array of literals. */
CopyLiteralsToByteArray(cmds, num_commands, data, pos, mask, literals);
/* Create the block split on the array of literals.
@@ -150,7 +150,7 @@ void BrotliSplitBlock(MemoryManager* m,
/* Compute prefix codes for commands. */
uint16_t* insert_and_copy_codes = BROTLI_ALLOC(m, uint16_t, num_commands);
size_t i;
- if (BROTLI_IS_OOM(m)) return;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(insert_and_copy_codes)) return;
for (i = 0; i < num_commands; ++i) {
insert_and_copy_codes[i] = cmds[i].cmd_prefix_;
}
@@ -170,7 +170,7 @@ void BrotliSplitBlock(MemoryManager* m,
uint16_t* distance_prefixes = BROTLI_ALLOC(m, uint16_t, num_commands);
size_t j = 0;
size_t i;
- if (BROTLI_IS_OOM(m)) return;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(distance_prefixes)) return;
for (i = 0; i < num_commands; ++i) {
const Command* cmd = &cmds[i];
if (CommandCopyLen(cmd) && cmd->cmd_prefix_ >= 128) {
diff --git a/c/enc/block_splitter_inc.h b/c/enc/block_splitter_inc.h
index 023712b..e612d6a 100644
--- a/c/enc/block_splitter_inc.h
+++ b/c/enc/block_splitter_inc.h
@@ -219,7 +219,12 @@ static void FN(ClusterBlocks)(MemoryManager* m,
uint32_t symbols[HISTOGRAMS_PER_BATCH] = { 0 };
uint32_t remap[HISTOGRAMS_PER_BATCH] = { 0 };
- if (BROTLI_IS_OOM(m)) return;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(histogram_symbols) ||
+ BROTLI_IS_NULL(block_lengths) || BROTLI_IS_NULL(all_histograms) ||
+ BROTLI_IS_NULL(cluster_size) || BROTLI_IS_NULL(histograms) ||
+ BROTLI_IS_NULL(pairs)) {
+ return;
+ }
memset(block_lengths, 0, num_blocks * sizeof(uint32_t));
@@ -278,11 +283,11 @@ static void FN(ClusterBlocks)(MemoryManager* m,
if (pairs_capacity < max_num_pairs + 1) {
BROTLI_FREE(m, pairs);
pairs = BROTLI_ALLOC(m, HistogramPair, max_num_pairs + 1);
- if (BROTLI_IS_OOM(m)) return;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(pairs)) return;
}
clusters = BROTLI_ALLOC(m, uint32_t, num_clusters);
- if (BROTLI_IS_OOM(m)) return;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(clusters)) return;
for (i = 0; i < num_clusters; ++i) {
clusters[i] = (uint32_t)i;
}
@@ -294,7 +299,7 @@ static void FN(ClusterBlocks)(MemoryManager* m,
BROTLI_FREE(m, cluster_size);
new_index = BROTLI_ALLOC(m, uint32_t, num_clusters);
- if (BROTLI_IS_OOM(m)) return;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(new_index)) return;
for (i = 0; i < num_clusters; ++i) new_index[i] = kInvalidIndex;
pos = 0;
{
@@ -386,7 +391,7 @@ static void FN(SplitByteVector)(MemoryManager* m,
return;
}
histograms = BROTLI_ALLOC(m, HistogramType, num_histograms);
- if (BROTLI_IS_OOM(m)) return;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(histograms)) return;
/* Find good entropy codes. */
FN(InitialEntropyCodes)(data, length,
sampling_stride_length,
@@ -405,7 +410,11 @@ static void FN(SplitByteVector)(MemoryManager* m,
uint16_t* new_id = BROTLI_ALLOC(m, uint16_t, num_histograms);
const size_t iters = params->quality < HQ_ZOPFLIFICATION_QUALITY ? 3 : 10;
size_t i;
- if (BROTLI_IS_OOM(m)) return;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(block_ids) ||
+ BROTLI_IS_NULL(insert_cost) || BROTLI_IS_NULL(cost) ||
+ BROTLI_IS_NULL(switch_signal) || BROTLI_IS_NULL(new_id)) {
+ return;
+ }
for (i = 0; i < iters; ++i) {
num_blocks = FN(FindBlocks)(data, length,
block_switch_cost,
diff --git a/c/enc/brotli_bit_stream.c b/c/enc/brotli_bit_stream.c
index 84b36ae..6391454 100644
--- a/c/enc/brotli_bit_stream.c
+++ b/c/enc/brotli_bit_stream.c
@@ -450,7 +450,7 @@ void BrotliBuildAndStoreHuffmanTreeFast(MemoryManager* m,
const size_t max_tree_size = 2 * length + 1;
HuffmanTree* tree = BROTLI_ALLOC(m, HuffmanTree, max_tree_size);
uint32_t count_limit;
- if (BROTLI_IS_OOM(m)) return;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(tree)) return;
for (count_limit = 1; ; count_limit *= 2) {
HuffmanTree* node = tree;
size_t l;
@@ -714,7 +714,7 @@ static void EncodeContextMap(MemoryManager* m,
}
rle_symbols = BROTLI_ALLOC(m, uint32_t, context_map_size);
- if (BROTLI_IS_OOM(m)) return;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(rle_symbols)) return;
MoveToFrontTransform(context_map, context_map_size, rle_symbols);
RunLengthCodeZeros(context_map_size, rle_symbols,
&num_rle_symbols, &max_run_length_prefix);
@@ -970,7 +970,7 @@ void BrotliStoreMetaBlock(MemoryManager* m,
StoreCompressedMetaBlockHeader(is_last, length, storage_ix, storage);
tree = BROTLI_ALLOC(m, HuffmanTree, MAX_HUFFMAN_TREE_SIZE);
- if (BROTLI_IS_OOM(m)) return;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(tree)) return;
InitBlockEncoder(&literal_enc, BROTLI_NUM_LITERAL_SYMBOLS,
mb->literal_split.num_types, mb->literal_split.types,
mb->literal_split.lengths, mb->literal_split.num_blocks);
@@ -1175,7 +1175,7 @@ void BrotliStoreMetaBlockTrivial(MemoryManager* m,
BrotliWriteBits(13, 0, storage_ix, storage);
tree = BROTLI_ALLOC(m, HuffmanTree, MAX_HUFFMAN_TREE_SIZE);
- if (BROTLI_IS_OOM(m)) return;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(tree)) return;
BuildAndStoreHuffmanTree(lit_histo.data_, BROTLI_NUM_LITERAL_SYMBOLS,
BROTLI_NUM_LITERAL_SYMBOLS, tree,
lit_depth, lit_bits,
diff --git a/c/enc/cluster_inc.h b/c/enc/cluster_inc.h
index 22ecb3c..3d4f40e 100644
--- a/c/enc/cluster_inc.h
+++ b/c/enc/cluster_inc.h
@@ -215,7 +215,7 @@ BROTLI_INTERNAL size_t FN(BrotliHistogramReindex)(MemoryManager* m,
uint32_t next_index;
HistogramType* tmp;
size_t i;
- if (BROTLI_IS_OOM(m)) return 0;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(new_index)) return 0;
for (i = 0; i < length; ++i) {
new_index[i] = kInvalidIndex;
}
@@ -229,7 +229,7 @@ BROTLI_INTERNAL size_t FN(BrotliHistogramReindex)(MemoryManager* m,
/* TODO: by using idea of "cycle-sort" we can avoid allocation of
tmp and reduce the number of copying by the factor of 2. */
tmp = BROTLI_ALLOC(m, HistogramType, next_index);
- if (BROTLI_IS_OOM(m)) return 0;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(tmp)) return 0;
next_index = 0;
for (i = 0; i < length; ++i) {
if (new_index[symbols[i]] == next_index) {
@@ -259,7 +259,10 @@ BROTLI_INTERNAL void FN(BrotliClusterHistograms)(
HistogramPair* pairs = BROTLI_ALLOC(m, HistogramPair, pairs_capacity + 1);
size_t i;
- if (BROTLI_IS_OOM(m)) return;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(cluster_size) ||
+ BROTLI_IS_NULL(clusters) || BROTLI_IS_NULL(pairs)) {
+ return;
+ }
for (i = 0; i < in_size; ++i) {
cluster_size[i] = 1;
diff --git a/c/enc/encode.c b/c/enc/encode.c
index 3319b39..68548ef 100644
--- a/c/enc/encode.c
+++ b/c/enc/encode.c
@@ -212,7 +212,7 @@ static uint8_t* GetBrotliStorage(BrotliEncoderState* s, size_t size) {
if (s->storage_size_ < size) {
BROTLI_FREE(m, s->storage_);
s->storage_ = BROTLI_ALLOC(m, uint8_t, size);
- if (BROTLI_IS_OOM(m)) return NULL;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(s->storage_)) return NULL;
s->storage_size_ = size;
}
return s->storage_;
@@ -251,7 +251,7 @@ static int* GetHashTable(BrotliEncoderState* s, int quality,
s->large_table_size_ = htsize;
BROTLI_FREE(m, s->large_table_);
s->large_table_ = BROTLI_ALLOC(m, int, htsize);
- if (BROTLI_IS_OOM(m)) return 0;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(s->large_table_)) return 0;
}
table = s->large_table_;
}
@@ -985,7 +985,10 @@ static BROTLI_BOOL EncodeData(
BROTLI_ALLOC(m, uint32_t, kCompressFragmentTwoPassBlockSize);
s->literal_buf_ =
BROTLI_ALLOC(m, uint8_t, kCompressFragmentTwoPassBlockSize);
- if (BROTLI_IS_OOM(m)) return BROTLI_FALSE;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(s->command_buf_) ||
+ BROTLI_IS_NULL(s->literal_buf_)) {
+ return BROTLI_FALSE;
+ }
}
if (s->params.quality == FAST_ONE_PASS_COMPRESSION_QUALITY ||
@@ -1043,7 +1046,7 @@ static BROTLI_BOOL EncodeData(
newsize += (bytes / 4) + 16;
s->cmd_alloc_size_ = newsize;
new_commands = BROTLI_ALLOC(m, Command, newsize);
- if (BROTLI_IS_OOM(m)) return BROTLI_FALSE;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(new_commands)) return BROTLI_FALSE;
if (s->commands_) {
memcpy(new_commands, s->commands_, sizeof(Command) * s->num_commands_);
BROTLI_FREE(m, s->commands_);
@@ -1275,7 +1278,7 @@ static BROTLI_BOOL BrotliCompressBufferQuality10(
ZopfliNode* nodes = BROTLI_ALLOC(m, ZopfliNode, block_size + 1);
size_t path_size;
size_t new_cmd_alloc_size;
- if (BROTLI_IS_OOM(m)) goto oom;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(nodes)) goto oom;
BrotliInitZopfliNodes(nodes, block_size + 1);
StitchToPreviousBlockH10(&hasher.privat._H10, block_size, block_start,
input_buffer, mask);
@@ -1295,7 +1298,7 @@ static BROTLI_BOOL BrotliCompressBufferQuality10(
num_commands + path_size + 1);
if (cmd_alloc_size != new_cmd_alloc_size) {
Command* new_commands = BROTLI_ALLOC(m, Command, new_cmd_alloc_size);
- if (BROTLI_IS_OOM(m)) goto oom;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(new_commands)) goto oom;
cmd_alloc_size = new_cmd_alloc_size;
if (commands) {
memcpy(new_commands, commands, sizeof(Command) * num_commands);
@@ -1327,7 +1330,7 @@ static BROTLI_BOOL BrotliCompressBufferQuality10(
if (metablock_size == 0) {
/* Write the ISLAST and ISEMPTY bits. */
storage = BROTLI_ALLOC(m, uint8_t, 16);
- if (BROTLI_IS_OOM(m)) goto oom;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(storage)) goto oom;
storage[0] = (uint8_t)last_bytes;
storage[1] = (uint8_t)(last_bytes >> 8);
BrotliWriteBits(2, 3, &storage_ix, storage);
@@ -1338,7 +1341,7 @@ static BROTLI_BOOL BrotliCompressBufferQuality10(
CreateBackwardReferences is now unused. */
memcpy(dist_cache, saved_dist_cache, 4 * sizeof(dist_cache[0]));
storage = BROTLI_ALLOC(m, uint8_t, metablock_size + 16);
- if (BROTLI_IS_OOM(m)) goto oom;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(storage)) goto oom;
storage[0] = (uint8_t)last_bytes;
storage[1] = (uint8_t)(last_bytes >> 8);
BrotliStoreUncompressedMetaBlock(is_last, input_buffer,
@@ -1362,7 +1365,7 @@ static BROTLI_BOOL BrotliCompressBufferQuality10(
BrotliOptimizeHistograms(block_params.dist.alphabet_size_limit, &mb);
}
storage = BROTLI_ALLOC(m, uint8_t, 2 * metablock_size + 503);
- if (BROTLI_IS_OOM(m)) goto oom;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(storage)) goto oom;
storage[0] = (uint8_t)last_bytes;
storage[1] = (uint8_t)(last_bytes >> 8);
BrotliStoreMetaBlock(m, input_buffer, metablock_start, metablock_size,
@@ -1613,7 +1616,10 @@ static BROTLI_BOOL BrotliEncoderCompressStreamFast(
BROTLI_ALLOC(m, uint32_t, kCompressFragmentTwoPassBlockSize);
s->literal_buf_ =
BROTLI_ALLOC(m, uint8_t, kCompressFragmentTwoPassBlockSize);
- if (BROTLI_IS_OOM(m)) return BROTLI_FALSE;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(s->command_buf_) ||
+ BROTLI_IS_NULL(s->literal_buf_)) {
+ return BROTLI_FALSE;
+ }
}
if (s->command_buf_) {
command_buf = s->command_buf_;
@@ -1621,7 +1627,10 @@ static BROTLI_BOOL BrotliEncoderCompressStreamFast(
} else {
tmp_command_buf = BROTLI_ALLOC(m, uint32_t, buf_size);
tmp_literal_buf = BROTLI_ALLOC(m, uint8_t, buf_size);
- if (BROTLI_IS_OOM(m)) return BROTLI_FALSE;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(tmp_command_buf) ||
+ BROTLI_IS_NULL(tmp_literal_buf)) {
+ return BROTLI_FALSE;
+ }
command_buf = tmp_command_buf;
literal_buf = tmp_literal_buf;
}
diff --git a/c/enc/hash.h b/c/enc/hash.h
index 60fb5df..6362f69 100644
--- a/c/enc/hash.h
+++ b/c/enc/hash.h
@@ -426,7 +426,7 @@ static BROTLI_INLINE void HasherSetup(MemoryManager* m, Hasher* hasher,
ChooseHasher(params, &params->hasher);
alloc_size = HasherSize(params, one_shot, input_size);
hasher->common.extra = BROTLI_ALLOC(m, uint8_t, alloc_size);
- if (BROTLI_IS_OOM(m)) return;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(hasher->common.extra)) return;
hasher->common.params = params->hasher;
switch (hasher->common.params.type) {
#define INITIALIZE_(N) \
diff --git a/c/enc/hash_longest_match_quickly_inc.h b/c/enc/hash_longest_match_quickly_inc.h
index 2af13c8..e5ba840 100644
--- a/c/enc/hash_longest_match_quickly_inc.h
+++ b/c/enc/hash_longest_match_quickly_inc.h
@@ -167,21 +167,21 @@ static BROTLI_INLINE void FN(FindLongestMatch)(
if (prev_ix < cur_ix) {
prev_ix &= (uint32_t)ring_buffer_mask;
if (compare_char == data[prev_ix + best_len]) {
- size_t len = FindMatchLengthWithLimit(&data[prev_ix],
- &data[cur_ix_masked],
- max_length);
+ const size_t len = FindMatchLengthWithLimit(
+ &data[prev_ix], &data[cur_ix_masked], max_length);
if (len >= 4) {
const score_t score = BackwardReferenceScoreUsingLastDistance(len);
if (best_score < score) {
- best_score = score;
- best_len = len;
out->len = len;
out->distance = cached_backward;
- out->score = best_score;
- compare_char = data[cur_ix_masked + best_len];
+ out->score = score;
if (BUCKET_SWEEP == 1) {
buckets[key] = (uint32_t)cur_ix;
return;
+ } else {
+ best_len = len;
+ best_score = score;
+ compare_char = data[cur_ix_masked + len];
}
}
}
diff --git a/c/enc/hash_rolling_inc.h b/c/enc/hash_rolling_inc.h
index bca41cc..586ae73 100644
--- a/c/enc/hash_rolling_inc.h
+++ b/c/enc/hash_rolling_inc.h
@@ -156,7 +156,7 @@ static BROTLI_INLINE void FN(FindLongestMatch)(
const size_t dictionary_distance, const size_t max_distance,
HasherSearchResult* BROTLI_RESTRICT out) {
const size_t cur_ix_masked = cur_ix & ring_buffer_mask;
- size_t pos = self->next_ix;
+ size_t pos;
if ((cur_ix & (JUMP - 1)) != 0) return;
diff --git a/c/enc/memory.h b/c/enc/memory.h
index ab928d0..832e7b2 100644
--- a/c/enc/memory.h
+++ b/c/enc/memory.h
@@ -56,6 +56,18 @@ BROTLI_INTERNAL void BrotliFree(MemoryManager* m, void* p);
#define BROTLI_IS_OOM(M) (!!(M)->is_oom)
#endif /* BROTLI_ENCODER_EXIT_ON_OOM */
+/*
+BROTLI_IS_NULL is a fake check, BROTLI_IS_OOM does the heavy lifting.
+The only purpose of it is to explain static analyzers the state of things.
+NB: use ONLY together with BROTLI_IS_OOM
+ AND ONLY for allocations in the current scope.
+ */
+#if defined(__clang_analyzer__) && !defined(BROTLI_ENCODER_EXIT_ON_OOM)
+#define BROTLI_IS_NULL(A) ((A) == nullptr)
+#else /* defined(__clang_analyzer__) */
+#define BROTLI_IS_NULL(A) (!!0)
+#endif /* defined(__clang_analyzer__) */
+
BROTLI_INTERNAL void BrotliWipeOutMemoryManager(MemoryManager* m);
/*
@@ -66,18 +78,18 @@ A: array
C: capacity
R: requested size
*/
-#define BROTLI_ENSURE_CAPACITY(M, T, A, C, R) { \
- if (C < (R)) { \
- size_t _new_size = (C == 0) ? (R) : C; \
- T* new_array; \
- while (_new_size < (R)) _new_size *= 2; \
- new_array = BROTLI_ALLOC((M), T, _new_size); \
- if (!BROTLI_IS_OOM(M) && C != 0) \
- memcpy(new_array, A, C * sizeof(T)); \
- BROTLI_FREE((M), A); \
- A = new_array; \
- C = _new_size; \
- } \
+#define BROTLI_ENSURE_CAPACITY(M, T, A, C, R) { \
+ if (C < (R)) { \
+ size_t _new_size = (C == 0) ? (R) : C; \
+ T* new_array; \
+ while (_new_size < (R)) _new_size *= 2; \
+ new_array = BROTLI_ALLOC((M), T, _new_size); \
+ if (!BROTLI_IS_OOM(M) && !BROTLI_IS_NULL(new_array) && C != 0) \
+ memcpy(new_array, A, C * sizeof(T)); \
+ BROTLI_FREE((M), A); \
+ A = new_array; \
+ C = _new_size; \
+ } \
}
/*
diff --git a/c/enc/metablock.c b/c/enc/metablock.c
index b3e6c38..5aa4d4f 100644
--- a/c/enc/metablock.c
+++ b/c/enc/metablock.c
@@ -196,7 +196,7 @@ void BrotliBuildMetaBlock(MemoryManager* m,
literal_context_multiplier = 1 << BROTLI_LITERAL_CONTEXT_BITS;
literal_context_modes =
BROTLI_ALLOC(m, ContextType, mb->literal_split.num_types);
- if (BROTLI_IS_OOM(m)) return;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(literal_context_modes)) return;
for (i = 0; i < mb->literal_split.num_types; ++i) {
literal_context_modes[i] = literal_context_mode;
}
@@ -206,21 +206,21 @@ void BrotliBuildMetaBlock(MemoryManager* m,
mb->literal_split.num_types * literal_context_multiplier;
literal_histograms =
BROTLI_ALLOC(m, HistogramLiteral, literal_histograms_size);
- if (BROTLI_IS_OOM(m)) return;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(literal_histograms)) return;
ClearHistogramsLiteral(literal_histograms, literal_histograms_size);
distance_histograms_size =
mb->distance_split.num_types << BROTLI_DISTANCE_CONTEXT_BITS;
distance_histograms =
BROTLI_ALLOC(m, HistogramDistance, distance_histograms_size);
- if (BROTLI_IS_OOM(m)) return;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(distance_histograms)) return;
ClearHistogramsDistance(distance_histograms, distance_histograms_size);
BROTLI_DCHECK(mb->command_histograms == 0);
mb->command_histograms_size = mb->command_split.num_types;
mb->command_histograms =
BROTLI_ALLOC(m, HistogramCommand, mb->command_histograms_size);
- if (BROTLI_IS_OOM(m)) return;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(mb->command_histograms)) return;
ClearHistogramsCommand(mb->command_histograms, mb->command_histograms_size);
BrotliBuildHistogramsWithContext(cmds, num_commands,
@@ -234,13 +234,13 @@ void BrotliBuildMetaBlock(MemoryManager* m,
mb->literal_split.num_types << BROTLI_LITERAL_CONTEXT_BITS;
mb->literal_context_map =
BROTLI_ALLOC(m, uint32_t, mb->literal_context_map_size);
- if (BROTLI_IS_OOM(m)) return;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(mb->literal_context_map)) return;
BROTLI_DCHECK(mb->literal_histograms == 0);
mb->literal_histograms_size = mb->literal_context_map_size;
mb->literal_histograms =
BROTLI_ALLOC(m, HistogramLiteral, mb->literal_histograms_size);
- if (BROTLI_IS_OOM(m)) return;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(mb->literal_histograms)) return;
BrotliClusterHistogramsLiteral(m, literal_histograms, literal_histograms_size,
kMaxNumberOfHistograms, mb->literal_histograms,
@@ -265,13 +265,13 @@ void BrotliBuildMetaBlock(MemoryManager* m,
mb->distance_split.num_types << BROTLI_DISTANCE_CONTEXT_BITS;
mb->distance_context_map =
BROTLI_ALLOC(m, uint32_t, mb->distance_context_map_size);
- if (BROTLI_IS_OOM(m)) return;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(mb->distance_context_map)) return;
BROTLI_DCHECK(mb->distance_histograms == 0);
mb->distance_histograms_size = mb->distance_context_map_size;
mb->distance_histograms =
BROTLI_ALLOC(m, HistogramDistance, mb->distance_histograms_size);
- if (BROTLI_IS_OOM(m)) return;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(mb->distance_histograms)) return;
BrotliClusterHistogramsDistance(m, distance_histograms,
mb->distance_context_map_size,
@@ -369,7 +369,7 @@ static void InitContextBlockSplitter(
*histograms_size = max_num_types * num_contexts;
*histograms = BROTLI_ALLOC(m, HistogramLiteral, *histograms_size);
self->histograms_ = *histograms;
- if (BROTLI_IS_OOM(m)) return;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(*histograms)) return;
/* Clear only current histogram. */
ClearHistogramsLiteral(&self->histograms_[0], num_contexts);
self->last_histogram_ix_[0] = self->last_histogram_ix_[1] = 0;
@@ -419,7 +419,7 @@ static void ContextBlockSplitterFinishBlock(
double combined_entropy[2 * BROTLI_MAX_STATIC_CONTEXTS];
double diff[2] = { 0.0 };
size_t i;
- if (BROTLI_IS_OOM(m)) return;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(combined_histo)) return;
for (i = 0; i < num_contexts; ++i) {
size_t curr_histo_ix = self->curr_histogram_ix_ + i;
size_t j;
@@ -523,7 +523,7 @@ static void MapStaticContexts(MemoryManager* m,
mb->literal_split.num_types << BROTLI_LITERAL_CONTEXT_BITS;
mb->literal_context_map =
BROTLI_ALLOC(m, uint32_t, mb->literal_context_map_size);
- if (BROTLI_IS_OOM(m)) return;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(mb->literal_context_map)) return;
for (i = 0; i < mb->literal_split.num_types; ++i) {
uint32_t offset = (uint32_t)(i * num_contexts);
diff --git a/c/enc/metablock_inc.h b/c/enc/metablock_inc.h
index dcc9d3c..ed507ef 100644
--- a/c/enc/metablock_inc.h
+++ b/c/enc/metablock_inc.h
@@ -71,7 +71,7 @@ static void FN(InitBlockSplitter)(
*histograms_size = max_num_types;
*histograms = BROTLI_ALLOC(m, HistogramType, *histograms_size);
self->histograms_ = *histograms;
- if (BROTLI_IS_OOM(m)) return;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(*histograms)) return;
/* Clear only current histogram. */
FN(HistogramClear)(&self->histograms_[0]);
self->last_histogram_ix_[0] = self->last_histogram_ix_[1] = 0;
diff --git a/c/enc/ringbuffer.h b/c/enc/ringbuffer.h
index 2fbac07..8dce148 100644
--- a/c/enc/ringbuffer.h
+++ b/c/enc/ringbuffer.h
@@ -75,7 +75,7 @@ static BROTLI_INLINE void RingBufferInitBuffer(
uint8_t* new_data = BROTLI_ALLOC(
m, uint8_t, 2 + buflen + kSlackForEightByteHashingEverywhere);
size_t i;
- if (BROTLI_IS_OOM(m)) return;
+ if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(new_data)) return;
if (rb->data_) {
memcpy(new_data, rb->data_,
2 + rb->cur_size_ + kSlackForEightByteHashingEverywhere);
diff --git a/java/org/brotli/dec/BUILD b/java/org/brotli/dec/BUILD
index e6d3a4d..13ec43a 100644
--- a/java/org/brotli/dec/BUILD
+++ b/java/org/brotli/dec/BUILD
@@ -11,7 +11,7 @@ java_library(
["*.java"],
exclude = ["*Test*.java"],
),
- proguard_specs = ["proguard.cfg"],
+ proguard_specs = ["proguard.pgcfg"],
)
java_library(
diff --git a/java/org/brotli/dec/proguard.cfg b/java/org/brotli/dec/proguard.pgcfg
similarity index 100%
rename from java/org/brotli/dec/proguard.cfg
rename to java/org/brotli/dec/proguard.pgcfg
diff --git a/js/decode.js b/js/decode.js
old mode 100755
new mode 100644
--
2.19.1