Skip to content

Commit

Permalink
external libs: rebuilt flac with undefined behavior fixes from mainst…
Browse files Browse the repository at this point in the history
…ream
  • Loading branch information
sezero committed Dec 1, 2019
1 parent 4b814c0 commit 8d0f5aa
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 68 deletions.
Binary file modified VisualC/external/lib/x64/libFLAC-8.dll
Binary file not shown.
Binary file modified VisualC/external/lib/x86/libFLAC-8.dll
Binary file not shown.
Binary file modified Xcode/Frameworks/FLAC.framework/Versions/A/FLAC
Binary file not shown.
17 changes: 6 additions & 11 deletions external/flac-1.3.3/0002a-flac.git-19a0e99.patch
@@ -1,15 +1,13 @@
From 19a0e99ac3ac5f1fc24d66612668a277ceba8195 Mon Sep 17 00:00:00 2001
From: sezero <sezero@users.sourceforge.net>
Date: Wed, 9 Oct 2019 10:39:11 +0300
Subject: [PATCH] move the new public get_decoder_client_data function to public header.
Date: Wed, 9 Oct 2019 07:39:11 +0000 (+0300)
Subject: move the new public get_decoder_client_data function to public header.
X-Git-Url: http://git.xiph.org/?p=flac.git;a=commitdiff_plain;h=19a0e99ac3ac5f1fc24d66612668a277ceba8195

move the new public get_decoder_client_data function to public header.
---
include/FLAC/stream_decoder.h | 10 ++++++++++
src/libFLAC/include/protected/stream_decoder.h | 5 -----
2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/include/FLAC/stream_decoder.h b/include/FLAC/stream_decoder.h
index 57215c5..50ebfa8 100644
index 57215c5e..50ebfa80 100644
--- a/include/FLAC/stream_decoder.h
+++ b/include/FLAC/stream_decoder.h
@@ -1550,6 +1550,16 @@ FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *
Expand All @@ -30,7 +28,7 @@ index 57215c5..50ebfa8 100644

