2 years agocpu.c: Merge ia32 and x86_64 CPU info functions
Erik de Castro Lopo [Mon, 27 Feb 2017 09:35:21 +0000 (20:35 +1100)]
cpu.c: Merge ia32 and x86_64 CPU info functions

After the removal of the OS SSE detection stuff ia32_cpu_info()
and x86_64_cpu_info() became very similar. Merging them makes

Patch-from: lvqcl <lvqcl.mail@gmail.com>

2 years agocpu.c: Fix debug Windows w32 build issue
Erik de Castro Lopo [Thu, 23 Feb 2017 07:58:44 +0000 (18:58 +1100)]
cpu.c: Fix debug Windows w32 build issue

Was failing to build without NASM.

Patch-from: Olivier Tristan <o.tristan@uvi.net>

2 years agostream_decoder.c: Comments
Erik de Castro Lopo [Tue, 21 Feb 2017 19:16:38 +0000 (06:16 +1100)]
stream_decoder.c: Comments

Patch-from: lvqcl <lvqcl.mail@gmail.com>

2 years agoSIMD: remove outdated SSE2 code
Erik de Castro Lopo [Tue, 21 Feb 2017 09:27:05 +0000 (20:27 +1100)]
SIMD: remove outdated SSE2 code

Removes FLAC__lpc_restore_signal_16_intrin_sse2() which was faster
than than C code, but not faster than MMX-accelerated ASM functions.
It's also slower than the new SSE4.1 functions that were added by
the previous patch.

Patch-from: lvqcl <lvqcl.mail@gmail.com>

2 years agoSIMD: Accelerate decoding of 16 bit FLAC
Erik de Castro Lopo [Sun, 19 Feb 2017 11:19:38 +0000 (22:19 +1100)]
SIMD: Accelerate decoding of 16 bit FLAC

This patch removes FLAC__lpc_restore_signal_16_intrin_sse2().

It's faster than C code, but not faster than MMX-accelerated
ASM functions. It's also slower than the new SSE4.1 functions
that were added by the previous patch.
So this function wasn't very useful before, and now it's
even less useful. I don't see a reason to keep it.

Patch-from: lvqcl <lvqcl.mail@gmail.com>

2 years agoSIMD: Improve decoding of some 24 bit files
Erik de Castro Lopo [Sun, 19 Feb 2017 08:47:58 +0000 (19:47 +1100)]
SIMD: Improve decoding of some 24 bit files

Accelerates decoding of non-Subset 24-bit FLAC files (where lpc_order
> 12).

The improved function is FLAC__lpc_restore_signal_wide_intrin_sse41().
It requires SSE4.1 and it's used only by 32-bit libFLAC.

Patch-from: lvqcl <lvqcl.mail@gmail.com>

2 years agoSIMD: Add const qualifier where appropriate
Erik de Castro Lopo [Sun, 19 Feb 2017 08:45:54 +0000 (19:45 +1100)]
SIMD: Add const qualifier where appropriate

Patch-from: lvqcl <lvqcl.mail@gmail.com>

2 years agocpu.h: Another CPP fixup
Erik de Castro Lopo [Thu, 16 Feb 2017 07:15:11 +0000 (18:15 +1100)]
cpu.h: Another CPP fixup

CPP is minefield. We should simplify CPP wherever possible and work
to minimise nesting.

2 years agocpu.h: Fix compiler detection
Erik de Castro Lopo [Wed, 15 Feb 2017 07:22:23 +0000 (18:22 +1100)]
cpu.h: Fix compiler detection

GCC version 4.6 was throwing an error on `__has_attribute` which
seems to be Clang specific. Solution was to un-nest the CPP code
so that Clang is confirmed before the `__has_attribute` is hit.

2 years agoflac/encode.c: Fix an integer overflow
Erik de Castro Lopo [Tue, 14 Feb 2017 10:21:54 +0000 (21:21 +1100)]
flac/encode.c: Fix an integer overflow

When encoding a 24 bit multichannel W64 file on a 32 bit system, a
calculation could overflow resulting in a "got partial sample"
error and early termination of the encoding process.

The fix was to replace the cast to `size_t` (which is only 32 bits
on a 32 bit system) with a cast to `uin64_t`.

Thanks to Janne Hyv√§rinen for helping to track down the problem.

Closes: https://sourceforge.net/p/flac/bugs/453

2 years agostream encoder: fix documentation inconsistencies
Christian Stadelmann [Mon, 30 Jan 2017 16:43:31 +0000 (17:43 +0100)]
stream encoder: fix documentation inconsistencies

Fixes https://sourceforge.net/p/flac/bugs/452/

