4079 Commits

Author SHA1 Message Date
Martijn van Beurden
10c0a5f610 Add INT64_MAX limit to seekpoints
FLAC seekpoints are coded in unsigned 64-bit ints, but the code
handling them uses signed 64-bit ints. Since users are unlikely
to run into this limit anyway, do not use seekpoints larger than
INT64_MAX

Credit: Oss-Fuzz
Issue: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=48112
2022-06-29 21:33:12 +02:00
Martijn van Beurden
cee5a1dcd3 Change eof handing in seeking code
Commit 3fc5ba4 replaced a seeking error with specific handling.
This handling consisted of lowering the upper seek bound.
However, this handling was both slow and wrong. Because it is slow
it causes fuzzing timeouts. It was wrong in that if there was
another valid frame in the boguss frame being read, it would no
longer be reachable.

This commit replaces the handling with another approach: instead of
lowering the upper bound, the lower bound is raised. With this, the
calculation of pos for the next seek is changed and the seeking code
hopefully ends up somewhere not decoding the bogus frame.

If in decoding the frame at lower bound eof is still reached,
a seek error is thrown. This is reasonable, as lower bound should
be after the end of the last frame (not somewhere halfway a frame)
and if a corrupt frame is encountered, proper seeking cannot be
reasonably expected. It could be argued that it is still possible
to try and lower the upper bound by trying to decode a frame by
moving one byte backward at a time, looking for a frame, but this
will probably cause fuzzer timeouts and as said, proper seeking
in such a stream cannot be reaonably expected.

