Commit Graph

3988 Commits

Author SHA1 Message Date
Martijn van Beurden 1ca7b38f3c Add FLAC__STREAM_DECODER_ERROR_STATUS_BAD_METADATA 2022-04-20 12:06:42 +02:00
Martijn van Beurden 0077d3b697 Add checks in parsing metadata blocks
In parsing certain types of metadata blocks, it was not checked
whether certain length fields were at all possible. A small file
of 64 byte was enough to let the decoder allocate 4GiB of memory
by simply stating a field was 4GiB in length, while metadata
blocks in FLAC cannot be larger than 16MiB.

This commit adds a mechanism to the bitreader to set a length
limit upon reading. This limit is checked at each read, at each
memory allocation and after reading the block. In case anything
is deemed wrong, parsing metadata is aborted, as 'resyncing' is
only possible on audio frames, not on metadata blocks.

Credit: Oss-Fuzz
Issue: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=37865
2022-04-20 12:06:42 +02:00
Martijn van Beurden 0f98b940f8 Update fuzzers
This changes the names of the two fuzzers so they align with
current oss-fuzz usage (to provide continuity in test data and
corpora) and adds a dictionary to the decoder fuzzer. It also
removes some unnecessary configuration, as it clashed with oss-fuzz
defaults
2022-04-20 11:10:08 +02:00
Martijn van Beurden b48ed95fcb Deduplicate VSX and SSE2 autocorelation calculation code 2022-04-19 20:38:37 +02:00
Martijn van Beurden ee18d1b892 Switch to autoc[] as double
This changes the calculation of autocorrelation from single precision
float to double precision. With this, compression improves on average
by about 0.5% with compression level 4, with some tracks (espcially
material with high samplerates) seeing improvements of 10% or more.

This commit removes SSE intrinsics and MMX assembler routins, adds
SSE2 and changes VSX autoc[] routines and changes the regular C
code.
2022-04-19 20:38:37 +02:00
Martijn van Beurden b19ed90a5b
Remove api doc note untrue since commit c9c0d13
This has been untrue for almost 20 years now
2022-04-19 19:05:24 +02:00
Martijn van Beurden 7385dac383
Fix overflow of streaminfo total samples (github issue 237)
When writing a FLAC file with over 2^36 samples, the total samples
entry in streaminfo will overflow and wrap around. Setting it to 0
(which means unknown number of samples) makes sure the decoder
doesn't rely on this number

Co-authored-by: Ralph Giles <giles@thaumas.net>
2022-04-19 17:45:22 +02:00
NotTsunami 7406eabe17 Remove unused macros
Cleanup of ecede0bc72
2022-04-19 10:57:46 +02:00
Till Schäfer ff818486dc Avoid creating a new variable in md5 gcc workaround
https://sourceforge.net/p/flac/bugs/478/
2022-04-19 10:55:23 +02:00
Martijn van Beurden 4b7e79f974 Fix stack protector detection for C++ 2022-04-19 10:55:23 +02:00
Martijn van Beurden cde4b8c783 Add more overflow checks for residual_bits calculation
commit 585e3b added an overflow check in the residual bits
calculation, but actually hitting this causes problems further
down the line. This fixes the problem described in
https://hydrogenaud.io/index.php?topic=121349.msg1001227;topicseen#new

Also, UINT_MAX is changed to UINT32_MAX as uint32_t is used, not unsigned
2022-04-17 21:22:02 +02:00
Martijn van Beurden 21d0640ea9 Limit maximum size of bitwriter buffer
In the past, various bugs have triggered libFLAC to write enormous
coded residuals. While these bugs have been fixed, this check is
added to limit the impact of possible remaining or future bugs

When a bitwriter is grown past the maximum sane size of a frame
(8 channels of 65535 samples with 24 + 4 bits per sample) this
indicates that such a bug was triggered. Instead of a possible
crash or creating unreadable files, bitwriter_grow_ fails as if
it could not allocate more memory.
2022-04-17 19:17:02 +02:00
Martijn van Beurden 2e50ea341d Remove special treatment of partition_order == 0
in set_partitioned_rice, there was a special treatment in case
partition_order == 0. In this case, a rice parameter was passed
as an argument. However, in case of an LPC block, this rice
parameter was calculated from the LPC error, which is based on the
samples after windowing. Quite often, this resulted in a subframe
with two partition with the same rice parameter. Also, in case of
partial_tukey and punchout_tukey windows, the suggested rice
parameter could be quite sub-optimal.

This patch removes the special treatment of partition_order == 0
and the passing of a rice_parameter as an argument
2022-04-17 19:17:02 +02:00
Martijn van Beurden c729747d42 Fix size of first frame when using analyze function
The size of the first frame was displaying including a PADDING
block, as the decoder position wasn't updated after processing
one such block. The location in the code where the decoder
position is updated has been moved, so a PADDING block does not
get included into the size of the first frame anymore
2022-04-17 16:41:39 +02:00
Martijn van Beurden 14eb65de34 Fix configuration of stack smash protection/fortify source on MinGW
Without this commit, building fails on MinGW because
-D_FORTIFY_SOURCE=2 needs runtime support which MinGW does not
provide. Building was possible with make LDFLAGS='-lssp'