Signed-off-by: Erik de Castro Lopo <erikd@mega-nerd.com>
2 years agocpu.h: Add #defines so Clang compiles AVX2
Erik de Castro Lopo [Sun, 12 Feb 2017 11:38:11 +0000 (22:38 +1100)]
cpu.h: Add #defines so Clang compiles AVX2

Patch-from: <lvqcl.mail@gmail.com>

2 years agoFix compile with cygwin
Rosen Penev [Thu, 9 Feb 2017 03:42:42 +0000 (19:42 -0800)]
Fix compile with cygwin

The underscores are wrong. The comment is also correct.

Also remove the configure.ac option. Otherwise it tries to compile the
windows unicode stuff which POSIX(cygwin) does not understand.

Signed-off-by: Erik de Castro Lopo <erikd@mega-nerd.com>
2 years agoconfigure.ac: Clean up CFLAGS code
Erik de Castro Lopo [Mon, 6 Feb 2017 08:54:13 +0000 (19:54 +1100)]
configure.ac: Clean up CFLAGS code

Also moves _FORTIFY_SOURCE detection to an M4 macro.

Patchfrom: David Seifert <soap@gentoo.org>

2 years agolibFLAC/lpc_intrin_sse41.c: Change usage of _mm_alignr_epi8
Erik de Castro Lopo [Tue, 31 Jan 2017 09:37:48 +0000 (20:37 +1100)]
libFLAC/lpc_intrin_sse41.c: Change usage of _mm_alignr_epi8

     a = _mm_alignr_epi8(b, a, n);
     a = _mm_alignr_epi8(a, b, n);

The resulting code is very slightly faster and the binaries slightly

Patch-from: lvqcl <lvqcl.mail@gmail.com>

2 years agolibFLAC/lpc_intrin_sse*: Formatting cleanup
Erik de Castro Lopo [Tue, 31 Jan 2017 09:35:55 +0000 (20:35 +1100)]
libFLAC/lpc_intrin_sse*: Formatting cleanup

Patch-from: lvqcl <lvqcl.mail@gmail.com>

2 years agoFLAC__stream_encoder_finish: Sanity improvement
Erik de Castro Lopo [Mon, 30 Jan 2017 19:39:22 +0000 (06:39 +1100)]
FLAC__stream_encoder_finish: Sanity improvement

Previously this function would abort or crash if passed `NULL` for
the encoder. Now it just returns without crashing or aborting which
is far more sane behaviour (ie much like FLAC__stream_encoder_delete).

2 years agoinclude/share/compat.h: Only define inline for C
Erik de Castro Lopo [Mon, 23 Jan 2017 19:20:03 +0000 (06:20 +1100)]
include/share/compat.h: Only define inline for C

Patch-from: lvqcl <lvqcl.mail@gmail.com>

2 years agoCreate .travis.yml
Stephen [Sun, 22 Jan 2017 01:15:44 +0000 (17:15 -0800)]
Create .travis.yml

Signed-off-by: Erik de Castro Lopo <erikd@mega-nerd.com>
Closes: https://github.com/xiph/flac/pull/28

2 years agoDo not override CFLAGS, as CFLAGS is a user flag.
David Seifert [Sun, 15 Jan 2017 09:37:02 +0000 (10:37 +0100)]
Do not override CFLAGS, as CFLAGS is a user flag.

* Furthermore, use NDEBUG globally to detect the presence
  of building with more debug output information.
  AX_CHECK_ENABLE_DEBUG is easier to use, and nowadays
  Gnome has also switched to it from its own custom solution.

Signed-off-by: Erik de Castro Lopo <erikd@mega-nerd.com>
2 years agoFix cppcheck warnings
Rosen Penev [Thu, 19 Jan 2017 02:45:28 +0000 (18:45 -0800)]
Fix cppcheck warnings

Signed-off-by: Erik de Castro Lopo <erikd@mega-nerd.com>
2 years agoshare/utf8/charset.c: Cleanup realloc() usage
Erik de Castro Lopo [Thu, 19 Jan 2017 09:28:18 +0000 (20:28 +1100)]
share/utf8/charset.c: Cleanup realloc() usage

This version should be logically identical to the previous version
but prevents a false-positive from the cppcheck static analysis

2 years agoAdd missing file include/share/msvc2005_int.h
Erik de Castro Lopo [Wed, 18 Jan 2017 19:56:14 +0000 (06:56 +1100)]
Add missing file include/share/msvc2005_int.h

2 years agostdint.h fixes for MSVS 2005/2008
Erik de Castro Lopo [Wed, 18 Jan 2017 19:30:45 +0000 (06:30 +1100)]
stdint.h fixes for MSVS 2005/2008

