Commit Graph

2488 Commits

Author SHA1 Message Date
Erik de Castro Lopo
3982865e97 libFLAC/bitwriter.c: Fix undefined behaviour 2015-08-31 00:22:12 +10:00
Erik de Castro Lopo
1b8af6bb45 libFLAC/fixed.c: Fix undefined behaviour
Left shift if a negative integer such that the sign bit is affected is
(according to the C spec) undefined behaviour and the residual
calculations using the shift operator were hitting this.

Fortunately these same calculations using plain multiplication do not
invoke UB and according to benchmarking (on x86_64 linux) have the same
performance as the bit shift version.
2015-08-29 05:22:22 +10:00
Erik de Castro Lopo
25d387377a tests: Fix undefined behaviour
Undefined behaviour in the test support code.
2015-08-27 09:34:43 +10:00
Erik de Castro Lopo
a14581642c libFLAC/format.c: Fix undefined behaviour
In the case where seek_table->num_points is zero, seek_table->points
will be NULL and passing that to qsort() invokes undefined behaviour.

Since seek_table->num_points is zero, the only sensible thing to do
is to short circuit return 0.
2015-08-26 17:21:36 +10:00
Erik de Castro Lopo
fb273e469e libFLAC/stream_decoder.c: Fix undefined behaviour
Found by compiling with -fsanitize=undefined and running the testsuite.
2015-08-24 19:21:51 +10:00
Erik de Castro Lopo
e3c8095336 libFLAC/bitwriter.c: Fix undefined behaviour
Improve folding of signed to unsgned to avoid UB.
2015-08-23 08:51:44 +10:00
Erik de Castro Lopo
b18d8d50bd libFLAC/bitreader.c: Fix undefined behaviour
The function FLAC__bitreader_read_raw_int32() triggered undefined behaviour
when sign extending an unsigned value. The Stanford Grahpics bithacks page
provided an alternative that avoided UB.
2015-08-23 08:50:33 +10:00
Erik de Castro Lopo
d9503c8458 libFLAC/md5.c: Clean up allocation
Make sure ctx->capacity gets updated correctly when safe_realloc()
fails.

Patch-from:  lvqcl <lvqcl.mail@gmail.com>
2015-08-23 07:37:56 +10:00
Erik de Castro Lopo
584a1346c9 libFLAC: Fix memory leak
Leak introduced in commit d9ae5e9128. Thanks to lvqcl <lvqcl.mail@gmail.com>
for pointing it out.
2015-08-22 20:28:47 +10:00
Erik de Castro Lopo
d9ae5e9128 libFLAC: Add function safe_realloc_()
The new function wraps, realloc() and if the realloc() fails, it
free()s the old pointer.

This is an improvement on the potential realloc() memory leak that
was fixed in 15a9062609.

Still needs fuzzing to validate it.
2015-08-22 19:39:37 +10:00
Erik de Castro Lopo
684fb3d544 libFLAC/stream_decoder: Fix double free
The american-fuzzy-lop fuzzer found a couple of instances of double
free() resulting from commit 15a9062609.

The problematic free() were the ones associated with use of the
safe_realloc_mul_2op_() function which can call realloc(ptr,0) which
according to the realloc manpage is already an implicit free().
2015-08-22 19:25:39 +10:00
Ben Boeckel
f7c52c8aa8 metaflac: add --scan-replay-gain option
Signed-off-by: Erik de Castro Lopo <erikd@mega-nerd.com>
2015-08-14 06:21:26 +10:00
Erik de Castro Lopo
15a9062609 libFLAC: Fix potential meory leaks
If the `realloc` function failed, memory would leak.

Patch-from: lvqcl <lvqcl.mail@gmail.com>
2015-08-09 14:32:11 +10:00
Erik de Castro Lopo
7083cf2d90 decoder: Treat negative qlp_shift as an error
Shift by a negative value is undefined behaviour so there is no "right"
way of dealing with this.

Patch-from: lvqcl <lvqcl.mail@gmail.com>
2015-08-09 08:50:35 +10:00
Erik de Castro Lopo
4f84da5dd4 Windows: Ensure FreeLibrary() calls match LoadLibrary() calls
The function get_utf8_argv() was calling LoadLibrary to load msvcrt.dll
but wasn't calling FreeLibrary() if GetProcAddress() fails.

Patch-from: lvqcl <lvqcl.mail@gmail.com>
2015-08-09 08:49:06 +10:00
Erik de Castro Lopo
92285393ca flac/metaflac: Do case-insensitve comparison of hex values
Patch-from: lvqcl <lvqcl.mail@gmail.com>
2015-08-09 08:48:57 +10:00
Erik de Castro Lopo
6ced857c25 libFLAC: Fix decoder_flush with uninitialized decoder
Closes: https://sourceforge.net/p/flac/bugs/428
2015-07-13 22:20:29 +10:00
Erik de Castro Lopo
cf7442d638 libFLAC/cpu.c: Assume Android has SSE
According to https://developer.android.com/ndk/guides/abis.html#x86
Android always support SSE, so there's no need to test SSE OS support.

