4113 Commits

Author SHA1 Message Date
Martijn van Beurden
fbb6cb5c07 Add OOM checking to fuzzing 2022-08-20 16:03:53 +02:00
Martijn van Beurden
707dace4bd Leave metadata items untouched if resize function fails 2022-08-20 16:03:53 +02:00
Martijn van Beurden
21fe95ee82 Add and use _nofree variants of safe_realloc functions
Parts of the code use realloc like

x = safe_realloc(x, somesize);

when this is the case, the safe_realloc variant used must free the
old memory block in case it fails, otherwise it will leak. However,
there are also instances in the code where handling is different:

if (0 == (x = safe_realloc(y, somesize)))
    return false

in this case, y should not be freed, as y is not set to NULL we
could encounter double frees. Here the safe_realloc_nofree
functions are used.
2022-08-20 16:03:53 +02:00
lutianxiong
b715d7b9fe fix potential memleak 2022-08-20 16:03:53 +02:00
Martijn van Beurden
35306a812b
Introduce subdivide_tukey apodization
Subdivide_tukey is intended to replace partial_tukey and
punchout_tukey. It works in rougly the same way, but uses a more
efficient algorithm, recyling more data.

subdivide_tukey has 2 arguments, of which 1 is optional. The
first states the maximum number of parts the signal has to be
split up in, the second is the tukey parameter, divided by the
max num of parts.

subdivide_tukey(3) analyses audio with an unsplit block, with the
block split in 2 and split in 3. Here the default p of 0.5 applies
to the smallest parts, so the unsplit block effectively has a p of
0.5/3. subdivide_tukey(3/2e-1) does the same but with p of 0.2.
2022-08-19 20:56:24 +02:00
Martijn van Beurden
6d2492d346
Prepare oom checking in fuzzing
By merging oom checking in fuzzing in steps, it is possible to
implement it without having oss-fuzz build failures
2022-08-19 11:59:16 +02:00
Martijn van Beurden
010c60e1f9
Add configure option to not build programs 2022-08-13 15:20:42 +02:00
Martijn van Beurden
9bc2cc4c3b
Remove really old --explain text and reflow to fit 80 chars
There was some help text in `flac --explain` which hasn't been
correct for about 20 years already. This is removed, the rest of
the text is reflowed to fit 80 chars standard terminal width
2022-08-10 19:12:00 +02:00
Martijn van Beurden
80d064e15d
Convert docbook to markdown
Currently, the man pages are converted from a docbook document, but
the conversion doesn't seem very reliable. Also, the man page is
more-or-less duplicated by the html documentation.