This adds a new msvc2005_int.h header file which is "force included"
as needed by the MSVS project file.

Patch-from: lvqcl <lvqcl.mail@gmail.com>

2 years agometadata.h: Fix search/replace typo in comments
Erik de Castro Lopo [Tue, 17 Jan 2017 07:53:57 +0000 (18:53 +1100)]
metadata.h: Fix search/replace typo in comments

2 years agogetopt.c: Pointer comparison fix
Erik de Castro Lopo [Tue, 17 Jan 2017 07:28:28 +0000 (18:28 +1100)]
getopt.c: Pointer comparison fix

* Remove <stdint.h> because MSVC 2005 (and probably 2008) don't have it.
* Fix pointer difference caclulation between `nameend` and `nextchar`.

Patch-from: lvqcl <lvqcl.mail@gmail.com>

2 years agoOnly compile and run tests when running 'make check'
David Seifert [Sun, 15 Jan 2017 09:37:03 +0000 (10:37 +0100)]
Only compile and run tests when running 'make check'

Signed-off-by: Erik de Castro Lopo <erikd@mega-nerd.com>
2 years agoFinal unsigned fixes
Erik de Castro Lopo [Mon, 16 Jan 2017 08:31:22 +0000 (19:31 +1100)]
Final unsigned fixes

Found using the Makefile.lite build system.

2 years agoYet more unsigned fixes
Erik de Castro Lopo [Mon, 16 Jan 2017 07:28:31 +0000 (18:28 +1100)]
Yet more unsigned fixes

2 years agobitmath.h: MSVS unsigned fix
Erik de Castro Lopo [Sun, 15 Jan 2017 05:25:40 +0000 (16:25 +1100)]
bitmath.h: MSVS unsigned fix

The orignal code had `unsigned long` inside `#ifdef MSVC`. It was then changed
to `uint64_t` which was incorrect because on Windows `sizze long == 4`.
Change it now to `uint32_t` which is always correct regardless of OS, compiler
or architecture.

2 years agolibFLAC/cpu.c: Replace memory.h include with string.h
sezero [Sat, 14 Jan 2017 22:56:56 +0000 (01:56 +0300)]
libFLAC/cpu.c: Replace memory.h include with string.h

cpu.c was the only source to use memory.h instead of string.h.

Signed-off-by: Erik de Castro Lopo <erikd@mega-nerd.com>
2 years agoHonor user's $(htmldir) and do not override GNU defaults for $(docdir)
David Seifert [Fri, 13 Jan 2017 17:42:30 +0000 (18:42 +0100)]
Honor user's $(htmldir) and do not override GNU defaults for $(docdir)

* HTML files should be installed to $(htmldir), and $(docdir) should
  not be changed, as this is a user flag in the GNU conventions.

Signed-off-by: Erik de Castro Lopo <erikd@mega-nerd.com>
2 years agoWhen using libtool, use LTLIBICONV instead.
David Seifert [Fri, 13 Jan 2017 17:42:31 +0000 (18:42 +0100)]
When using libtool, use LTLIBICONV instead.

* This is required, as otherwise -Wl,--as-needed could fail.

Signed-off-by: Erik de Castro Lopo <erikd@mega-nerd.com>
2 years agoMake building/installing examples optional
David Seifert [Fri, 13 Jan 2017 17:42:29 +0000 (18:42 +0100)]
Make building/installing examples optional

Signed-off-by: Erik de Castro Lopo <erikd@mega-nerd.com>
2 years agobitmath.h: More unsigned fixes
Erik de Castro Lopo [Sun, 15 Jan 2017 01:20:52 +0000 (12:20 +1100)]
bitmath.h: More unsigned fixes

2 years agoYet more purging of `unsigned` type
Erik de Castro Lopo [Sat, 14 Jan 2017 19:47:51 +0000 (06:47 +1100)]
Yet more purging of `unsigned` type

2 years agoinclude/FLAC: More unsigned fixes
Erik de Castro Lopo [Sat, 14 Jan 2017 09:02:15 +0000 (20:02 +1100)]
include/FLAC: More unsigned fixes

These fixes are in the public API, but FLAC would have been extremely
unlikely to work in any system where `unsigned` was not 32 bits.
Therefore we do not treat this as an API change.

2 years agoflac/utils.c: Workaround for DJGPP missing wcswidth()
sezero [Fri, 13 Jan 2017 15:20:35 +0000 (18:20 +0300)]
flac/utils.c: Workaround for DJGPP missing wcswidth()