Why both __ANDROID__ and ANDROID are tested:
http://stackoverflow.com/questions/15328751/android-macro-suddenly-not-defined
http://stackoverflow.com/questions/6374523/how-to-detect-compilation-by-android-ndk-in-a-c-c-file
https://groups.google.com/forum/#!topic/android-ndk/cf9_f1SLXls

Patch-from: lvqcl <lvqcl.mail@gmail.com>
2015-07-13 22:20:29 +10:00
Erik de Castro Lopo
e771e7b6a7 flac/foreign_metadata: Fix for odd RIFF chunk size
Accept odd values to ckSize of RIFF chunk. FLAC should read these
but should avoid creating them.

Patch-from: lvqcl <lvqcl.mail@gmail.com>
Closes: https://sourceforge.net/p/flac/support-requests/152/
Closes: https://sourceforge.net/p/flac/bugs/419/
2015-07-10 19:22:39 +10:00
Erik de Castro Lopo
0cacc0c09f libFLAC/metadata_object.c: Assign NULL after free()
Patch-from: lvqcl <lvqcl.mail@gmail.com>
2015-07-06 21:30:58 +10:00
Erik de Castro Lopo
a45af0ceaf libFLAC/md5.c: Minor formatting fixes
Patch-from: lvqcl <lvqcl.mail@gmail.com>
2015-07-06 21:29:40 +10:00
Erik de Castro Lopo
ff50779e44 libFLAC: More comment validation
When the allocation for obj->comment fails, set obj->num_comments
to zero.

Patch-from: lvqcl <lvqcl.mail@gmail.com>
2015-07-05 21:21:48 +10:00
Erik de Castro Lopo
d939b44a20 libFLAC: Improve fix in bc5113007a
The assert that was removed in bc5113007a, was a result of error
handling in read_metadata_vorbiscomment_() which set obj->num_comments
to zero, without freeing obj->comments and setting it to NULL.

This commit also restores the assert that was removed.
2015-07-05 20:57:39 +10:00
Erik de Castro Lopo
bc5113007a libFLAC: Remove un-needed assert
This asset was firing when the build was configured with --enable-debug
and the flac executable was then run under American Fuzzy Lop. Removing
the assert did not cause any other problems, even under AFL.
2015-07-04 16:27:33 +10:00
Erik de Castro Lopo
48ff5ee89d replaygain: Remove dead assignment
Patch-from: lvqcl <lvqcl.mail@gmail.com>
2015-07-04 12:36:28 +10:00
Erik de Castro Lopo
b105f9ad93 libFLAC: Remove un-needed test for NULL before free
Passing a NULL pointer to free() is a no-op.
2015-07-04 12:36:28 +10:00
Erik de Castro Lopo
ccb5a4debd flac: Fix inlining failure warning
Also remove related, but old and irrelevant comment.
2015-07-04 11:51:33 +10:00
Erik de Castro Lopo
d9aa331ce4 grabbag: Replace strncpy with safe_strncpy
Patch-from: lvqcl <lvqcl.mail@gmail.com>
2015-07-04 09:15:27 +10:00
Erik de Castro Lopo
bc1f15db29 Remove old incorrect comment
As discussed on the flac-dev mailing list.

Patch-from: lvqcl <lvqcl.mail@gmail.com>
2015-04-25 08:16:34 +10:00
Erik de Castro Lopo
ef9f7998fd src/libFLAC/lpc.c : Restore missing conditional.
Git commit 9c2290ade5 in-correctly removed a conditional around
an fprintf. Thanks to mark4o on #xiph (freenode) for reporting
this.
2015-03-31 10:14:17 +11:00
Erik de Castro Lopo
ab7ab03bfa src/test_streams/main.c : Use flac_snprintf() instead of snprintf().
MSVC doesn't have snprintf().

Patch-from: lvqcl <lvqcl.mail@gmail.com>
2015-02-25 06:48:31 +11:00
Erik de Castro Lopo
29db3fbf1c Fix cursheet tests for 'make distcheck'. 2015-02-24 06:06:10 +11:00
Erik de Castro Lopo
8267168d28 src/encode.c : Fix potential infinite loop in flac-toflac encoding.
A malformed file (generated by AFL) had a 'samples_left_to_process' value
of greater than the actual numbe of samples. When re-encoding the decoder
would get to the end of the file and then continuously return a decode
status of FLAC__STREAM_DECODER_END_OF_STREAM, causing an infinite loop.

Solution is to break out of the loop on two consecutive end-of-stream
events.
2015-02-22 21:44:27 +11:00
Erik de Castro Lopo
c431a6c581 libFLAC/metadata_object.c : Fix typo in comment. 2015-02-21 07:05:21 +11:00
Miroslav Lichvar
fed0dfa108 src/libFLAC/stream_decoder.c : Rework fix for seeking bug.
To avoid crash caused by an unbound LPC decoding when predictor order is
larger than blocksize, the sanity check needs to be moved to the subframe
decoding functions.