Credit: Oss-Fuzz
Issue: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=48077
2022-06-29 21:33:12 +02:00
Martijn van Beurden
b3c6fc2a04 Improve foreign metadata handling
Add options --keep-foreign-metadata-if-present and improve error
messages when on decoding the wrong type of foreign metadata is
found.
2022-06-28 07:11:16 +02:00
Martijn van Beurden
e6ff8b035a Always take compression level as first compression setting
Without this patch, the order of the arguments matter, with it
it does not: specific compression settings now always override
the more generic compression levels. This fixes issue
https://github.com/xiph/flac/issues/20
2022-06-27 07:31:42 +02:00
Martijn van Beurden
c94b4f8fbd Increase max bitreader size to max metadata block size
This fixes https://github.com/xiph/flac/issues/370
2022-06-26 07:42:18 +02:00
Cameron Cawley
f0f9deb5b2
Fix CMake builds with -DBUILD_CXXLIBS=OFF (#360) 2022-06-24 22:17:46 +02:00
Martijn van Beurden
287f777035 Do not add channel mask to vorbis_comment that will be reused later
This fixes https://github.com/xiph/flac/issues/376
2022-06-24 07:17:03 +02:00
Martijn van Beurden
cbb039d2d6 Fix assertion failure in seek_to_absolute_sample_
On fuzzing the assertion
'decoder->private_->last_frame.header.number_type ==
FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER' failed. This was because it
was possible to get there without having decoded a valid frame yet.

The checks are rearranged such that the code past this assertion is
only reached after it is made sure a valid frame has been decoded.
2022-06-15 07:46:48 +02:00
Martijn van Beurden
99cb7046f3 Fix bitreader bug, leaving bitreader in undefined state
When a call to read_callback failed in bitreader_read_from_client_
it left the bitreader buffer in a state where the last word was swapped
for endianness. While this wasn't ever a problem, recently code was
merged that rewound the bitreader in case a bogus frame was found.
If this happened, the bitreader buffer would be used in the state
where the last word in the buffer was still swapped. This commit
restores the last word of the buffer in case the call to the
read callback fails
2022-06-15 07:46:48 +02:00
Martijn van Beurden
12cf4b9c4e Fix two timeouts when decoding ogg
Fuzzing found timeouts occuring when processing garbage input with
the decoder trying to decode or seek in it assuming it to be an ogg
stream
2022-06-15 07:46:48 +02:00
Martijn van Beurden
bef0c92d05 Add check for unsigned integer underflow in seeking code 2022-06-15 07:46:48 +02:00
Martijn van Beurden
81c973fa1c Add new decoder fuzzer, mostly to cover seeking
This second decoder fuzzer dumps the fuzz input to a file, which enables
testing of seeking code
2022-06-15 07:46:48 +02:00
Martijn van Beurden
78d85dd4e4 Remove draft designation from isoflac.txt 2022-06-14 08:47:44 +02:00
Martijn van Beurden
73cb63a0e5 Add stats to encoder fuzzer on verify failure 2022-06-12 18:38:21 +02:00
Martijn van Beurden
a15ae334c9 Add 32-bit files to test 2022-06-12 18:38:21 +02:00
Martijn van Beurden
0fe187b545 Add 32-bit encoding, including limiting of residual to 32-bit int 2022-06-12 18:38:21 +02:00
Martijn van Beurden
9df24ac202 Add 32-bit decoding capability
Decoding for 32-bit files is added, including the ability to decode
a 33-bit side subframe. However, residuals are assumed to be limited
to a 32-bit signed int, the encoder must make sure of this
2022-06-12 18:38:21 +02:00
Martijn van Beurden
9b3826006a Change fuzzer_encoder_v2 timeout prevention 2022-06-11 22:44:16 +02:00
Martijn van Beurden
3528fa292a Check found metadata in decoder fuzzer
This greatly improves code coverage
2022-06-10 21:58:24 +02:00
Ralph Giles
c2daa37104 Remove obsolete ci/flac-autotool.sh
I think this is from the jenkins era. For a while we tried to
consolidate continuous-integration build descriptions across
services, but the formats are different enough that it's been
easier to use separate, per-service implementations.

In any case, this isn't used any more so there's no reason to
keep it around.
2022-05-30 20:32:03 -07:00
Ralph Giles
9fbccc9089 gitlab ci: Remove Makefile.lite job
This build system has been removed, so don't try to test it on
gitlab instances.
2022-05-30 20:32:03 -07:00
Ralph Giles
91cb661e0b Github actions: add make distcheck job
Add a github action to build and verify the traditional distribution
source package with GNU Autotools, also known as `make distcheck`.

This helps catch errors propagating required file list changes.

Co-authored-by: Martijn van Beurden <mvanb1@gmail.com>
2022-05-30 20:32:03 -07:00
martinRenou
39e6e570d8
Export flac properly when use with add_subdirectory (#285)
This allows for flac to be used in a larger CMake project
with add_subdirectory. It also allows for Ogg to be
build elsewhere in the larger project.
2022-05-30 20:22:45 +02:00
Martijn van Beurden
95064f9f08 Fix fuzzer_decoder timeouts
fuzzer_decoder was running into timeouts because it triggered the
gap-filling for broken frames with 5*192000 samples and a blocksize
of 1, causing the write callback to be called 960000 times. Doing
this several times in one file caused a single fuzz run to take
> 60 seconds

This commit limits the minimum blocksize to 16 samples, and the
maximum number of frames emitted to 50

Credit: Oss-Fuzz
Issue: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=47193
2022-05-29 21:08:29 +02:00
Martijn van Beurden
9e425621cc Close file when stream_encoder init fails 2022-05-28 22:28:21 +02:00
Martijn van Beurden
9e143766ca Only locally disable signed integer sanitizing on decoder fuzzers
See https://github.com/google/oss-fuzz/pull/7687
2022-05-28 07:31:37 +02:00
Martijn van Beurden
6b2fc739ed Improve compute_residual_from_qlp_coefficients datapath selection
This bases the selection of the datapath on the actual predictor
coefficients instead of on the predictor coefficient precision
2022-05-28 07:31:37 +02:00
Martijn van Beurden
dd4a263406 Remove Makefile.lite build system 2022-05-27 21:59:32 +02:00
Martijn van Beurden
1bb80c18da Small make distcheck fixes 2022-05-27 21:59:32 +02:00
Martijn van Beurden
e0e9cc58b4 Remove all Visual Studio specific build files 2022-05-27 21:59:32 +02:00
Martijn van Beurden
5705a61c55 fuzzer_encoder_v2, fix 32-bit input and seektable 2022-05-26 22:46:09 +02:00
Martijn van Beurden
febff86af0 Remove all assembler and intrinsics from decoder
This commit drops all use of assembler and intrinsics from the libFLAC
decoder. This is because they are only for 32-bit x86, hard to debug,
maintain and fuzz properly, and because the decoder has much greater
security risks than the encoder.
2022-05-26 11:04:05 +02:00
Martijn van Beurden
a67102694d Add extra check to decoding cpp example like in 93846ee
This fixes https://github.com/xiph/flac/issues/162

See also https://sourceforge.net/p/flac/bugs/418/
2022-05-23 06:53:07 +02:00
Martijn van Beurden
4dedae4f18 Renable escape coding for fuzzing
Escape coding has been deprecated since FLAC 1.0.4 (24-Sep-2002), but
it is needed for full spec coverage, (as this is a reference
implementation after all) so this should be reenabled at some point.

For now only enable while fuzzing, so we can get some bugs out first.
2022-05-22 10:53:56 +02:00
Martijn van Beurden
f44d5967fd
Fix compression of loose mid-side for certain kinds of music
The loose mid-side option only fully evaluates stereo decorrelation
once every few frames. However, in case of finding left-side or
right-side to be the best option, subsequent frames were coded
mid-side, which could be worse off. To not complicate code too much
(to make it possible to evaluate only left or right and side frame
for example), evaluation of left-side and right-side is completely
disabled when loose mid-side is enabled.
2022-05-21 20:06:57 +02:00
Martijn van Beurden
bcb7ed12b9 Default to picture type other when unknown picture type is found
When an unknown picture type was found, the resulting type wouldn't
occur in the enum, which is undefined behaviour. This commit changes
the picture type to 0 (other) when that happens.

Credit: Oss-Fuzz
Issue: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=46964
2022-05-20 22:48:38 +02:00
Martijn van Beurden
69cf76c58e Fix use of undefined value
The mechanism to improve metadata reading added in 0077d3b overrides
a FLAC__STREAM_DECODER_ABORTED with
FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC causing the decoder to
overread a buffer into an uninitialized part. A check is added that
ensures searching for frame sync is only set when the decoder is
still in a valid state

Credit: Oss-Fuzz
Issue: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=47525
2022-05-20 19:38:56 +02:00
Martijn van Beurden
43b6b64cad [CMake] Add /arch:avx2 flag, clarify WITH_SSE2 and WITH_AVX options
Adds /arch:avx2 to the avx2-specific source files. This mirrors the
current vcxproj files. While it currently brings no improvements,
it might if CPU-specific optimization is left to the compiler
instead of with hand-optimized code in the future

Also, the exact meaning of options WITH_SSE2 and WITH_AVX is
stated, as the first is compile-time only, and the second also
has runtime detection
2022-05-20 16:32:25 +02:00
Martijn van Beurden
7e4d8189d8 [CMake] Remove _FORTIFY_SOURCE=1 on not having libssp
Based on some information somewhere on the internet, CMakeLists.txt
sets _FORTIFY_SOURCE=2 when its runtime functions are available and
_FORTIFY_SOURCE=1 when they are not. However, _FORTIFY_SOURCE=1
also requires runtime functions.
2022-05-20 16:09:39 +02:00
Martijn van Beurden
5f4fa0ad73 Fix heap overflow when invalid encoder is used anyway 2022-05-19 20:22:09 +02:00
Martijn van Beurden
74b093f6e1 Fix initialization of encoder fuzzer (v1)
The encoder fuzzer initialized before setting up. This is now swapped
without upsetting the way the datasource is queried
2022-05-19 20:22:09 +02:00
Martijn van Beurden
383b77fa08 Let fuzzer_encoder_v2 use tmp files to improve coverage 2022-05-19 20:22:09 +02:00
Rosen Penev
2b4ba6013e
tests: Run through shellcheck (#134)
Signed-off-by: Rosen Penev <rosenp@gmail.com>
2022-05-18 21:27:19 +02:00
Martijn van Beurden
f180900b95 Fix memory leak
When resetting the decoder, the MD5 buffer wasn't freed but the pointer
set to zero anyway.
2022-05-18 17:12:28 +02:00
Martijn van Beurden
9e8d7389dc Fix initialization of decoder fuzzer
The decoder fuzzer initialized before setting up. This is now swapped
without upsetting the way the datasource is queried
2022-05-18 17:12:28 +02:00
Martijn van Beurden
e5e99dcdc2
Simplify and merge win_utf8 files and remove from DLL interface
libFLAC DLLs were exposing windows_unicode_filename.h functions
because flac and metaflac needed to set flac_internal_set_utf8_
filenames. Files windows_unicode_filename.{c/h} and
win_utf8_io.[c/h] are merged, and all non-utf8 parts are removed.

With this commit, the libFLAC DLL interface is the same as the
libFLAC interface of shared libraries on other platforms
2022-05-17 22:05:45 +02:00
Martijn van Beurden
3d40818489
Revert part of commit 5df56db
Commit 5df56db introduced four completely rewritten functions with
intrinsics, but it turns out two of them have integers that can
overflow. Because those two functions were barely faster than
what they replaced, fixing these overflows will probably make the
functions slower than what they replaced, so this is reverted.

Credit: Oss-Fuzz
Issue: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=47416
2022-05-16 19:41:59 +02:00
Martijn van Beurden
61649d09aa
Add checks for decoding from and encoding to UTF-8 filenames 2022-05-12 22:21:39 +02:00
Martijn van Beurden
1bec35e337 Add residual limit checking
This patch adds a (fast) check in the bitreader to detect overflow
of the residual
2022-05-11 10:34:49 +02:00
Martijn van Beurden
becba351f0 Make it possible for fuzzer to disable instruction set optimizations
This should greatly increase code coverage of the encoder fuzzer
2022-05-11 10:34:49 +02:00