Signed-off-by: Erik de Castro Lopo <erikd@mega-nerd.com>
2 years agoSupport nasm coff obj format for djgpp
sezero [Fri, 13 Jan 2017 14:51:06 +0000 (17:51 +0300)]
Support nasm coff obj format for djgpp

Signed-off-by: Erik de Castro Lopo <erikd@mega-nerd.com>
2 years agoPurge usage of `unsigned` type
Erik de Castro Lopo [Sat, 14 Jan 2017 06:26:39 +0000 (17:26 +1100)]
Purge usage of `unsigned` type

As pointed out by Ozkan Sezer, on some platforms `int32_t` is actually
a typedef for `long` so `unsigned` cannot be used interchangably with
`FLAC__uint32`. Fix is to switch from `unsigned` to explicit sized ISO
C types defined in <stdint.h>.

2 years agoconfigure.ac: relax linux OS detection
Peter Korsgaard [Mon, 9 Jan 2017 21:19:01 +0000 (22:19 +0100)]
configure.ac: relax linux OS detection

Not all linux hosts match the *-pc-linux-gnu wildcard, causing build
failures for older glibc versions where we need to link with -lrt for
clock_gettime - E.G.:

 - arm-unknown-linux-musleabihf
 - powerpc-unknown-linux-gnuspe
 - bfin-linux-linux-uclibc

Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
Signed-off-by: Erik de Castro Lopo <erikd@mega-nerd.com>
2 years agolibFLAC/cpu.c: Fix build issue on OpenBSD/i386
Erik de Castro Lopo [Fri, 13 Jan 2017 10:30:55 +0000 (21:30 +1100)]
libFLAC/cpu.c: Fix build issue on OpenBSD/i386

Patch-from: Christian Weisgerber <naddy@mips.inka.de>

2 years agostream_encoder.c: Make compression_levels_ array const
Erik de Castro Lopo [Fri, 6 Jan 2017 09:01:18 +0000 (20:01 +1100)]
stream_encoder.c: Make compression_levels_ array const

As pointed out by github user @randomascii, the `compression_levels_`
struct could and should be const.

Closes: https://github.com/xiph/flac/issues/26

2 years agoFix build with MSVC if UNICODE is enabled
Erik de Castro Lopo [Tue, 3 Jan 2017 19:30:42 +0000 (06:30 +1100)]
Fix build with MSVC if UNICODE is enabled

Patch-from: "lvqcl.mail" <lvqcl.mail@gmail.com>
Closes: https://sourceforge.net/p/flac/bugs/447/

2 years agolibFLAC/cpu.c: Fix CPU detecton
Erik de Castro Lopo [Mon, 2 Jan 2017 17:46:20 +0000 (04:46 +1100)]
libFLAC/cpu.c: Fix CPU detecton

Patch-from: Janne Hyv√§rinen <cse@sci.fi>

2 years agoVersion 1.3.2 1.3.2
Erik de Castro Lopo [Sun, 1 Jan 2017 00:54:07 +0000 (11:54 +1100)]
Version 1.3.2

2 years agotest/test_metaflac.sh: Comment only
Erik de Castro Lopo [Sun, 1 Jan 2017 00:52:04 +0000 (11:52 +1100)]
test/test_metaflac.sh: Comment only

2 years agolibFLAC: Remove commented out assert
Erik de Castro Lopo [Sat, 24 Dec 2016 11:05:07 +0000 (22:05 +1100)]
libFLAC: Remove commented out assert

Pointed out by c.helmrich@ecodis.de. It was added during debugging
in commit c06a44969, but was never meant to stay.

2 years agoMakefile.lite: Fix running of tests
Erik de Castro Lopo [Wed, 21 Dec 2016 05:42:15 +0000 (16:42 +1100)]
Makefile.lite: Fix running of tests

* Generate `test/common.sh` from `test/common.sh.in`.
* Move `is_win` setting to `test_common.sh`.

2 years agolibFLAC/cpu.c: Add CPP guard
Erik de Castro Lopo [Wed, 21 Dec 2016 05:16:13 +0000 (16:16 +1100)]
libFLAC/cpu.c: Add CPP guard

2 years agoMore Makefile.lite fixes
Erik de Castro Lopo [Wed, 21 Dec 2016 05:14:46 +0000 (16:14 +1100)]
More Makefile.lite fixes

Patch-from: Robert Kausch <robert.kausch@freac.org>

2 years agoAdd missing files to Makefile.am
Erik de Castro Lopo [Sun, 11 Dec 2016 09:20:47 +0000 (20:20 +1100)]
Add missing files to Makefile.am