#ifdef __cplusplus
diff --git a/src/libFLAC/include/protected/stream_decoder.h b/src/libFLAC/include/protected/stream_decoder.h
index 9909275..2f3996b 100644
index 99092751..2f3996b3 100644
--- a/src/libFLAC/include/protected/stream_decoder.h
+++ b/src/libFLAC/include/protected/stream_decoder.h
@@ -57,9 +57,4 @@ typedef struct FLAC__StreamDecoderProtected {
Expand All @@ -43,6 +41,3 @@ index 9909275..2f3996b 100644
-FLAC_API const void *FLAC__get_decoder_client_data(FLAC__StreamDecoder *decoder);
-
#endif
--
1.7.1

26 changes: 9 additions & 17 deletions external/flac-1.3.3/0004a-flac.git-7bc7aeb.patch
@@ -1,18 +1,13 @@
From 7bc7aebc7c7f10e3e5252162b668095845cd509a Mon Sep 17 00:00:00 2001
From: NY00123 <ny00@outlook.com>
Date: Mon, 14 Oct 2019 22:15:18 +0300
Subject: [PATCH] Replace unsigned with uint32_t in prototypes; Fixes DJGPP builds.
Date: Mon, 14 Oct 2019 19:15:18 +0000 (+0300)
Subject: Replace unsigned with uint32_t in prototypes; Fixes DJGPP builds.
X-Git-Url: http://git.xiph.org/?p=flac.git;a=commitdiff_plain;h=7bc7aebc7c7f10e3e5252162b668095845cd509a

Replace unsigned with uint32_t in prototypes; Fixes DJGPP builds.
---
include/test_libs_common/file_utils_flac.h | 2 +-
include/test_libs_common/metadata_utils.h | 6 +++---
src/flac/analyze.h | 2 +-
src/flac/encode.h | 2 +-
src/flac/utils.h | 2 +-
5 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/include/test_libs_common/file_utils_flac.h b/include/test_libs_common/file_utils_flac.h
index 8b809b8..7687c8f 100644
index 8b809b85..7687c8f7 100644
--- a/include/test_libs_common/file_utils_flac.h
+++ b/include/test_libs_common/file_utils_flac.h
@@ -31,6 +31,6 @@
Expand All @@ -24,7 +19,7 @@ index 8b809b8..7687c8f 100644

#endif
diff --git a/include/test_libs_common/metadata_utils.h b/include/test_libs_common/metadata_utils.h
index ad0f6f5..6bd4e8f 100644
index ad0f6f58..6bd4e8f6 100644
--- a/include/test_libs_common/metadata_utils.h
+++ b/include/test_libs_common/metadata_utils.h
@@ -28,9 +28,9 @@
Expand All @@ -49,7 +44,7 @@ index ad0f6f5..6bd4e8f 100644
FLAC__bool mutils__compare_block(const FLAC__StreamMetadata *block, const FLAC__StreamMetadata *blockcopy);

diff --git a/src/flac/analyze.h b/src/flac/analyze.h
index 7c7ec23..44798c7 100644
index 7c7ec237..44798c71 100644
--- a/src/flac/analyze.h
+++ b/src/flac/analyze.h
@@ -26,7 +26,7 @@ typedef struct {
Expand All @@ -62,7 +57,7 @@ index 7c7ec23..44798c7 100644

#endif
diff --git a/src/flac/encode.h b/src/flac/encode.h
index 51c68a4..b98bef6 100644
index 51c68a40..b98bef6b 100644
--- a/src/flac/encode.h
+++ b/src/flac/encode.h
@@ -112,6 +112,6 @@ typedef struct {
Expand All @@ -74,7 +69,7 @@ index 51c68a4..b98bef6 100644

#endif
diff --git a/src/flac/utils.h b/src/flac/utils.h
index 6932d3e..36ceb37 100644
index 6932d3ef..36ceb37d 100644
--- a/src/flac/utils.h
+++ b/src/flac/utils.h
@@ -62,7 +62,7 @@ void stats_print_name(int level, const char *name);
Expand All @@ -86,6 +81,3 @@ index 6932d3e..36ceb37 100644

FLAC__bool flac__utils_parse_cue_specification(const char *s, utils__CueSpecification *spec);
void flac__utils_canonicalize_cue_specification(const utils__CueSpecification *cue_spec, const FLAC__StreamMetadata_CueSheet *cuesheet, FLAC__uint64 total_samples, utils__SkipUntilSpecification *skip_spec, utils__SkipUntilSpecification *until_spec);
--
1.7.1

21 changes: 21 additions & 0 deletions external/flac-1.3.3/0005a-flac.git-6455e47.patch
@@ -0,0 +1,21 @@
From: Andrey Astafyev <dev@246060.ru>
Date: Fri, 29 Nov 2019 17:03:25 +0000 (+0300)
Subject: Both files are checked for EOF
X-Git-Url: http://git.xiph.org/?p=flac.git;a=commitdiff_plain;h=6455e477218360899c55f8dbd06c6628260d4123

Both files are checked for EOF
---

diff --git a/src/utils/flacdiff/main.cpp b/src/utils/flacdiff/main.cpp
index f86b8bbd..6a42db15 100644
--- a/src/utils/flacdiff/main.cpp
+++ b/src/utils/flacdiff/main.cpp
@@ -166,7 +166,7 @@ static FLAC__off_t get_diff_offset(AutoFILE &f1, AutoFILE &f2)
{
FLAC__off_t off = 0;
while(1) {
- if(feof((FILE*)f1) && feof((FILE*)f1)) {
+ if(feof((FILE*)f1) && feof((FILE*)f2)) {
fprintf(stderr, "ERROR: files are identical\n");
return -1;
}
18 changes: 7 additions & 11 deletions external/flac-1.3.3/0012-flac.git-d4a1b345.patch
@@ -1,7 +1,9 @@
From d4a1b345dd16591ff6f17c67ee519afebe2f9792 Mon Sep 17 00:00:00 2001
From: sezero <sezero@users.sourceforge.net>
Date: Tue, 8 Oct 2019 20:25:55 +0300
Subject: [PATCH] configure.ac: allow several compiler flags for clang
Date: Tue, 8 Oct 2019 17:25:55 +0000 (+0300)
Subject: configure.ac: allow several compiler flags for clang
X-Git-Url: http://git.xiph.org/?p=flac.git;a=commitdiff_plain;h=d4a1b345dd16591ff6f17c67ee519afebe2f9792

configure.ac: allow several compiler flags for clang

The flac configury marked clang as 'not being gcc' and excluded
a lot of compiler switches, most importantly the visibility flags,
Expand All @@ -26,12 +28,9 @@ Tested compilation using gcc-7.3.1 and clang-5.0.2 on x86_64-linux,
and gcc-4.4.7 and clang-3.4.2 on an i686-linux. Also tested cross-
compiling for Mac OS X using clang-5.0.2.
---
configure.ac | 18 ++++++++++++++----
m4/gcc_version.m4 | 3 +++
2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/configure.ac b/configure.ac
index 6efefaf..88f89a9 100644
index 6efefaf5..88f89a91 100644
--- a/configure.ac
+++ b/configure.ac
@@ -429,11 +429,12 @@ dnl If debugging is disabled AND no CFLAGS/CXXFLAGS/CPPFLAGS/LDFLAGS
Expand Down Expand Up @@ -75,7 +74,7 @@ index 6efefaf..88f89a9 100644
CFLAGS="$CFLAGS -fvisibility=hidden"
CXXFLAGS="$CXXFLAGS -fvisibility=hidden"
diff --git a/m4/gcc_version.m4 b/m4/gcc_version.m4
index 1c53086..e6aaa60 100644
index 1c53086f..e6aaa603 100644
--- a/m4/gcc_version.m4
+++ b/m4/gcc_version.m4
@@ -22,6 +22,9 @@ if test "x$ac_cv_c_compiler_gnu" = "xyes" ; then
Expand All @@ -88,6 +87,3 @@ index 1c53086..e6aaa60 100644
fi

AC_SUBST(GCC_VERSION)
--
1.7.1

24 changes: 9 additions & 15 deletions external/flac-1.3.3/0013-flac.git-b917d456.patch
@@ -1,22 +1,19 @@
From b917d456d23c3268cc6f466d720605b713d7b9ff Mon Sep 17 00:00:00 2001
From: sezero <sezero@users.sourceforge.net>
Date: Tue, 8 Oct 2019 15:10:20 +0300
Subject: [PATCH] make dllexport work with compilers other than MSVC
Date: Tue, 8 Oct 2019 12:10:20 +0000 (+0300)
Subject: make dllexport work with compilers other than MSVC
X-Git-Url: http://git.xiph.org/?p=flac.git;a=commitdiff_plain;h=b917d456d23c3268cc6f466d720605b713d7b9ff

make dllexport work with compilers other than MSVC

the issue is, flac and metaflac exes rely on flac_internal_???_utf8()
procedures from windows_unicode_filenames.c and there is no easy way
to exclude them from exports without breaking things. So export them
explicitly (they are exported anyway w/o this patch), but add a FIXME
note about the kludge in windows_unicode_filenames.c.
---
configure.ac | 16 ++++++++++++++++
include/FLAC++/export.h | 2 +-
include/FLAC/export.h | 2 +-
src/libFLAC/windows_unicode_filenames.c | 19 +++++++++++--------
4 files changed, 29 insertions(+), 10 deletions(-)

diff --git a/configure.ac b/configure.ac
index 14e2205..6efefaf 100644
index 14e2205a..6efefaf5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -493,6 +493,22 @@ if test x$enable_stack_smash_protection = "xyes" ; then
Expand All @@ -43,7 +40,7 @@ index 14e2205..6efefaf 100644
Makefile \
src/Makefile \
diff --git a/include/FLAC++/export.h b/include/FLAC++/export.h
index 1645362..6776b29 100644
index 16453621..6776b29c 100644
--- a/include/FLAC++/export.h
+++ b/include/FLAC++/export.h
@@ -59,7 +59,7 @@
Expand All @@ -56,7 +53,7 @@ index 1645362..6776b29 100644
#define FLACPP_API __declspec(dllexport)
#else
diff --git a/include/FLAC/export.h b/include/FLAC/export.h
index d52f0bb..628fe5f 100644
index d52f0bbb..628fe5fc 100644
--- a/include/FLAC/export.h
+++ b/include/FLAC/export.h
@@ -59,7 +59,7 @@
Expand All @@ -69,7 +66,7 @@ index d52f0bb..628fe5f 100644
#define FLAC_API __declspec(dllexport)
#else
diff --git a/src/libFLAC/windows_unicode_filenames.c b/src/libFLAC/windows_unicode_filenames.c
index 7855008..7f59ebe 100644
index 78550087..7f59ebea 100644
--- a/src/libFLAC/windows_unicode_filenames.c
+++ b/src/libFLAC/windows_unicode_filenames.c
@@ -37,6 +37,9 @@
Expand Down Expand Up @@ -150,6 +147,3 @@ index 7855008..7f59ebe 100644
{
if (!utf8_filenames) {
return rename(oldname, newname);
--
1.7.1

18 changes: 7 additions & 11 deletions external/flac-1.3.3/0013a-flac.git-25305d6.patch
@@ -1,16 +1,15 @@
From 25305d685b52979295064a9b566e697372a9878a Mon Sep 17 00:00:00 2001
From: sezero <sezero@users.sourceforge.net>
Date: Fri, 18 Oct 2019 08:11:10 +0300
Subject: [PATCH] Fix msvc build after commit b917d456
Date: Fri, 18 Oct 2019 05:11:10 +0000 (+0300)
Subject: Fix msvc build after commit b917d456
X-Git-Url: http://git.xiph.org/?p=flac.git;a=commitdiff_plain;h=25305d685b52979295064a9b566e697372a9878a

Fix msvc build after commit b917d456

Closes: https://github.com/xiph/flac/issues/152
---
include/share/windows_unicode_filenames.h | 19 +++++++++++--------
src/libFLAC/windows_unicode_filenames.c | 1 -
2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/include/share/windows_unicode_filenames.h b/include/share/windows_unicode_filenames.h
index 526b30d..94cbeb6 100644
index 526b30d5..94cbeb6c 100644
--- a/include/share/windows_unicode_filenames.h
+++ b/include/share/windows_unicode_filenames.h
@@ -39,21 +39,24 @@
Expand Down Expand Up @@ -47,7 +46,7 @@ index 526b30d..94cbeb6 100644
#ifdef __cplusplus
} /* extern "C" */
diff --git a/src/libFLAC/windows_unicode_filenames.c b/src/libFLAC/windows_unicode_filenames.c
index 7f59ebe..bf3bfe1 100644
index 7f59ebea..bf3bfe16 100644
--- a/src/libFLAC/windows_unicode_filenames.c
+++ b/src/libFLAC/windows_unicode_filenames.c
@@ -38,7 +38,6 @@
Expand All @@ -58,6 +57,3 @@ index 7f59ebe..bf3bfe1 100644

/* convert UTF-8 back to WCHAR. Caller is responsible for freeing memory */
static wchar_t *wchar_from_utf8(const char *str)
--
1.7.1

35 changes: 35 additions & 0 deletions external/flac-1.3.3/0015c-flac.git-b02e159.patch
@@ -0,0 +1,35 @@
From: Erik de Castro Lopo <erikd@mega-nerd.com>
Date: Sun, 24 Nov 2019 03:14:50 +0000 (+1100)
Subject: libFLAC/bitreader.c: Fix shift invoking undefined behaviour
X-Git-Url: http://git.xiph.org/?p=flac.git;a=commitdiff_plain;h=b02e1593525f63aaa4c671e034ff8f0cdc641e46

libFLAC/bitreader.c: Fix shift invoking undefined behaviour

Credit: Oss-Fuzz
Issue: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=19067
Testcase: fuzzer_decoder-5725157960450048
---

diff --git a/src/libFLAC/bitreader.c b/src/libFLAC/bitreader.c
index e94f8b01..79cb5cc4 100644
--- a/src/libFLAC/bitreader.c
+++ b/src/libFLAC/bitreader.c
@@ -405,7 +405,8 @@ FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *va
const brword word = br->buffer[br->consumed_words];
const brword mask = br->consumed_bits < FLAC__BITS_PER_WORD ? FLAC__WORD_ALL_ONES >> br->consumed_bits : 0;
if(bits < n) {
- *val = (FLAC__uint32)((word & mask) >> (n-bits)); /* The result has <= 32 non-zero bits */
+ uint32_t shift = n - bits;
+ *val = shift < FLAC__BITS_PER_WORD ? (FLAC__uint32)((word & mask) >> shift) : 0; /* The result has <= 32 non-zero bits */
br->consumed_bits += bits;
return true;
}
@@ -670,7 +671,7 @@ FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, uint32_t *va
*val = 0;
while(1) {
while(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
- brword b = br->buffer[br->consumed_words] << br->consumed_bits;
+ brword b = br->consumed_bits < FLAC__BITS_PER_WORD ? br->buffer[br->consumed_words] << br->consumed_bits : 0;
if(b) {
i = COUNT_ZERO_MSBS(b);
*val += i;
5 changes: 3 additions & 2 deletions external/flac-1.3.3/src/libFLAC/bitreader.c
Expand Up @@ -405,7 +405,8 @@ FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *va
const brword word = br->buffer[br->consumed_words];
const brword mask = br->consumed_bits < FLAC__BITS_PER_WORD ? FLAC__WORD_ALL_ONES >> br->consumed_bits : 0;
if(bits < n) {
*val = (FLAC__uint32)((word & mask) >> (n-bits)); /* The result has <= 32 non-zero bits */
uint32_t shift = n - bits;
*val = shift < FLAC__BITS_PER_WORD ? (FLAC__uint32)((word & mask) >> shift) : 0; /* The result has <= 32 non-zero bits */
br->consumed_bits += bits;
return true;
}
Expand Down Expand Up @@ -670,7 +671,7 @@ FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, uint32_t *va
*val = 0;
while(1) {
while(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
brword b = br->buffer[br->consumed_words] << br->consumed_bits;
brword b = br->consumed_bits < FLAC__BITS_PER_WORD ? br->buffer[br->consumed_words] << br->consumed_bits : 0;
if(b) {
i = COUNT_ZERO_MSBS(b);
*val += i;
Expand Down
2 changes: 1 addition & 1 deletion external/flac-1.3.3/src/utils/flacdiff/main.cpp
Expand Up @@ -166,7 +166,7 @@ static FLAC__off_t get_diff_offset(AutoFILE &f1, AutoFILE &f2)
{
FLAC__off_t off = 0;
while(1) {
if(feof((FILE*)f1) && feof((FILE*)f1)) {
if(feof((FILE*)f1) && feof((FILE*)f2)) {
fprintf(stderr, "ERROR: files are identical\n");
return -1;
}
Expand Down

0 comments on commit 8d0f5aa

Please sign in to comment.