This commit moves all tool documentation to a markdown document which
is readable by itself and can be converted by pandoc to a man page
and can be used by Jekyll to populate the website.
2022-08-09 21:26:19 +02:00
Martijn van Beurden
4f40fa8433
Move changelog to markdown and top directory, add changes in git 2022-08-08 12:55:50 +02:00
pkubaj
349cc0700a
Fix HAVE_GETAUXVAL check for FreeBSD (#410)
FreeBSD doesn't have getauxval().
2022-08-07 21:47:01 +02:00
Martijn van Beurden
3022dad831
Fix and warning for MSVC with Windows XP toolset (#399)
A warning and a small workaround is added for building
libFLAC on MSVC with a specific Windows XP targeting toolset.
2022-08-06 20:32:28 +02:00
Martijn van Beurden
428e681784 [CMake] Don't search for libiconv and libintl on Windows
The functions these libs provide don't seem to be used on Windows
anyway. This fixes https://github.com/xiph/flac/issues/249
2022-08-01 21:02:03 +02:00
Martijn van Beurden
4e823662ec Fix decoding of 33 bps constant subframe 2022-07-31 21:58:07 +02:00
Martijn van Beurden
10e34d444a Also add trailing nul to empty vorbis comment entries
This might fix https://github.com/xiph/flac/issues/48 I cannot
check as I don't have a file to test with. Besides returning an
empty string upon reading, also allocate empty strings when growing
vorbiscomments
2022-07-28 17:44:24 +02:00
Martijn van Beurden
6a9d952f6c Check for vorbis comment entry being not null in fuzzer 2022-07-28 17:44:24 +02:00
Martijn van Beurden
05ff569266 Finish porting guide 2022-07-27 22:16:04 +02:00
Martijn van Beurden
42201ae575 Add porting guide stub 2022-07-27 22:16:04 +02:00
Martijn van Beurden
10d7ce268b Bulk update copyright dates to 2022 2022-07-26 16:23:07 +02:00
Martijn van Beurden
c6a4d5c07b
Add FMA intrinsics for autocorrelation calculation
See https://github.com/xiph/flac/pull/387 for details
2022-07-25 12:07:24 +02:00
Martijn van Beurden
67131c04b8 Include stddef.h in compat.h
See https://github.com/xiph/flac/issues/76 for details

Also, move include of stddef.h and stdarg.h up to top of file to
make clear that they are included unconditionally
2022-07-19 17:33:29 +02:00
Martijn van Beurden
99885d3d64 Fix rolled up version of lpc_restore_signal_wide
This fixes https://github.com/xiph/flac/issues/393
2022-07-17 22:32:02 +02:00
Martijn van Beurden
d3b8947b73 Improve tempfile generation of fuzzer_metadata 2022-07-16 21:11:16 +02:00
Martijn van Beurden
5186025b94 Re-add check for block align
In 2003, in commit 94f81b0, a check was added for the block align
field in WAVE. If it contradicts other parts of the header, an error
was raised. This was (probably erroneously) made inactive with #if 0
in commit 13c63e4. This commit reactivates the check and removes the
rest of the inactivated code.
2022-07-16 15:19:52 +02:00
Martijn van Beurden
77521a7d67 Eliminate race conditions in fuzzer_metadata file access
See https://github.com/google/oss-fuzz/issues/8006 for details
2022-07-15 07:46:26 +02:00
Martijn van Beurden
48d4f81211
Revert "Enable encoder to use INT32_MIN as residual value" (#389)
This reverts commit 7e0a0e572305e9004a6fa9bba3dd6be936553b03,
following the change to the FLAC format proposed here:
https://github.com/ietf-wg-cellar/flac-specification/pull/148

It turns out supporting use of INT32_MIN is quite a hassle.
2022-07-13 20:57:15 +02:00
Martijn van Beurden
43a93a00e4 Only search for backslash in filename on Windows 2022-07-13 09:11:05 +02:00
Martijn van Beurden
772efde6a7 Check first metadata block is streaminfo in level 1 metadata iterator
In simple_iterator_prime_input_ there was no check whether the first
metadata block is a streaminfo block. As the rest of the functions
operate under the assumption the first block is a streaminfo block,
for example to prevent the functions from deleting the last block
and being left with an iterator pointing nowhere, this check is
added.
2022-07-07 22:06:14 +02:00
Martijn van Beurden
b963ce0873 Check chain length Ogg FLAC file
When a metadata chain was read from an Ogg FLAC file containing no
metadata (but otherwise valid), an empty chain could be returned,
leading to null derefencing on trying to manipulate it. This commit
adds a check for the chain length
2022-07-07 22:06:14 +02:00
Martijn van Beurden
46f3f36772 Fix dereferencing of null pointer in metadata_iterators.c 2022-07-07 22:06:14 +02:00
Martijn van Beurden
f3864bf1f6 Add limits to metadata reading
In commit 0077d3b checks were added for metadata reading in the
stream decoder. However, the metadata interface suffers from the
same problems. Similar to the mentioned commit, checks are added.
2022-07-07 22:06:14 +02:00
Martijn van Beurden
da7b9a0ced Add fuzzer_metadata 2022-07-07 22:06:14 +02:00
Martijn van Beurden
7e0a0e5723 Enable encoder to use INT32_MIN as residual value
As abs(INT32_MIN) is undefined, it took some extra work to enable
the encoder to do this. While expected gains are zero, this is
done to ensure full spec coverage in this regard
2022-07-01 21:51:31 +02:00
Martijn van Beurden
633ab36ec5
Small fixes needed for 32-bit capability (#379)
* Change replaygain analysis so it is able to handle 32-bit PCM
* Increase FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE to 32
* Fix switch-case fallthrough
2022-07-01 07:36:48 +02:00
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