2 years agoMakefile.lite fixes
Erik de Castro Lopo [Sun, 11 Dec 2016 09:17:49 +0000 (20:17 +1100)]
Makefile.lite fixes

Patch-from: Robert Kausch <robert.kausch@freac.org>

2 years agoFix PACKAGE_VERSION in MSVC files
Erik de Castro Lopo [Sun, 11 Dec 2016 09:11:58 +0000 (20:11 +1100)]

Patch-from: "lvqcl.mail" <lvqcl.mail@gmail.com>

2 years agodoc/html/changelog.html: Add credits
Erik de Castro Lopo [Tue, 6 Dec 2016 19:05:52 +0000 (06:05 +1100)]
doc/html/changelog.html: Add credits

2 years agodoc/html/changelog.html: Add OS/SSE assumptions
Erik de Castro Lopo [Tue, 6 Dec 2016 09:29:15 +0000 (20:29 +1100)]
doc/html/changelog.html: Add OS/SSE assumptions

2 years agodoc/html/changelog.html: More updates for 1.3.2 release
Erik de Castro Lopo [Tue, 6 Dec 2016 09:04:18 +0000 (20:04 +1100)]
doc/html/changelog.html: More updates for 1.3.2 release

2 years agolibFLAC/metadata_object.c: Fix typo in number
Erik de Castro Lopo [Tue, 6 Dec 2016 08:44:37 +0000 (19:44 +1100)]
libFLAC/metadata_object.c: Fix typo in number

As pointed out by Evan Ramos there was typo, `32786` instead of

2 years agolibFLAC/cpu.c: Improve logic
Erik de Castro Lopo [Tue, 6 Dec 2016 08:37:52 +0000 (19:37 +1100)]
libFLAC/cpu.c: Improve logic

Only call `FLAC__cpu_have_cpuid_asm_ia32` if `FLAC__HAS_NASM` is

Patch-from: "lvqcl.mail" <lvqcl.mail@gmail.com>

2 years agoUpdate version in MSVS project files
Erik de Castro Lopo [Mon, 5 Dec 2016 08:35:53 +0000 (19:35 +1100)]
Update version in MSVS project files

2 years agoAnother bulk update of copyright dates
Erik de Castro Lopo [Mon, 5 Dec 2016 07:57:47 +0000 (18:57 +1100)]
Another bulk update of copyright dates

2 years agodoc/html/changelog.html: Update for 1.3.2 release
Erik de Castro Lopo [Sun, 4 Dec 2016 19:49:59 +0000 (06:49 +1100)]
doc/html/changelog.html: Update for 1.3.2 release

2 years agoBulk update copyright dates
Erik de Castro Lopo [Sun, 4 Dec 2016 19:35:39 +0000 (06:35 +1100)]
Bulk update copyright dates

2 years agoconfigure.ac: Fix description of --disable-sse
Erik de Castro Lopo [Sun, 4 Dec 2016 18:37:44 +0000 (05:37 +1100)]
configure.ac: Fix description of --disable-sse

2 years agoconfigure.ac: Remove unused config flags
Erik de Castro Lopo [Sun, 4 Dec 2016 18:33:51 +0000 (05:33 +1100)]
configure.ac: Remove unused config flags


Patch-from: "lvqcl.mail" <lvqcl.mail@gmail.com>

2 years agovcxproj: Remove unused config flags
Erik de Castro Lopo [Sun, 4 Dec 2016 18:31:24 +0000 (05:31 +1100)]
vcxproj: Remove unused config flags

Specifically, FLAC__NO_SSE_OS and FLAC__SSE_OS.

Patch-from: "lvqcl.mail" <lvqcl.mail@gmail.com>

2 years agolibFLAC/cpu.c: Whitespace fixes
Erik de Castro Lopo [Sun, 4 Dec 2016 06:41:40 +0000 (17:41 +1100)]
libFLAC/cpu.c: Whitespace fixes

Patch-from : lvqcl.mail <lvqcl.mail@gmail.com>

2 years agolibFLAC/cpu.c: Remove OS SSE detection
Erik de Castro Lopo [Sun, 4 Dec 2016 06:36:58 +0000 (17:36 +1100)]
libFLAC/cpu.c: Remove OS SSE detection

Assume that all OSes that are usable today support SSE.

Patch-from: lvqcl.mail <lvqcl.mail@gmail.com>

2 years agosrc/share/grabbag/seektable.c: Fix typo inside assert
Erik de Castro Lopo [Fri, 2 Dec 2016 07:02:50 +0000 (18:02 +1100)]
src/share/grabbag/seektable.c: Fix typo inside assert