This commit checks whether a symbol used by _D_FORTIFY_SOURCE=2 and
the stack smashing protector are available, and if so, enables these.
Resulting DLLs depend on the libssp DLL.
2022-04-15 09:36:15 +02:00
Martijn van Beurden 7dd7f94822 Fix building both static and shared libs on MinGW with autotools
When building both static and shared libs on MinGW with autotools,
the build broke down without any error message. This commit makes
such a build work
2022-04-15 09:36:15 +02:00
Martijn van Beurden ecede0bc72 Remove AC_C_VARARRAYS from configure.ac
With autoconf 2.70, the behaviour of AC_C_VARARRAYS has changed,
causing a lot of warnings and as a result a cluttered make output.

Doing some research as to where this comes from, I found an strange
piece of code that seems to rely on a misunderstanding as to VLA's
in C++. As I found, the C++ standard does not have VLA's. The
configure.ac code and some code in libFLAC++ seems to think it does.
This now causes strange behaviour.

This commit removes the code relying on this behaviour and removing
all VLA related autoconf macro's from configure.ac
2022-04-15 09:36:15 +02:00
Martijn van Beurden 13149acddd Remove more obsolete autoconf macro's
Autoconf 2.71 warns about obsolete macro's on running ./autogen.sh.

AC_PROG_CC_STDC is replaced by AC_PROG_CC as recommended by autoupdate

