Commit Graph

4474 Commits

Author SHA1 Message Date
manx 31ccd3df31
Use correct argument type for _BitScanReverse and _BitScanReverse64. (#638)
_BitScanReverse and _BitScanReverse64 are documented to take an `unsigned long *` as the first argument (see <https://learn.microsoft.com/en-us/cpp/intrinsics/bitscanreverse-bitscanreverse64?view=msvc-170>), however libFLAC used `uint32_t` which happens to be `unsigned int`.

This silences Clang warning `incompatible pointer types passing 'uint32_t *' (aka 'unsigned int *') to parameter of type 'unsigned long *' [-Wincompatible-pointer-types]`.

Fixes https://github.com/xiph/flac/issues/637
See also https://github.com/xiph/flac/pull/638 for comments
2023-07-27 12:11:07 +02:00
Martijn van Beurden 6c126e9308
Limit the number of clock() calls
The overhead of calling clock() when encoding/decoding very small
frames turned out to be very large, for framesize 16 these syscalls
took over half the execution time. This commit only calls clock()
when at least 10.000 samples have been encoded or 25.000 samples
have been decoded since the last call to clock()
2023-07-07 20:31:23 +02:00
Martijn van Beurden 28e4f0528c
Release FLAC 1.4.3 2023-06-23 09:17:08 +02:00
Martijn van Beurden c7fc1768e8
Fix library version numbers/sonames 2023-06-21 17:09:24 +02:00
Martijn van Beurden 08f8af0845
Improve on "Check for got_stream_info instead of samplerate being 0"
This improves on commit 6db29d1. It turns that commit broke some
parsing, this fixes it
2023-06-18 20:32:27 +02:00
Martijn van Beurden d80e574451
Explain use of errno with callbacks 2023-06-16 06:46:57 +02:00
Martijn van Beurden 4f9be8620b
Add github action to check against flac test files 2023-06-15 19:46:38 +02:00
Martijn van Beurden e00d9b881f
Update copyright year and maintainer status 2023-06-06 22:08:24 +02:00
Martijn van Beurden 7f89a74cb2
Slim down CI 2023-06-06 18:03:32 +02:00
Martijn van Beurden c0fc3c73e2
Update changelog 2023-06-06 09:30:50 +02:00
Martijn van Beurden fd890034a5
Fix compression level 8 in API docs 2023-06-01 19:16:03 +02:00
Martijn van Beurden 6a9c1664b3
Check that seektable length > 0 2023-06-01 16:50:27 +02:00
Martijn van Beurden d6974b9702
Remove sector align option
This option has been deprecated since FLAC 1.3.0.
2023-05-31 21:49:44 +02:00
Martijn van Beurden 1619af5a36
Update changelog and library version numbers 2023-05-30 07:41:35 +02:00
Martijn van Beurden 0b8a271b3e
Fix version number display on Windows
This adds windows-specific version information to build objects

Co-authored-by: Ozkan Sezer <sezeroz@gmail.com>
2023-05-24 14:52:13 +02:00
dmitrykos 6571cbbf17 Fixed compile error under Windows if winapifamily.h is unavailable (regression of fd842b6a3b). 2023-05-23 12:05:58 +02:00
Martijn van Beurden c8e6f7372c
Prevent overflow when parsing RIFF fmt chunk 2023-05-22 21:21:33 +02:00
Martijn van Beurden 9e157b5e1e
Explain that --with-filename does not work with --export options 2023-05-22 12:02:41 +02:00
Martijn van Beurden 7761f5472c Check for FLAC__STREAM_DECODER_ABORTED on reencoding
This status was ignored, leading to an infinite loop
2023-05-20 07:29:04 +02:00
Martijn van Beurden 808efb3287 Explicitly check for bps == 0 when applying replaygain
During application of replaygain, bps is checked to be > 0. This
should never happen in a valid file. This check is specific for
replaygain application instead of more generic (at streaminfo)
because we still want to be able to recover files in which
streaminfo is invalid or missing.
2023-05-20 07:29:04 +02:00
Martijn van Beurden 69155423c4 Check for replaygain peak value being positive on parsing 2023-05-20 07:29:04 +02:00
Martijn van Beurden 890912644a Add seed corpus files for fuzzer_tool_flac 2023-05-20 07:29:04 +02:00
Martijn van Beurden ef34ee5269 Small correction on commit 7ed6f4f
The 4 byte application id was not considered

Credit: Oss-Fuzz
Issue: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=59015
2023-05-17 21:44:32 +02:00
Martijn van Beurden f18692df18 Add OOM check to metaflac append handling
Credit: Oss-Fuzz
Issue: N/A
2023-05-17 21:44:32 +02:00
Martijn van Beurden 7ed6f4ff58 Throw error on too large foreign metadata directly
Previously, too large chunks of foreign metadata (> 16MiB) were
signalled by libFLAC, throwing an error upon adding the metadata,
so flac gave a rather vague error back to the user. This commit
adds detection to the foreign metadata handling, so the user gets
a much clearer error.

Credit: Oss-Fuzz
Issue: N/A
2023-05-11 17:20:30 +02:00
Martijn van Beurden c65ef58924 Stop processing subframes when invalid data is found
This fixes https://github.com/xiph/flac/issues/580

The problem was that after encountering a problem in a first
subframe, the state was changed from READ_FRAME to
SEARCH_FOR_FRAME_SYNC, which meant a problem in the second
subframe was interpreted as a read error instead of invalid data.

With this patch, processing of subframes is stopped after setting
SEARCH_FOR_FRAME_SYNC
2023-05-11 09:01:44 +02:00
Martijn van Beurden c623f0f42c Fix use-after-free warning in GCC 12
A pointer was used for arithmatic after a realloc.

Co-authored-by: Alexia Massalin <alexia@lambda.csail.mit.edu>
2023-05-09 20:29:05 +02:00
DK fd842b6a3b
Fixed compilation of get_utf8_argv() for Windows UWP
Fixed compilation in Win32 environment.
Use FLAC_WINDOWS_APP define to check between UWP app and Win32 for more consistency.
2023-05-09 14:37:57 +02:00
Martijn van Beurden 22fffdceb8 Check for overflow when multiplying skip samples with sample size
Credit: Oss-Fuzz
Issue: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=58606
2023-05-08 19:39:08 +02:00
Martijn van Beurden afad04f0a9 Fix undefined shift
Credit: Oss-Fuzz
Issue: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=58602
2023-05-08 19:39:08 +02:00
Martijn van Beurden ebc2a69697 Fix mistake in eba4b6f and add check to seektable_is_legal
Credit: Oss-Fuzz
Issue: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=58546
2023-05-08 19:39:08 +02:00
Martijn van Beurden 183b22ac32 When outputting partial frame, emulate verbatim frame
After seeking, a partial frame is passed to the write callback.
The FLAC__Frame passed there only has its blocksize and sample
number changed to accomodate. This results in several 'rules'
being violated. For example, the predictor order can be larger
than the blocksize. This caused integer underflow in the analysis
output of the flac command line program, causing heap overflow.
Also, the output analysis data is junk, because the residual and
rice parameters are not changed accordingly, as this would
violate other things that are otherwise given, like the number
of rice partitions being a power of 2.

To remedy this, a FLAC__Frame is now output stating that all
subframes are of the verbatim type, which has no restrictions
like fixed and lpc subframes have.

A better remedy will have to wait to the next API change, to
introduce a few new subframe types for this case and the case
of conveying an unreadable frame.

Credit: Oss-Fuzz
Issue: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=58481
2023-05-08 19:39:08 +02:00
Martijn van Beurden 4caaef6bf4
Fix compilation of getopt1.c on Intel Compiler with LLVM backend
This mirrors a change in 2005 to the GCC getopt1.c.
2023-05-05 09:20:19 +02:00
Martijn van Beurden 1b92b86ac9 Check for samplerate != 0 before dividing by it
Credit: Oss-Fuzz
Issue: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=58199
2023-05-04 20:48:36 +02:00
Martijn van Beurden 365c7aa92e Add another check for overflow in cuesheet parsing code
Credit: Oss-Fuzz
Issue: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=58406
2023-05-04 20:48:36 +02:00
Martijn van Beurden af6df3b953 Fix cuesheet parsing code skipping a digit
The code parsing cuepoints of the form MM:SS.SS, which is only
allowed for non-CDDA, had a bug where the first S of the above
template was skipped. That meant that 00:12.34 was parsed as
00:02.34. This is not covered in the test suite, but fuzzing
stumbled on it as 00: as input made the parser skip the string-
terminating nul.

Credit: Oss-Fuzz
Issue: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=57320
2023-05-04 20:48:36 +02:00
Martijn van Beurden 321c4aeb22 Remove files generated during fuzzing of metaflac tool
Similar to commit 5008827
2023-05-04 20:48:36 +02:00
Martijn van Beurden db57fe14c2 Revert exclusion of stdin code for fuzzer_tool_metaflac
When building the tool fuzzers, I excluded some code reading from
stdin because it caused blocking of the fuzzer (i.e. timeouts).
However, the fuzzer now handles stdin, so these exclusions can be
removed
2023-05-04 20:48:36 +02:00
Martijn van Beurden 2e14bc19a9 Reject floating point value with exponent == 63
This prevent shifting with a negative number (which is undefined
behaviour) and such values are too large to process anyway.

Credit: Oss-Fuzz
Issue: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=58077
2023-05-03 07:27:07 +02:00
Martijn van Beurden 946c25de76 Check for overflow when converting skip and until to samples
Credit: Oss-Fuzz
Issue: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=57409
2023-05-03 07:27:07 +02:00
Martijn van Beurden 4f81ef46c9 Handle case where lookahead length is larger than read size ...
... for raw input

This can happen when --until is used on a very short raw file.

Credit: Oss-Fuzz
Issue: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=58536
2023-05-02 07:34:12 +02:00
Martijn van Beurden 072cfdf5b2 Try to fix unreproducible memory leak in metaflac
It seems the fuzzer tries to add a picture file, for which the
file was available during fuzzing but not during reproducing. This
fix seems the most logical place it was failing.

Credit: Oss-Fuzz
Issue: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=58371
2023-05-02 07:34:12 +02:00
Martijn van Beurden 645d651e83 Only unset 'first' after successful execution
'first' was handed to flac__encode_file on the first file of a
set, to let that function know replaygain needs to be initialized.
However, when processing of the first file fails, the second file
uses replaygain uninitialized.
2023-04-28 23:08:58 +02:00
Martijn van Beurden 189cbaabd8 Only invalidate last seen framesync when actually emptying buffer
The last seen framesync in the bitreader was invalidated when
reading new data in. However, data only leaved the buffer when
more than one word has been fully read. When an invalid frame is
read and reading is aborted within less than a wordlength because
of reaching end-of-stream, the read_from_client had invalidated
the last seen framesync, causing rewinding to the start of the
bitreader. This causes an infinite loop, syncing on the same
pattern every time.
2023-04-28 23:08:58 +02:00
Martijn van Beurden ec4e5aa95d Add flac tool fuzzer dictionary 2023-04-28 23:08:58 +02:00
Martijn van Beurden 763e185671 Hide unreproducible bug that is probably harmless
Issue https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=56395
remains unreproducible to me, and the whole problem doesn't seem
to make any sense. Even downloading the affected build and running
it locally doesn't reproduce the problem.

As this is probably a harmless bug (if it is a bug) that is
triggered by an assert but is handled anyway, I'm hiding the assert
so the handling is fuzzed when the assert is removed, as in
production code.
2023-04-28 11:43:38 +02:00
Martijn van Beurden c7861aa846 Also apply shift to raw data
This change only applies when bitdepth changes halfway a stream.
It is more a technicality that needs fixing because of fuzzing than
an actual problem

Credit: Oss-Fuzz
Issue: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=58357
2023-04-28 11:43:38 +02:00
Martijn van Beurden 147cfc8df4 Do not use main output buffer when outputting padding frames
Currently, when the decoder finds that it is missing some data,
it will fill that up with silence. However, it uses the output
buffer for that, overwriting the last decoded data. Therefore,
more data is dropped than is necessary. This also leads to a
heap use after free when a buffer resize is needed to accomodate
the silence data and the frame data is used for analysis

Credit: Oss-Fuzz
Issue: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=57354
2023-04-25 07:38:58 +02:00
Martijn van Beurden 01fb06103d Fix mistakes in 29d1460 and simplify
Return false was used instead of return -1. Also, overflow is
checked with signed int, which triggers the undefined behaviour
sanitizer. Instead, be a little more strict, such large values
aren't useful in this context anyway.

Credit: Oss-Fuzz
Issue: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=58268
2023-04-25 07:38:58 +02:00
Martijn van Beurden 3e3b4407ae Add check for samplerate == 0 when parsing cuesheets
Credit: Oss-Fuzz
Issue: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=58199
2023-04-25 07:38:58 +02:00