Patch-from: "lvqcl.mail" <lvqcl.mail@gmail.com>

2 years agoCorrect additional 'MEATADATA' typos.
Ralph Giles [Thu, 27 Oct 2016 15:47:09 +0000 (08:47 -0700)]
Correct additional 'MEATADATA' typos.

Thanks to Matthew Gregan for the report.

Signed-off-by: Erik de Castro Lopo <erikd@mega-nerd.com>
3 years agoFlac-in-mp4 draft v0.0.3.
Ralph Giles [Tue, 4 Oct 2016 16:46:26 +0000 (09:46 -0700)]
Flac-in-mp4 draft v0.0.3.

Draft updates in response to feedback from Yusuke Nakamura.

Signed-off-by: Erik de Castro Lopo <erikd@mega-nerd.com>
3 years agoFlac-in-mp4 draft v0.0.2.
Ralph Giles [Tue, 4 Oct 2016 15:49:09 +0000 (08:49 -0700)]
Flac-in-mp4 draft v0.0.2.

Draft updates in response to feedback from David Evans.

Signed-off-by: Erik de Castro Lopo <erikd@mega-nerd.com>
3 years agoFlac-in-mp4 draft v0.0.1.
Ralph Giles [Tue, 4 Oct 2016 15:46:00 +0000 (08:46 -0700)]
Flac-in-mp4 draft v0.0.1.

Draft updates in response to feedback from Timothy B. Terriberry
and Jean-Yves Avenard.

Signed-off-by: Erik de Castro Lopo <erikd@mega-nerd.com>
3 years agoFlac-in-mp4 draft v0.0.0.
Ralph Giles [Tue, 4 Oct 2016 15:41:07 +0000 (08:41 -0700)]
Flac-in-mp4 draft v0.0.0.

We've been working on a draft spec for encapsulation of FLAC
in the ISO Base Media File Format (mp4). This is the initial
draft created by Monty Montgomery based on Yusuke Nakamura's
Opus-in-mp4 draft.

More details at https://bugzilla.mozilla.org/show_bug.cgi?id=1286097

Signed-off-by: Erik de Castro Lopo <erikd@mega-nerd.com>
3 years agocpu.c: Really fix compiler warnings
Erik de Castro Lopo [Mon, 12 Sep 2016 07:27:03 +0000 (17:27 +1000)]
cpu.c: Really fix compiler warnings

3 years agocpu.c: Fix compiler warning on PowerPC
Erik de Castro Lopo [Sun, 11 Sep 2016 03:35:46 +0000 (13:35 +1000)]
cpu.c: Fix compiler warning on PowerPC

3 years agoFix compiler warning from gcc-6.1.1
Erik de Castro Lopo [Thu, 8 Sep 2016 10:39:16 +0000 (20:39 +1000)]
Fix compiler warning from gcc-6.1.1

3 years agostream_decoder: reset has_seek_table before read_metadata_seektable_()
Max Kellermann [Thu, 14 Jul 2016 08:22:43 +0000 (10:22 +0200)]
stream_decoder: reset has_seek_table before read_metadata_seektable_()

If a seek table has already been read successfully, then the
has_seek_table flag is true.  Now imagine the file comes with another
seek table, which doesn't make sense, but libFLAC accepts it happily.
If reading this second seek table fails (for example allocation
failure), read_metadata_seektable_() returns false, but the
has_seek_table flag is still true.  If the calling application happens
to ignore this failure, and at some point tries to seek, the process
will crash due to NULL pointer dereference.  This would sure be an
application bug that needs to be fixed, but libFLAC's internal state
is inconsistent, so let's fix this up.

Signed-off-by: Erik de Castro Lopo <erikd@mega-nerd.com>
3 years agostream_decoder: fix memory leak after seek table read error
Max Kellermann [Thu, 14 Jul 2016 08:06:23 +0000 (10:06 +0200)]
stream_decoder: fix memory leak after seek table read error

When read_metadata_seektable_() fails, the has_seek_table flag is
never set to true, and thus free() is never called.

Example valgrind output:

 11,185,464 bytes in 1 blocks are definitely lost in loss record 62 of 62
    at 0x4C2BC0F: malloc (vg_replace_malloc.c:299)
    by 0x4C2DE6F: realloc (vg_replace_malloc.c:785)
    by 0x40A7880: safe_realloc_ (alloc.h:159)
    by 0x40A7911: safe_realloc_mul_2op_ (alloc.h:205)
    by 0x40AB6B5: read_metadata_seektable_ (stream_decoder.c:1654)
    by 0x40AAB2D: read_metadata_ (stream_decoder.c:1422)
    by 0x40A9C79: FLAC__stream_decoder_process_until_end_of_metadata (stream_decoder.c:1055)