AC_HEADER_STDC has been removed. Autoupdate recommended the following:
> The preprocessor macro `STDC_HEADERS' is obsolete. Except in unusual
> embedded environments, you can safely include all ISO C90 headers
> unconditionally.
2022-04-15 09:36:15 +02:00
Martijn van Beurden d94a43d5c3 Update configure.ac and m4 files with autoupdate 2.60
Starting with autoconf 2.70, obsolescence warnings are output by
default. To keep the script as compatible as possible, I build
autoconf 2.60 and ran the autoupdate that came with it on
configure.ac and all m4 files.
2022-04-15 09:36:15 +02:00
Rosen Penev 144075a114 add clang-format file
This was generated with whatstyle:

whatstyle.py $(find -name "*.h")

with some minor fixups.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2022-04-14 20:42:01 +02:00
Con Kolivas 24629435bb Add support in the encoder for up to 20 bit sample rates
Now that many DACs support up to 768kHz, add support for these
sample rates to the encoder. Files produced with these sample rates
are already decodable by the reference decoder. Update documentation
and tests accordingly.
2022-04-13 20:32:08 +02:00
Martijn van Beurden f7e77f627a Build as Release to speed up testing and mute debug output 2022-04-13 17:37:50 +02:00
Martijn van Beurden 31bcbb8662 [CI] Run full test suite on Windows 2022-04-13 17:37:50 +02:00
Martijn van Beurden ce31a1d51f [CMake] Enable testing through busybox
With this commit, it is possible to run the full test suite on
Windows machines when busybox-w32 is installed. This program is
available through chocolatey with 'choco install busybox'

CMake tests for availability of busybox and use if available. As
chocolatey is the preferred method of fetching software for
Github actions, this commit paves the way for running the full
test suite on Windows for CI
2022-04-13 17:37:50 +02:00
Martijn van Beurden 0ec47a87b4 [CMake] Remove /MT from MSVC flags, causes crashes with shared libs 2022-04-13 17:37:50 +02:00
Martijn van Beurden db72703f86 [CMake] Set binary and library output dir to objs on Windows
Without this patch, CMake places output binaries and libraries in
the respective source directories, like the autotools build system.
The Visual Studio build system places objects in the objs directory

Because CTest didn't run properly when building shared libs, this
commit changes the CMake behaviour on (NOT UNIX) to that similar
to Visual Studio. That way, DLLs and EXEs are placed in the same
directory and running CTest with the correct DLLs being loaded
is trivial.
2022-04-13 17:37:50 +02:00
Martijn van Beurden 4256c12eac [CMake] Specifically prefer linking with static libssp
As to have a libFLAC.dll with no additional dependencies, linking
with libssp.a is preferred over linking with libssp.dll.a
2022-04-13 17:37:50 +02:00
Martijn van Beurden 6e3089b9bc [CMake] Add BUILD_SHARED_LIBS as options 2022-04-13 17:37:50 +02:00
Martijn van Beurden 805b7dba83 [CMake] Build with -lssp on MinGW 2022-04-13 17:37:50 +02:00
NotTsunami 617efda90d CMake: Make FORTIFY_SOURCE optional
* Also add in checking for libssp for MinGW
2022-04-13 17:37:50 +02:00
Martijn van Beurden f5efd956d9 [CMake] Create prettier MSVC solution files 2022-04-13 17:37:50 +02:00
Martijn van Beurden 2013738622 [CMake] Add options for better MS Visual Studio building 2022-04-13 17:37:50 +02:00
Martijn van Beurden be1df4085a Silence clang warnings on alignment of unaligned loads
Clang throws *a lot* of warnings on alignment requirement increase
where no alignment is required at all. This is a results of the
way intrinsics were implemented long ago. See
https://stackoverflow.com/questions/71279668/why-does-clang-complain-about-alignment-on-sse-intrinsic-unaligned-loads

This commit silences these warnings by first casting the pointer
to (const void*) or (void*) before casting the (const __m128i*),
(__m128i*), (const __m256i*) or (__m256i*)

Compiling with and without this patch returns exactly the same
binary for GCC 9.3 and clang 10.0
2022-04-13 13:55:26 +02:00
Silent 179cdce1db cmake: Fix tests with BUILD_CXXLIBS or BUILD_PROGRAMS off
Fixes a regression introduced in 10797d5896
2022-04-13 07:35:33 +02:00
David Callu 6debf337c8 cmake: fix c/cxx compile option use with asm code 2022-04-12 21:37:51 +02:00
NotTsunami 2bf5f6ecc9 flacdiff: Add format specifier to prints
printf/fprintf prefer format specifiers rather than variable strings
(despite the const status). No functional change.

Fixes the following compiler reported warning:
warning: format not a string literal and no format arguments [-Wformat-security]
2022-04-12 13:03:22 +02:00
Martijn van Beurden 7b73bbcca4 Move initialization of state up in stream_encoder_new
In stream_encoder_new, set_defaults_ was called before setting
encoder->protected_->state to uninitialized. However, this state
was being accessed by set_compression_level in set_defaults_. As
this is undefined behaviour, move the initialization of
encoder->protected_->state up to before calling set_default_
2022-04-11 21:38:06 +02:00
Martijn van Beurden 4a8ec07e95
Add checks that supplied samples are bounded within bits-per-sample
The encoder did not check whether samples provided through
FLAC__stream_encoder_process or FLAC__stream_encoder_process_interleaved
were bounded to fall within the set bits_per_sample (bps). This created
all kinds of trouble within the encoder, as there are numerous times
where the encoder chooses between different datapaths, data types and
encoding strategies based on the set bps.

https://sourceforge.net/p/flac/bugs/468/ also proved that invalid FLAC
files have been created with libFLAC in the past because of this

See https://github.com/xiph/flac/pull/273 for detailed description of
the commit

Credit: Oss-Fuzz
Issue: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=19758
Issue: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=31727
2022-04-11 20:13:09 +02:00
Ralph Giles 2610594d04
Update maintainer statement.
Erik hasn't had time to look after the repo lately. We continue
as we can.

Signed-off-by: Ralph Giles <giles@thaumas.net>
2022-02-20 20:54:23 -08:00
Ralph Giles 01faa6c644
Set release date in the changelog.
Missed this in the previous commit.

Signed-off-by: Ralph Giles <giles@thaumas.net>
2022-02-20 20:54:22 -08:00
Ralph Giles 22816c6c1b
Set release date for 1.3.4.
This is a target date, but it's a nice round number if we're able
to make it work.

Signed-off-by: Ralph Giles <giles@thaumas.net>
2022-02-20 20:54:20 -08:00
Martijn van Beurden e75495be3d
Change version to 1.3.4 and add placeholders for release date
Signed-off-by: Ralph Giles <giles@thaumas.net>
2022-02-20 20:54:19 -08:00
Martijn van Beurden c86def849b
Add 1.3.4 to changelog
Signed-off-by: Ralph Giles <giles@thaumas.net>
2022-02-20 20:54:17 -08:00
Ralph Giles e548ea38d4
Run CIFuzz on the 1.3.x release branch.
Make sure we have coverage when working on backports to the
older stable API series.

Signed-off-by: Ralph Giles <giles@thaumas.net>
2022-02-20 20:54:06 -08:00
Martijn van Beurden a2fe43f64e
Change sourceforge URL in flac error messages to github
Signed-off-by: Ralph Giles <giles@thaumas.net>
2022-02-13 21:19:59 -08:00
Martijn van Beurden e8143ab527
Add CIFuzz to workflows
Signed-off-by: Ralph Giles <giles@thaumas.net>
2022-02-10 20:10:59 -08:00
Martijn van Beurden 79e462fb61
Check that blocksize is evenly divisible by 2^(partition order)
Credit: Oss-Fuzz
Issue: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=38815

Signed-off-by: Ralph Giles <giles@thaumas.net>
2022-02-08 20:49:14 -08:00
Martijn van Beurden 2f209573d0
Check for predictor order <= blocksize in subframe header
Credit: Oss-Fuzz
Issue: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=38347

Signed-off-by: Ralph Giles <giles@thaumas.net>
2022-02-08 20:49:13 -08:00
Martijn van Beurden d4a7221046
Mark fixed subframes with bps > 24 as unparsable
Like 1fd178e, decoding fixed subframes with bps > 24 results in
integer overflow

Signed-off-by: Ralph Giles <giles@thaumas.net>
2022-02-08 20:49:12 -08:00
Martijn van Beurden aa126b8f2f
Mark 32 bps stream with stereo decorrelation as unparsable
Credit: Oss-Fuzz
Issue: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=19234

Signed-off-by: Ralph Giles <giles@thaumas.net>
2022-02-08 20:49:11 -08:00