Signed-off-by: Erik de Castro Lopo <erikd@mega-nerd.com>
2015-02-18 17:19:19 +11:00
Erik de Castro Lopo
033af7bf1c libFLAC : Put upper bound on number of seek points.
Restrict number of seek points to 32768 total and a maximum of two per
second.

Ten hours of content is 36000 seconds which gives about one seek point
for every second for those ten hours. Also, having more than two seek
point per second makes little sense regardless of content length.

Without these restrictions flac-to-flac encoding of a malformed input
file (eg something generated with http://lcamtuf.coredump.cx/afl/)
can result in an attempt to generate a stupidly large number of seek
points and cause an allocation failure.
2015-02-18 10:13:53 +11:00
Erik de Castro Lopo
c06a44969c flac : Fix for https://sourceforge.net/p/flac/bugs/425/
* flac/encode.c : Validate num_tracks field of cuesheet.
* libFLAC/stream_encoder.c : Add check for a NULL pointer.
* flac/encode.c : Improve bounds checking.

Closes: https://sourceforge.net/p/flac/bugs/425/
2015-02-18 09:49:08 +11:00
Erik de Castro Lopo
7c3cd3d908 Update grabbag tests to work out-of-tree. 2015-02-15 20:37:40 +11:00
Erik de Castro Lopo
b903670f21 replaygain test: Use C code to generate test files. 2015-02-15 16:48:46 +11:00
Erik de Castro Lopo
a0277fc637 src/test_streams/ : Pull out write_simple_wavex_header() for reuse. 2015-02-13 10:53:46 +11:00
Erik de Castro Lopo
875be0ada5 src/libFLAC/stream_decoder.c : Fix NULL de-reference.
NULL de-reference can really only happen on a malformed file.
Found using afl (http://lcamtuf.coredump.cx/afl/).
2014-12-22 09:05:09 +11:00
Erik de Castro Lopo
775eb934f7 src/flac/decode.c : Add WAVEFORMATEXTENSIBLE to WAV files as needed.
Patch-by: lvqcl <lvqcl.mail@gmail.com>
2014-12-14 20:00:37 +11:00
Karthik Periagaram
f8255f2b7a Spelling and grammar fixes for console output
This commit fixes a typo in a console debug message encountered during
encoding. It also fixes a grammatical error in the same message.

Signed-off-by: Erik de Castro Lopo <erikd@mega-nerd.com>
2014-12-14 17:59:47 +11:00
Erik de Castro Lopo
18a4854510 stream_decoder.c : Fix free-ing of unitilialized pointer.
Found using afl (http://lcamtuf.coredump.cx/afl/).
2014-12-12 06:51:38 +11:00
Erik de Castro Lopo
b4b2910bdc src/libFLAC/stream_decoder.c : Fix seek bug.
Janne Hyvärinen reported a problem with seeking as a result of the
fix for CVE-2014-9028. This is a different solution to the issue
that should not adversely affect seeking.

This version of the fix for the above CVE has been extensively fuzz
tested using afl (http://lcamtuf.coredump.cx/afl/).

Reported-by: Janne Hyvärinen <cse@sci.fi>
2014-12-11 11:17:03 +11:00
Erik de Castro Lopo
3ff1b9d3f0 flac/vorbiscomment.c : Fix typo.
Patch-from: Jan Stary <hans@stare.cz>
2014-12-09 06:04:49 +11:00
Erik de Castro Lopo
eb753ae5b4 Remove traiing whitespace (mostly .c and .h files).
Patch-from: lvqcl <lvqcl.mail@gmail.com>
2014-12-05 05:52:30 +11:00
Martijn van Beurden
c97e057ee5 Improve LPC order guess
The recent compression preset retuning improved upon most material
but it the few tracks that show regression are usually classical
music. This patch improves compression by improving the LPC order
guess, of which classical music benefits most.

Improvement is 0.007% on average but up to 0.1%. I haven't seen
regressions for any of my test samples.

Signed-off-by: Erik de Castro Lopo <erikd@mega-nerd.com>
2014-12-05 05:50:24 +11:00
Erik de Castro Lopo
ac0b4b4cab Improve encoding speed on older Intel CPUs.
The commit http://git.xiph.org/?p=flac.git;a=commit;h=e9d805dd4374
changed the that calculate autocorrelation. However, the new code
worked slightly (about 4%) slower on Core 2, but with the new
presets the speed decrease can reach ~25%.

This patch enables both old and new functions and chooses between
them at runtime.

Patch-from: lvqcl <lvqcl.mail@gmail.com>
2014-12-04 21:03:06 +11:00
Erik de Castro Lopo
d03c9f46be src/flac/main.c : Fix an output line > 81 characters in length.
Requested-by: lvqcl <lvqcl.mail@gmail.com>
2014-12-04 21:01:23 +11:00