It is easy to craft a FLAC file which leaks megabytes of memory on
every attempt to open the file.

This patch fixes the problem by removing checks which are unnecessary
(and harmful).  Checking the has_seek_table flag is not enough, as
described above.  The NULL check is not harmful, but is not helpful
either, because free(NULL) is documented to be legal.

After running this code block, we're in a well-known safe state, no
matter how inconsistent pointer and flag may have been before, for
whatever reasons.

Signed-off-by: Erik de Castro Lopo <erikd@mega-nerd.com>
3 years agolibFLAC: Fix cpuid detecton on old Cyrix CPUs
Erik de Castro Lopo [Wed, 13 Jul 2016 09:45:53 +0000 (19:45 +1000)]
libFLAC: Fix cpuid detecton on old Cyrix CPUs

Some old CPUs (eg Cyrix) set EDX but not ECX when executing CPUID.
One of the solutions is to clear ECX before calling cpuid. From
https://bugzilla.mozilla.org/show_bug.cgi?id=1096651#c9 bug

Patch-from: lvqcl <lvqcl.mail@gmail.com>

3 years agolibFLAC: Set decoding status if write callback failed
Erik de Castro Lopo [Wed, 13 Jul 2016 09:41:14 +0000 (19:41 +1000)]
libFLAC: Set decoding status if write callback failed

Previously, it the write callback failed the error status
would be set to `FLAC__STREAM_DECODER_READ_FRAME`. Now it

Patch-from: lvqcl <lvqcl.mail@gmail.com>

3 years agolibFLAC/metadata_object.c: Clean up
Erik de Castro Lopo [Sun, 10 Jul 2016 06:12:32 +0000 (16:12 +1000)]
libFLAC/metadata_object.c: Clean up

* Remove Yoda conditionals.
* Drop some un-needed asserts.

3 years agometadata_object.c: Remove un-needed asserts
Erik de Castro Lopo [Sun, 10 Jul 2016 01:18:34 +0000 (11:18 +1000)]
metadata_object.c: Remove un-needed asserts

These asserts were being triggered by AFL (American Fuzzy Lop) and
serve seemingly no useful purpose. The are only enabled in debug builds
where they abort the program which is otherwise in a safe state.

Removing these asserts will potentially allow AFL to turn up other
problems elsewhere.

3 years agostream_decoder: fix integer underflow due to malformed wasted_bits
Max Kellermann [Fri, 8 Jul 2016 19:29:41 +0000 (21:29 +0200)]
stream_decoder: fix integer underflow due to malformed wasted_bits

It is pretty easy for a malformed FLAC file to underflow the "bps"
variable.  In the debug build, this results in an assertion failure in

    FLAC__ASSERT(bits <= 32);

In non-debug builds, this simply makes
FLAC__bitreader_read_raw_uint32() fail because
bitreader_read_from_client_() doesn't find enough buffer space for
2**32-1 bits.  But since the failing FLAC_ASSERT() is reasonable, this
should be caught in the FLAC__bitreader_read_raw_uint32() caller.

Signed-off-by: Erik de Castro Lopo <erikd@mega-nerd.com>
Closes: https://github.com/xiph/flac/pull/13

3 years agostream_decoder: check state==ABORTED after process_single() for seek
Max Kellermann [Wed, 6 Jul 2016 14:28:53 +0000 (16:28 +0200)]
stream_decoder: check state==ABORTED after process_single() for seek

FLAC__stream_decoder_process_single() ignores frame_sync_() errors,
which means the caller cannot rely solely on the boolean return value,
it is also required to check the new "state".

After FLAC__stream_decoder_process_until_end_of_metadata(),
last_frame.header.number_type==FRAME_NUMBER.  When an application
seeks at this time, but an I/O error occurs, then
FLAC__stream_decoder_process_single() returns true, but no frame has
been read yet, i.e. last_frame.header.number_type is still
FRAME_NUMBER.  This triggers the assertion in

 FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);

So what needs to be done is check for state==ABORTED after the
FLAC__stream_decoder_process_single() call.

This bug can be triggered remotely with the Music Player Daemon
(https://www.musicpd.org/), and crashes the process.

Signed-off-by: Erik de Castro Lopo <erikd@mega-nerd.com>
Closes: https://github.com/xiph/flac/pull/12

3 years agoflac++.pc.in: Make flac a private requires
Erik de Castro Lopo [Sat, 9 Jul 2016 11:55:07 +0000 (21:55 +1000)]
flac++.pc.in: Make flac a private requires

Patch pulled from Debian package.

Chain::Status::as_cstring uses FLAC__Metadata_ChainStatusString which
is in libFLAC. Since the function is inline, every program calling
this function must also link with -lflac, but this is missing in

Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=713645

3 years agolibFLAC/cpu.c: Fix dfprintf macro for MSVS
Erik de Castro Lopo [Thu, 30 Jun 2016 20:41:18 +0000 (06:41 +1000)]
libFLAC/cpu.c: Fix dfprintf macro for MSVS

3 years agolibFLAC/cpu.c: Add parens to avoid compiler warnings
Erik de Castro Lopo [Mon, 27 Jun 2016 21:12:42 +0000 (07:12 +1000)]
libFLAC/cpu.c: Add parens to avoid compiler warnings

3 years agolibFLAC/cpu.c: Inline *_disable_avx()
Julian Calaby [Mon, 27 Jun 2016 13:22:20 +0000 (23:22 +1000)]
libFLAC/cpu.c: Inline *_disable_avx()

Also only print out OS AVX status if AVX is actually enabled.

3 years agolibFLAC/cpu.c: Move cpu_id_ex into cpu_info_x86()
Julian Calaby [Mon, 27 Jun 2016 12:41:13 +0000 (22:41 +1000)]
libFLAC/cpu.c: Move cpu_id_ex into cpu_info_x86()

This simplifies the C code without complexifying the preprocessor

3 years agolibFLAC/cpu.c: Eliminate a branch in cpu_info_x86
Julian Calaby [Mon, 27 Jun 2016 12:37:45 +0000 (22:37 +1000)]
libFLAC/cpu.c: Eliminate a branch in cpu_info_x86

Inverting all the if statements allows us to move the common code of
setting all the registers to zero outside the #if statement.

3 years agolibFLAC/cpu.c: Remove a layer of cpp conditionals
Julian Calaby [Mon, 27 Jun 2016 12:17:03 +0000 (22:17 +1000)]
libFLAC/cpu.c: Remove a layer of cpp conditionals

3 years agolibFLAC/cpu.c: Drop some unnecessary returns
Julian Calaby [Mon, 27 Jun 2016 12:15:31 +0000 (22:15 +1000)]
libFLAC/cpu.c: Drop some unnecessary returns

3 years agolibFLAC/cpu.c: Get rid of OS_IS_ANDROID function
Julian Calaby [Mon, 27 Jun 2016 12:13:30 +0000 (22:13 +1000)]
libFLAC/cpu.c: Get rid of OS_IS_ANDROID function

3 years agolibFLAC/cpu.c: Move stdio.h include under DEBUG
Julian Calaby [Mon, 27 Jun 2016 12:10:47 +0000 (22:10 +1000)]
libFLAC/cpu.c: Move stdio.h include under DEBUG

3 years agolibFLAC/cpu.c: Use a dummy function for debugging
Julian Calaby [Mon, 27 Jun 2016 12:08:51 +0000 (22:08 +1000)]
libFLAC/cpu.c: Use a dummy function for debugging

This saves 5 if statements that would have had to have been
optimised away.

3 years agolibFLAC/cpu.c: More MSVC fixes
Erik de Castro Lopo [Sun, 26 Jun 2016 19:09:07 +0000 (05:09 +1000)]
libFLAC/cpu.c: More MSVC fixes

With help from lvqcl <lvqcl.mail@gmail.com>

3 years agolibFLAC/cpu.c: Fixes for MSVC
Erik de Castro Lopo [Sun, 26 Jun 2016 11:09:08 +0000 (21:09 +1000)]
libFLAC/cpu.c: Fixes for MSVC

MSVC is strange and perverse.

3 years agolibFLAC/cpu.c: Fix build on non-Intel CPUs
Erik de Castro Lopo [Sun, 26 Jun 2016 07:28:27 +0000 (17:28 +1000)]
libFLAC/cpu.c: Fix build on non-Intel CPUs

3 years agolibFLAC/cpu.c: More cleanup and refactoring
Erik de Castro Lopo [Sun, 26 Jun 2016 02:59:11 +0000 (12:59 +1000)]
libFLAC/cpu.c: More cleanup and refactoring

* Split `FLAC__cpu_info` into CPU specific functions. We now have
  `ia32_cpi_info` and `x86_64_cpu_info` and a simple obvious way
  to add support for other CPUs.
* Improve handling of Android OS.
* Remove more #ifdefs where possible.
* Compile (syntax and type check) DEBUG output code even when debugging
  is disabled.
* Remove build support for ancient NetBSD version 1.5 (version 1.6 was
  released in 2002).