aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/Makefile.am2
-rw-r--r--src/flac/CMakeLists.txt1
-rw-r--r--src/flac/Makefile.am22
-rw-r--r--src/flac/analyze.c5
-rw-r--r--src/flac/analyze.h2
-rw-r--r--src/flac/decode.c43
-rw-r--r--src/flac/decode.h2
-rw-r--r--src/flac/encode.c208
-rw-r--r--src/flac/encode.h6
-rw-r--r--src/flac/foreign_metadata.c9
-rw-r--r--src/flac/foreign_metadata.h2
-rw-r--r--src/flac/iffscan.c2
-rw-r--r--src/flac/local_string_utils.h2
-rw-r--r--src/flac/main.c76
-rw-r--r--src/flac/utils.c26
-rw-r--r--src/flac/utils.h4
-rw-r--r--src/flac/version.rc38
-rw-r--r--src/flac/vorbiscomment.c2
-rw-r--r--src/flac/vorbiscomment.h2
-rw-r--r--src/libFLAC++/CMakeLists.txt5
-rw-r--r--src/libFLAC++/Makefile.am17
-rw-r--r--src/libFLAC++/metadata.cpp2
-rw-r--r--src/libFLAC++/stream_decoder.cpp2
-rw-r--r--src/libFLAC++/stream_encoder.cpp2
-rw-r--r--src/libFLAC++/version.rc40
-rw-r--r--src/libFLAC/CMakeLists.txt3
-rw-r--r--src/libFLAC/Makefile.am13
-rw-r--r--src/libFLAC/bitmath.c2
-rw-r--r--src/libFLAC/bitreader.c157
-rw-r--r--src/libFLAC/bitwriter.c2
-rw-r--r--src/libFLAC/cpu.c5
-rw-r--r--src/libFLAC/crc.c2
-rw-r--r--src/libFLAC/deduplication/bitreader_read_rice_signed_block.c143
-rw-r--r--src/libFLAC/fixed.c2
-rw-r--r--src/libFLAC/fixed_intrin_avx2.c72
-rw-r--r--src/libFLAC/fixed_intrin_sse2.c2
-rw-r--r--src/libFLAC/fixed_intrin_sse42.c22
-rw-r--r--src/libFLAC/fixed_intrin_ssse3.c2
-rw-r--r--src/libFLAC/float.c2
-rw-r--r--src/libFLAC/format.c9
-rw-r--r--src/libFLAC/include/Makefile.am2
-rw-r--r--src/libFLAC/include/private/Makefile.am2
-rw-r--r--src/libFLAC/include/private/all.h2
-rw-r--r--src/libFLAC/include/private/bitmath.h2
-rw-r--r--src/libFLAC/include/private/bitreader.h6
-rw-r--r--src/libFLAC/include/private/bitwriter.h2
-rw-r--r--src/libFLAC/include/private/cpu.h5
-rw-r--r--src/libFLAC/include/private/crc.h2
-rw-r--r--src/libFLAC/include/private/fixed.h2
-rw-r--r--src/libFLAC/include/private/float.h2
-rw-r--r--src/libFLAC/include/private/format.h2
-rw-r--r--src/libFLAC/include/private/lpc.h2
-rw-r--r--src/libFLAC/include/private/macros.h2
-rw-r--r--src/libFLAC/include/private/memory.h2
-rw-r--r--src/libFLAC/include/private/metadata.h2
-rw-r--r--src/libFLAC/include/private/ogg_decoder_aspect.h2
-rw-r--r--src/libFLAC/include/private/ogg_encoder_aspect.h2
-rw-r--r--src/libFLAC/include/private/ogg_helper.h2
-rw-r--r--src/libFLAC/include/private/ogg_mapping.h2
-rw-r--r--src/libFLAC/include/private/stream_encoder.h2
-rw-r--r--src/libFLAC/include/private/stream_encoder_framing.h4
-rw-r--r--src/libFLAC/include/private/window.h2
-rw-r--r--src/libFLAC/include/protected/Makefile.am2
-rw-r--r--src/libFLAC/include/protected/all.h2
-rw-r--r--src/libFLAC/include/protected/stream_decoder.h2
-rw-r--r--src/libFLAC/include/protected/stream_encoder.h2
-rw-r--r--src/libFLAC/lpc.c2
-rw-r--r--src/libFLAC/lpc_intrin_avx2.c2
-rw-r--r--src/libFLAC/lpc_intrin_fma.c2
-rw-r--r--src/libFLAC/lpc_intrin_neon.c2
-rw-r--r--src/libFLAC/lpc_intrin_sse2.c2
-rw-r--r--src/libFLAC/lpc_intrin_sse41.c2
-rw-r--r--src/libFLAC/memory.c2
-rw-r--r--src/libFLAC/metadata_iterators.c14
-rw-r--r--src/libFLAC/metadata_object.c166
-rw-r--r--src/libFLAC/ogg_decoder_aspect.c2
-rw-r--r--src/libFLAC/ogg_encoder_aspect.c2
-rw-r--r--src/libFLAC/ogg_helper.c2
-rw-r--r--src/libFLAC/ogg_mapping.c2
-rw-r--r--src/libFLAC/stream_decoder.c143
-rw-r--r--src/libFLAC/stream_encoder.c154
-rw-r--r--src/libFLAC/stream_encoder_framing.c22
-rw-r--r--src/libFLAC/stream_encoder_intrin_avx2.c2
-rw-r--r--src/libFLAC/stream_encoder_intrin_sse2.c2
-rw-r--r--src/libFLAC/stream_encoder_intrin_ssse3.c2
-rw-r--r--src/libFLAC/version.rc40
-rw-r--r--src/libFLAC/window.c2
-rw-r--r--src/metaflac/CMakeLists.txt1
-rw-r--r--src/metaflac/Makefile.am22
-rw-r--r--src/metaflac/main.c6
-rw-r--r--src/metaflac/operations.c163
-rw-r--r--src/metaflac/operations.h2
-rw-r--r--src/metaflac/operations_shorthand.h2
-rw-r--r--src/metaflac/operations_shorthand_cuesheet.c14
-rw-r--r--src/metaflac/operations_shorthand_picture.c10
-rw-r--r--src/metaflac/operations_shorthand_seektable.c4
-rw-r--r--src/metaflac/operations_shorthand_streaminfo.c2
-rw-r--r--src/metaflac/operations_shorthand_vorbiscomment.c9
-rw-r--r--src/metaflac/options.c20
-rw-r--r--src/metaflac/options.h5
-rw-r--r--src/metaflac/usage.c34
-rw-r--r--src/metaflac/usage.h2
-rw-r--r--src/metaflac/utils.c8
-rw-r--r--src/metaflac/utils.h7
-rw-r--r--src/metaflac/version.rc38
-rw-r--r--src/share/Makefile.am2
-rw-r--r--src/share/getopt/getopt1.c27
-rw-r--r--src/share/grabbag/alloc.c2
-rw-r--r--src/share/grabbag/cuesheet.c75
-rw-r--r--src/share/grabbag/file.c2
-rw-r--r--src/share/grabbag/picture.c2
-rw-r--r--src/share/grabbag/replaygain.c4
-rw-r--r--src/share/grabbag/seektable.c5
-rw-r--r--src/share/grabbag/snprintf.c2
-rw-r--r--src/share/replaygain_synthesis/replaygain_synthesis.c2
-rw-r--r--src/share/utf8/iconvert.c9
-rw-r--r--src/share/win_utf8_io/win_utf8_io.c46
-rw-r--r--src/test_grabbag/Makefile.am2
-rw-r--r--src/test_grabbag/cuesheet/Makefile.am2
-rw-r--r--src/test_grabbag/cuesheet/main.c2
-rw-r--r--src/test_grabbag/picture/Makefile.am2
-rw-r--r--src/test_grabbag/picture/main.c2
-rw-r--r--src/test_libFLAC++/Makefile.am2
-rw-r--r--src/test_libFLAC++/decoders.cpp2
-rw-r--r--src/test_libFLAC++/decoders.h2
-rw-r--r--src/test_libFLAC++/encoders.cpp2
-rw-r--r--src/test_libFLAC++/encoders.h2
-rw-r--r--src/test_libFLAC++/main.cpp2
-rw-r--r--src/test_libFLAC++/metadata.cpp2
-rw-r--r--src/test_libFLAC++/metadata.h2
-rw-r--r--src/test_libFLAC++/metadata_manip.cpp2
-rw-r--r--src/test_libFLAC++/metadata_object.cpp2
-rw-r--r--src/test_libFLAC/Makefile.am2
-rw-r--r--src/test_libFLAC/bitreader.c2
-rw-r--r--src/test_libFLAC/bitreader.h2
-rw-r--r--src/test_libFLAC/bitwriter.c2
-rw-r--r--src/test_libFLAC/bitwriter.h2
-rw-r--r--src/test_libFLAC/crc.c2
-rw-r--r--src/test_libFLAC/crc.h2
-rw-r--r--src/test_libFLAC/decoders.c2
-rw-r--r--src/test_libFLAC/decoders.h2
-rw-r--r--src/test_libFLAC/encoders.c2
-rw-r--r--src/test_libFLAC/encoders.h2
-rw-r--r--src/test_libFLAC/endswap.c2
-rw-r--r--src/test_libFLAC/endswap.h2
-rw-r--r--src/test_libFLAC/format.c4
-rw-r--r--src/test_libFLAC/format.h2
-rw-r--r--src/test_libFLAC/main.c2
-rw-r--r--src/test_libFLAC/md5.c2
-rw-r--r--src/test_libFLAC/md5.h2
-rw-r--r--src/test_libFLAC/metadata.c2
-rw-r--r--src/test_libFLAC/metadata.h2
-rw-r--r--src/test_libFLAC/metadata_manip.c2
-rw-r--r--src/test_libFLAC/metadata_object.c2
-rw-r--r--src/test_libs_common/Makefile.am2
-rw-r--r--src/test_libs_common/file_utils_flac.c2
-rw-r--r--src/test_libs_common/metadata_utils.c5
-rw-r--r--src/test_seeking/Makefile.am2
-rw-r--r--src/test_seeking/main.c2
-rw-r--r--src/test_streams/Makefile.am2
-rw-r--r--src/test_streams/main.c2
-rw-r--r--src/utils/Makefile.am2
-rw-r--r--src/utils/flacdiff/Makefile.am2
-rw-r--r--src/utils/flacdiff/main.cpp2
-rw-r--r--src/utils/flactimer/Makefile.am2
-rw-r--r--src/utils/flactimer/main.cpp2
167 files changed, 1382 insertions, 840 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 97e397aa..262feead 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.11)
-option(ENABLE_64_BIT_WORDS "Set FLAC__BYTES_PER_WORD to 8 (4 is the default)" OFF)
+option(ENABLE_64_BIT_WORDS "Set FLAC__BYTES_PER_WORD to 8, for 64-bit machines. For 32-bit machines, turning this off might give a tiny speed improvement" ON)
option(BUILD_UTILS "Build utils" OFF)
add_subdirectory("libFLAC")
diff --git a/src/Makefile.am b/src/Makefile.am
index c46a94fc..e9d60a9b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,6 +1,6 @@
# FLAC - Free Lossless Audio Codec
# Copyright (C) 2001-2009 Josh Coalson
-# Copyright (C) 2011-2022 Xiph.Org Foundation
+# Copyright (C) 2011-2023 Xiph.Org Foundation
#
# This file is part the FLAC project. FLAC is comprised of several
# components distributed under different licenses. The codec libraries
diff --git a/src/flac/CMakeLists.txt b/src/flac/CMakeLists.txt
index 40034502..da7ce8de 100644
--- a/src/flac/CMakeLists.txt
+++ b/src/flac/CMakeLists.txt
@@ -10,6 +10,7 @@ add_executable(flacapp
local_string_utils.c
utils.c
vorbiscomment.c
+ version.rc
$<$<BOOL:${WIN32}>:../../include/share/win_utf8_io.h>
$<$<BOOL:${WIN32}>:../share/win_utf8_io/win_utf8_io.c>)
set_property(TARGET flacapp PROPERTY RUNTIME_OUTPUT_NAME flac)
diff --git a/src/flac/Makefile.am b/src/flac/Makefile.am
index 5fc34386..279a7cb9 100644
--- a/src/flac/Makefile.am
+++ b/src/flac/Makefile.am
@@ -1,6 +1,6 @@
# flac - Command-line FLAC encoder/decoder
# Copyright (C) 2000-2009 Josh Coalson
-# Copyright (C) 2011-2022 Xiph.Org Foundation
+# Copyright (C) 2011-2023 Xiph.Org Foundation
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -16,13 +16,22 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+if OS_IS_WINDOWS
+win_utf8_lib = $(top_builddir)/src/share/win_utf8_io/libwin_utf8_io.la
+if HAVE_WINDRES
+flac_DEPENDENCIES = version.o
+windows_resource_link = -Wl,version.o
+endif
+endif
+
bin_PROGRAMS = flac
AM_CFLAGS = @OGG_CFLAGS@
AM_CPPFLAGS = -I$(top_builddir) -I$(srcdir)/include -I$(top_srcdir)/include
EXTRA_DIST = \
CMakeLists.txt \
- iffscan.c
+ iffscan.c \
+ version.rc
flac_SOURCES = \
analyze.c \
@@ -41,10 +50,6 @@ flac_SOURCES = \
utils.h \
vorbiscomment.h
-if OS_IS_WINDOWS
-win_utf8_lib = $(top_builddir)/src/share/win_utf8_io/libwin_utf8_io.la
-endif
-
flac_LDADD = \
$(top_builddir)/src/share/utf8/libutf8.la \
$(top_builddir)/src/share/grabbag/libgrabbag.la \
@@ -56,4 +61,9 @@ flac_LDADD = \
@LTLIBICONV@ \
-lm
+flac_LDFLAGS = $(AM_LDFLAGS) $(windows_resource_link)
+
CLEANFILES = flac.exe
+
+.rc.o:
+ $(RC) $(AM_CPPFLAGS) $< $@
diff --git a/src/flac/analyze.c b/src/flac/analyze.c
index ff1b170d..0a85565e 100644
--- a/src/flac/analyze.c
+++ b/src/flac/analyze.c
@@ -1,6 +1,6 @@
/* flac - Command-line FLAC encoder/decoder
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -245,5 +245,8 @@ FLAC__bool dump_stats(const subframe_stats_t *stats, const char *filename)
fprintf(outfile, "pause -1 'waiting...'\n");
fclose(outfile);
+#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
+ unlink(filename);
+#endif
return true;
}
diff --git a/src/flac/analyze.h b/src/flac/analyze.h
index fbdec29e..ce07b145 100644
--- a/src/flac/analyze.h
+++ b/src/flac/analyze.h
@@ -1,6 +1,6 @@
/* flac - Command-line FLAC encoder/decoder
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/flac/decode.c b/src/flac/decode.c
index c9c74546..90f7a6c8 100644
--- a/src/flac/decode.c
+++ b/src/flac/decode.c
@@ -1,6 +1,6 @@
/* flac - Command-line FLAC encoder/decoder
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -242,7 +242,7 @@ FLAC__bool DecoderSession_construct(DecoderSession *d, FLAC__bool is_ogg, FLAC__
d->has_md5sum = false;
d->bps = 0;
d->channels = 0;
- d->sample_rate = 0;
+ d->sample_rate = UINT32_MAX;
d->channel_mask = 0;
d->decode_position = 0;
@@ -297,7 +297,11 @@ void DecoderSession_destroy(DecoderSession *d, FLAC__bool error_occurred)
}
#endif
fclose(d->fout);
+
+#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
+ /* Always delete output file when fuzzing */
if(error_occurred)
+#endif
flac_unlink(d->outfilename);
}
}
@@ -586,7 +590,10 @@ int DecoderSession_finish_error(DecoderSession *d)
FLAC__bool canonicalize_until_specification(utils__SkipUntilSpecification *spec, const char *inbasefilename, uint32_t sample_rate, FLAC__uint64 skip, FLAC__uint64 total_samples_in_input)
{
/* convert from mm:ss.sss to sample number if necessary */
- flac__utils_canonicalize_skip_until_specification(spec, sample_rate);
+ if(!flac__utils_canonicalize_skip_until_specification(spec, sample_rate)) {
+ flac__utils_printf(stderr, 1, "%s: ERROR, value of --until is too large\n", inbasefilename);
+ return false;
+ }
/* special case: if "--until=-0", use the special value '0' to mean "end-of-stream" */
if(spec->is_relative && spec->value.samples == 0) {
@@ -707,7 +714,7 @@ FLAC__bool write_iff_headers(FILE *f, DecoderSession *decoder_session, FLAC__uin
else if(format == FORMAT_AIFF)
iff_size = 46 + foreign_metadata_size + aligned_data_size;
else /* AIFF-C */
- iff_size = 16 + foreign_metadata_size + aligned_data_size + fm->aifc_comm_length;
+ iff_size = 16 + foreign_metadata_size + aligned_data_size + (fm?fm->aifc_comm_length:0);
if(format != FORMAT_WAVE64 && format != FORMAT_RF64 && iff_size >= 0xFFFFFFF4) {
flac__utils_printf(stderr, 1, "%s: ERROR: stream is too big to fit in a single %s file\n", decoder_session->inbasefilename, fmt_desc);
@@ -1095,7 +1102,7 @@ FLAC__StreamDecoderWriteStatus write_callback(const FLAC__StreamDecoder *decoder
DecoderSession *decoder_session = (DecoderSession*)client_data;
FILE *fout = decoder_session->fout;
const uint32_t bps = frame->header.bits_per_sample, channels = frame->header.channels;
- const uint32_t shift = (decoder_session->format != FORMAT_RAW && (bps%8))? 8-(bps%8): 0;
+ const uint32_t shift = (bps%8)? 8-(bps%8): 0;
FLAC__bool is_big_endian = (
(decoder_session->format == FORMAT_AIFF || (decoder_session->format == FORMAT_AIFF_C && decoder_session->subformat == SUBFORMAT_AIFF_C_NONE)) ? true : (
decoder_session->format == FORMAT_WAVE || decoder_session->format == FORMAT_WAVE64 || decoder_session->format == FORMAT_RF64 || (decoder_session->format == FORMAT_AIFF_C && decoder_session->subformat == SUBFORMAT_AIFF_C_SOWT) ? false :
@@ -1140,6 +1147,10 @@ FLAC__StreamDecoderWriteStatus write_callback(const FLAC__StreamDecoder *decoder
else {
/* must not have gotten STREAMINFO, save the bps from the frame header */
FLAC__ASSERT(!decoder_session->got_stream_info);
+ if(decoder_session->format == FORMAT_RAW && ((decoder_session->bps % 8) != 0 || decoder_session->bps < 4)) {
+ flac__utils_printf(stderr, 1, "%s: ERROR: bits per sample is %u, must be 8/16/24/32 for raw format output\n", decoder_session->inbasefilename, decoder_session->bps);
+ return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
+ }
decoder_session->bps = bps;
}
@@ -1161,7 +1172,7 @@ FLAC__StreamDecoderWriteStatus write_callback(const FLAC__StreamDecoder *decoder
}
/* sanity-check the sample rate */
- if(!decoder_session->got_stream_info) {
+ if(decoder_session->sample_rate < UINT32_MAX) {
if(frame->header.sample_rate != decoder_session->sample_rate) {
if(decoder_session->got_stream_info)
flac__utils_printf(stderr, 1, "%s: ERROR, sample rate is %u in frame but %u in STREAMINFO\n", decoder_session->inbasefilename, frame->header.sample_rate, decoder_session->sample_rate);
@@ -1172,15 +1183,16 @@ FLAC__StreamDecoderWriteStatus write_callback(const FLAC__StreamDecoder *decoder
}
}
else {
+ /* must not have gotten STREAMINFO, save the sample rate from the frame header */
+ FLAC__ASSERT(!decoder_session->got_stream_info);
decoder_session->sample_rate = frame->header.sample_rate;
}
/*
* limit the number of samples to accept based on --until
*/
- FLAC__ASSERT(!decoder_session->skip_specification->is_relative);
/* if we never got the total_samples from the metadata, the skip and until specs would never have been canonicalized, so protect against that: */
- if(decoder_session->skip_specification->is_relative) {
+ if(decoder_session->skip_specification->is_relative || !decoder_session->got_stream_info) {
if(decoder_session->skip_specification->value.samples == 0) /* special case for when no --skip was given */
decoder_session->skip_specification->is_relative = false; /* convert to our meaning of beginning-of-stream */
else {
@@ -1188,7 +1200,7 @@ FLAC__StreamDecoderWriteStatus write_callback(const FLAC__StreamDecoder *decoder
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
}
}
- if(decoder_session->until_specification->is_relative) {
+ if(decoder_session->until_specification->is_relative || !decoder_session->got_stream_info) {
if(decoder_session->until_specification->value.samples == 0) /* special case for when no --until was given */
decoder_session->until_specification->is_relative = false; /* convert to our meaning of end-of-stream */
else {
@@ -1452,7 +1464,11 @@ void metadata_callback(const FLAC__StreamDecoder *decoder, const FLAC__StreamMet
decoder_session->channels = metadata->data.stream_info.channels;
decoder_session->sample_rate = metadata->data.stream_info.sample_rate;
- flac__utils_canonicalize_skip_until_specification(decoder_session->skip_specification, decoder_session->sample_rate);
+ if(!flac__utils_canonicalize_skip_until_specification(decoder_session->skip_specification, decoder_session->sample_rate)) {
+ flac__utils_printf(stderr, 1, "%s: ERROR, value of --skip is too large\n", decoder_session->inbasefilename);
+ decoder_session->abort_flag = true;
+ return;
+ }
FLAC__ASSERT(decoder_session->skip_specification->value.samples >= 0);
skip = (FLAC__uint64)decoder_session->skip_specification->value.samples;
@@ -1529,6 +1545,13 @@ void metadata_callback(const FLAC__StreamDecoder *decoder, const FLAC__StreamMet
return;
}
}
+ else if(decoder_session->bps == 0) {
+ flac__utils_printf(stderr, 1, "%s: WARNING: can't apply ReplayGain, bit-per-sample value is invalid\n", decoder_session->inbasefilename);
+ if(decoder_session->treat_warnings_as_errors) {
+ decoder_session->abort_flag = true;
+ return;
+ }
+ }
else {
const char *ls[] = { "no", "peak", "hard" };
const char *ns[] = { "no", "low", "medium", "high" };
diff --git a/src/flac/decode.h b/src/flac/decode.h
index 67bd3c04..24f5723d 100644
--- a/src/flac/decode.h
+++ b/src/flac/decode.h
@@ -1,6 +1,6 @@
/* flac - Command-line FLAC encoder/decoder
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/flac/encode.c b/src/flac/encode.c
index bc71088d..a945b356 100644
--- a/src/flac/encode.c
+++ b/src/flac/encode.c
@@ -1,6 +1,6 @@
/* flac - Command-line FLAC encoder/decoder
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -47,7 +47,6 @@
#endif
#define max(x,y) ((x)>(y)?(x):(y))
-/* this MUST be >= 588 so that sector aligning can take place with one read */
/* this MUST be < 2^sizeof(size_t) / ( FLAC__MAX_CHANNELS * (FLAC__MAX_BITS_PER_SAMPLE/8) ) */
#define CHUNK_OF_SAMPLES 2048
@@ -143,7 +142,7 @@ static FLAC__int32 *input_[FLAC__MAX_CHANNELS];
*/
static FLAC__bool EncoderSession_construct(EncoderSession *e, encode_options_t options, FLAC__off_t infilesize, FILE *infile, const char *infilename, const char *outfilename, const FLAC__byte *lookahead, uint32_t lookahead_length);
static void EncoderSession_destroy(EncoderSession *e);
-static int EncoderSession_finish_ok(EncoderSession *e, int info_align_carry, int info_align_zero, foreign_metadata_t *foreign_metadata, FLAC__bool error_on_compression_fail);
+static int EncoderSession_finish_ok(EncoderSession *e, foreign_metadata_t *foreign_metadata, FLAC__bool error_on_compression_fail);
static int EncoderSession_finish_error(EncoderSession *e);
static FLAC__bool EncoderSession_init_encoder(EncoderSession *e, encode_options_t options);
static FLAC__bool EncoderSession_process(EncoderSession *e, const FLAC__int32 * const buffer[], uint32_t samples);
@@ -327,7 +326,7 @@ static FLAC__bool get_sample_info_wave(EncoderSession *e, encode_options_t optio
}
data_bytes -= (16+8);
}
- if(data_bytes < 16) {
+ if(data_bytes < 16 || data_bytes > (UINT32_MAX-8)) {
flac__utils_printf(stderr, 1, "%s: ERROR: non-standard 'fmt ' chunk has length = %u\n", e->inbasefilename, (uint32_t)data_bytes);
return false;
}
@@ -482,7 +481,6 @@ static FLAC__bool get_sample_info_wave(EncoderSession *e, encode_options_t optio
data_bytes = ds64_data_size;
}
if(options.ignore_chunk_sizes) {
- FLAC__ASSERT(!options.sector_align);
if(data_bytes) {
flac__utils_printf(stderr, 1, "%s: WARNING: 'data' chunk has non-zero size, using --ignore-chunk-sizes is probably a bad idea\n", e->inbasefilename, chunk_id);
if(e->treat_warnings_as_errors)
@@ -717,7 +715,6 @@ static FLAC__bool get_sample_info_aiff(EncoderSession *e, encode_options_t optio
return false;
data_bytes = xx;
if(options.ignore_chunk_sizes) {
- FLAC__ASSERT(!options.sector_align);
if(data_bytes) {
flac__utils_printf(stderr, 1, "%s: WARNING: 'SSND' chunk has non-zero size, using --ignore-chunk-sizes is probably a bad idea\n", e->inbasefilename, chunk_id);
if(e->treat_warnings_as_errors)
@@ -864,7 +861,6 @@ int flac__encode_file(FILE *infile, FLAC__off_t infilesize, const char *infilena
{
EncoderSession encoder_session;
size_t channel_map[FLAC__MAX_CHANNELS];
- int info_align_carry = -1, info_align_zero = -1;
if(!EncoderSession_construct(&encoder_session, options, infilesize, infile, infilename, outfilename, lookahead, lookahead_length))
return 1;
@@ -946,34 +942,19 @@ int flac__encode_file(FILE *infile, FLAC__off_t infilesize, const char *infilena
flac__utils_printf(stderr, 1, "%s: ERROR: unsupported bits-per-sample %u\n", encoder_session.inbasefilename, encoder_session.info.bits_per_sample-encoder_session.info.shift);
return EncoderSession_finish_error(&encoder_session);
}
- if(options.sector_align) {
- if(encoder_session.info.channels != 2) {
- flac__utils_printf(stderr, 1, "%s: ERROR: file has %u channels, must be 2 for --sector-align\n", encoder_session.inbasefilename, encoder_session.info.channels);
- return EncoderSession_finish_error(&encoder_session);
- }
- if(encoder_session.info.sample_rate != 44100) {
- flac__utils_printf(stderr, 1, "%s: ERROR: file's sample rate is %u, must be 44100 for --sector-align\n", encoder_session.inbasefilename, encoder_session.info.sample_rate);
- return EncoderSession_finish_error(&encoder_session);
- }
- if(encoder_session.info.bits_per_sample-encoder_session.info.shift != 16) {
- flac__utils_printf(stderr, 1, "%s: ERROR: file has %u bits-per-sample, must be 16 for --sector-align\n", encoder_session.inbasefilename, encoder_session.info.bits_per_sample-encoder_session.info.shift);
- return EncoderSession_finish_error(&encoder_session);
- }
- }
{
FLAC__uint64 total_samples_in_input; /* WATCHOUT: may be 0 to mean "unknown" */
FLAC__uint64 skip;
FLAC__uint64 until; /* a value of 0 mean end-of-stream (i.e. --until=-0) */
uint32_t consecutive_eos_count = 0;
- uint32_t align_remainder = 0;
switch(options.format) {
case FORMAT_RAW:
if(infilesize < 0)
total_samples_in_input = 0;
else
- total_samples_in_input = (FLAC__uint64)infilesize / encoder_session.info.bytes_per_wide_sample + *options.align_reservoir_samples;
+ total_samples_in_input = (FLAC__uint64)infilesize / encoder_session.info.bytes_per_wide_sample;
break;
case FORMAT_WAVE:
case FORMAT_WAVE64:
@@ -981,7 +962,7 @@ int flac__encode_file(FILE *infile, FLAC__off_t infilesize, const char *infilena
case FORMAT_AIFF:
case FORMAT_AIFF_C:
/* truncation in the division removes any padding byte that was counted in encoder_session.fmt.iff.data_bytes */
- total_samples_in_input = encoder_session.fmt.iff.data_bytes / encoder_session.info.bytes_per_wide_sample + *options.align_reservoir_samples;
+ total_samples_in_input = encoder_session.fmt.iff.data_bytes / encoder_session.info.bytes_per_wide_sample;
/* check for chunks trailing the audio data */
if(!options.ignore_chunk_sizes && !options.format_options.iff.foreign_metadata
@@ -1004,7 +985,7 @@ int flac__encode_file(FILE *infile, FLAC__off_t infilesize, const char *infilena
break;
case FORMAT_FLAC:
case FORMAT_OGGFLAC:
- total_samples_in_input = encoder_session.fmt.flac.client_data.metadata_blocks[0]->data.stream_info.total_samples + *options.align_reservoir_samples;
+ total_samples_in_input = encoder_session.fmt.flac.client_data.metadata_blocks[0]->data.stream_info.total_samples;
break;
default:
FLAC__ASSERT(0);
@@ -1016,12 +997,12 @@ int flac__encode_file(FILE *infile, FLAC__off_t infilesize, const char *infilena
* now that we know the sample rate, canonicalize the
* --skip string to an absolute sample number:
*/
- flac__utils_canonicalize_skip_until_specification(&options.skip_specification, encoder_session.info.sample_rate);
+ if(!flac__utils_canonicalize_skip_until_specification(&options.skip_specification, encoder_session.info.sample_rate)) {
+ flac__utils_printf(stderr, 1, "%s: ERROR: value of --skip is too large\n", encoder_session.inbasefilename, encoder_session.info.bits_per_sample-encoder_session.info.shift);
+ return EncoderSession_finish_error(&encoder_session);
+ }
FLAC__ASSERT(options.skip_specification.value.samples >= 0);
skip = (FLAC__uint64)options.skip_specification.value.samples;
- FLAC__ASSERT(!options.sector_align || (options.format != FORMAT_FLAC && options.format != FORMAT_OGGFLAC && skip == 0));
- /* *options.align_reservoir_samples will be 0 unless --sector-align is used */
- FLAC__ASSERT(options.sector_align || *options.align_reservoir_samples == 0);
/*
* now that we possibly know the input size, canonicalize the
@@ -1030,11 +1011,15 @@ int flac__encode_file(FILE *infile, FLAC__off_t infilesize, const char *infilena
if(!canonicalize_until_specification(&options.until_specification, encoder_session.inbasefilename, encoder_session.info.sample_rate, skip, total_samples_in_input))
return EncoderSession_finish_error(&encoder_session);
until = (FLAC__uint64)options.until_specification.value.samples;
- FLAC__ASSERT(!options.sector_align || until == 0);
/* adjust encoding parameters based on skip and until values */
switch(options.format) {
case FORMAT_RAW:
+ FLAC__ASSERT(sizeof(FLAC__off_t) == 8);
+ if(skip >= INT64_MAX / encoder_session.info.bytes_per_wide_sample) {
+ flac__utils_printf(stderr, 1, "%s: ERROR: value of --skip is too large\n", encoder_session.inbasefilename, encoder_session.info.bits_per_sample-encoder_session.info.shift);
+ return EncoderSession_finish_error(&encoder_session);
+ }
infilesize -= (FLAC__off_t)skip * encoder_session.info.bytes_per_wide_sample;
encoder_session.total_samples_to_encode = total_samples_in_input - skip;
break;
@@ -1043,6 +1028,11 @@ int flac__encode_file(FILE *infile, FLAC__off_t infilesize, const char *infilena
case FORMAT_RF64:
case FORMAT_AIFF:
case FORMAT_AIFF_C:
+ FLAC__ASSERT(sizeof(FLAC__off_t) == 8);
+ if(skip >= INT64_MAX / encoder_session.info.bytes_per_wide_sample) {
+ flac__utils_printf(stderr, 1, "%s: ERROR: value of --skip is too large\n", encoder_session.inbasefilename, encoder_session.info.bits_per_sample-encoder_session.info.shift);
+ return EncoderSession_finish_error(&encoder_session);
+ }
encoder_session.fmt.iff.data_bytes -= skip * encoder_session.info.bytes_per_wide_sample;
if(options.ignore_chunk_sizes) {
encoder_session.total_samples_to_encode = 0;
@@ -1064,21 +1054,12 @@ int flac__encode_file(FILE *infile, FLAC__off_t infilesize, const char *infilena
if(until > 0) {
const FLAC__uint64 trim = total_samples_in_input - until;
FLAC__ASSERT(total_samples_in_input > 0);
- FLAC__ASSERT(!options.sector_align);
if(options.format == FORMAT_RAW)
infilesize -= (FLAC__off_t)trim * encoder_session.info.bytes_per_wide_sample;
else if(EncoderSession_format_is_iff(&encoder_session))
encoder_session.fmt.iff.data_bytes -= trim * encoder_session.info.bytes_per_wide_sample;
encoder_session.total_samples_to_encode -= trim;
}
- if(options.sector_align && (options.format != FORMAT_RAW || infilesize >=0)) { /* for RAW, need to know the filesize */
- FLAC__ASSERT(skip == 0); /* asserted above too, but lest we forget */
- align_remainder = (uint32_t)(encoder_session.total_samples_to_encode % 588);
- if(options.is_last_file)
- encoder_session.total_samples_to_encode += (588-align_remainder); /* will pad with zeroes */
- else
- encoder_session.total_samples_to_encode -= align_remainder; /* will stop short and carry over to next file */
- }
switch(options.format) {
case FORMAT_RAW:
encoder_session.unencoded_size = encoder_session.total_samples_to_encode * encoder_session.info.bytes_per_wide_sample;
@@ -1183,36 +1164,6 @@ int flac__encode_file(FILE *infile, FLAC__off_t infilesize, const char *infilena
}
/*
- * first do any samples in the reservoir
- */
- if(options.sector_align && *options.align_reservoir_samples > 0) {
- FLAC__ASSERT(options.format != FORMAT_FLAC && options.format != FORMAT_OGGFLAC); /* check again */
- if(!EncoderSession_process(&encoder_session, (const FLAC__int32 * const *)options.align_reservoir, *options.align_reservoir_samples)) {
- print_error_with_state(&encoder_session, "ERROR during encoding");
- return EncoderSession_finish_error(&encoder_session);
- }
- }
-
- /*
- * decrement infilesize or the data_bytes counter if we need to align the file
- */
- if(options.sector_align) {
- if(options.is_last_file) {
- *options.align_reservoir_samples = 0;
- }
- else {
- *options.align_reservoir_samples = align_remainder;
- if(options.format == FORMAT_RAW) {
- FLAC__ASSERT(infilesize >= 0);
- infilesize -= (FLAC__off_t)((*options.align_reservoir_samples) * encoder_session.info.bytes_per_wide_sample);
- FLAC__ASSERT(infilesize >= 0);
- }
- else if(EncoderSession_format_is_iff(&encoder_session))
- encoder_session.fmt.iff.data_bytes -= (*options.align_reservoir_samples) * encoder_session.info.bytes_per_wide_sample;
- }
- }
-
- /*
* now do samples from the file
*/
switch(options.format) {
@@ -1265,10 +1216,18 @@ int flac__encode_file(FILE *infile, FLAC__off_t infilesize, const char *infilena
wanted = (size_t) min((FLAC__uint64)wanted, max_input_bytes - total_input_bytes_read);
if(lookahead_length > 0) {
- FLAC__ASSERT(lookahead_length <= wanted);
- memcpy(ubuffer.u8, lookahead, lookahead_length);
- wanted -= lookahead_length;
- bytes_read = lookahead_length;
+ if(lookahead_length <= wanted) {
+ memcpy(ubuffer.u8, lookahead, lookahead_length);
+ wanted -= lookahead_length;
+ bytes_read = lookahead_length;
+ }
+ else {
+ /* This happens when --until is used on a very short file */
+ FLAC__ASSERT(lookahead_length < CHUNK_OF_SAMPLES * encoder_session.info.bytes_per_wide_sample);
+ memcpy(ubuffer.u8, lookahead, wanted);
+ wanted = 0;
+ bytes_read = wanted;
+ }
if(wanted > 0) {
bytes_read += fread(ubuffer.u8+lookahead_length, sizeof(uint8_t), wanted, infile);
if(ferror(infile)) {
@@ -1382,7 +1341,7 @@ int flac__encode_file(FILE *infile, FLAC__off_t infilesize, const char *infilena
break;
}
- if(!FLAC__stream_decoder_process_single(encoder_session.fmt.flac.decoder)) {
+ if(decoder_state == FLAC__STREAM_DECODER_ABORTED || !FLAC__stream_decoder_process_single(encoder_session.fmt.flac.decoder)) {
flac__utils_printf(stderr, 1, "%s: ERROR: while decoding FLAC input, state = %s\n", encoder_session.inbasefilename, FLAC__stream_decoder_get_resolved_state_string(encoder_session.fmt.flac.decoder));
return EncoderSession_finish_error(&encoder_session);
}
@@ -1398,53 +1357,10 @@ int flac__encode_file(FILE *infile, FLAC__off_t infilesize, const char *infilena
return EncoderSession_finish_error(&encoder_session);
}
- /*
- * now read unaligned samples into reservoir or pad with zeroes if necessary
- */
- if(options.sector_align) {
- if(options.is_last_file) {
- uint32_t wide_samples = 588 - align_remainder;
- if(wide_samples < 588) {
- uint32_t channel;
-
- info_align_zero = wide_samples;
- for(channel = 0; channel < encoder_session.info.channels; channel++)
- memset(input_[channel], 0, sizeof(input_[0][0]) * wide_samples);
-
- if(!EncoderSession_process(&encoder_session, (const FLAC__int32 * const *)input_, wide_samples)) {
- print_error_with_state(&encoder_session, "ERROR during encoding");
- return EncoderSession_finish_error(&encoder_session);
- }
- }
- }
- else {
- if(*options.align_reservoir_samples > 0) {
- size_t bytes_read;
- FLAC__ASSERT(CHUNK_OF_SAMPLES >= 588);
- bytes_read = fread(ubuffer.u8, sizeof(uint8_t), (*options.align_reservoir_samples) * encoder_session.info.bytes_per_wide_sample, infile);
- if(bytes_read == 0 && ferror(infile)) {
- flac__utils_printf(stderr, 1, "%s: ERROR during read\n", encoder_session.inbasefilename);
- return EncoderSession_finish_error(&encoder_session);
- }
- else if(bytes_read != (*options.align_reservoir_samples) * encoder_session.info.bytes_per_wide_sample) {
- flac__utils_printf(stderr, 1, "%s: WARNING: unexpected EOF; read %" PRIu64 " bytes; expected %" PRIu64 " samples, got %" PRIu64 " samples\n", encoder_session.inbasefilename, bytes_read, encoder_session.total_samples_to_encode, encoder_session.samples_written);
- if(encoder_session.treat_warnings_as_errors)
- return EncoderSession_finish_error(&encoder_session);
- }
- else {
- info_align_carry = *options.align_reservoir_samples;
- if(!format_input(options.align_reservoir, *options.align_reservoir_samples, encoder_session.info.is_big_endian, encoder_session.info.is_unsigned_samples, encoder_session.info.channels, encoder_session.info.bits_per_sample, encoder_session.info.shift, channel_map))
- return EncoderSession_finish_error(&encoder_session);
- }
- }
- }
- }
}
return EncoderSession_finish_ok(
&encoder_session,
- info_align_carry,
- info_align_zero,
EncoderSession_format_is_iff(&encoder_session)? options.format_options.iff.foreign_metadata : 0,
options.error_on_compression_fail
);
@@ -1520,7 +1436,9 @@ FLAC__bool EncoderSession_construct(EncoderSession *e, encode_options_t options,
e->fmt.flac.client_data.fatal_error = false;
break;
default:
+#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
FLAC__ASSERT(0);
+#endif
/* double protection */
return false;
}
@@ -1571,7 +1489,7 @@ void EncoderSession_destroy(EncoderSession *e)
}
}
-int EncoderSession_finish_ok(EncoderSession *e, int info_align_carry, int info_align_zero, foreign_metadata_t *foreign_metadata, FLAC__bool error_on_compression_fail)
+int EncoderSession_finish_ok(EncoderSession *e, foreign_metadata_t *foreign_metadata, FLAC__bool error_on_compression_fail)
{
FLAC__StreamEncoderState fse_state = FLAC__STREAM_ENCODER_OK;
int ret = 0;
@@ -1597,14 +1515,6 @@ int EncoderSession_finish_ok(EncoderSession *e, int info_align_carry, int info_a
print_verify_error(e);
ret = 1;
}
- else {
- if(info_align_carry >= 0) {
- flac__utils_printf(stderr, 1, "%s: INFO: sector alignment causing %d samples to be carried over\n", e->inbasefilename, info_align_carry);
- }
- if(info_align_zero >= 0) {
- flac__utils_printf(stderr, 1, "%s: INFO: sector alignment causing %d zero samples to be appended\n", e->inbasefilename, info_align_zero);
- }
- }
/*@@@@@@ should this go here or somewhere else? */
if(ret == 0 && foreign_metadata) {
@@ -1626,6 +1536,11 @@ int EncoderSession_finish_ok(EncoderSession *e, int info_align_carry, int info_a
ret = 1;
}
+#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
+ /* Always delete output file when fuzzing */
+ flac_unlink(e->outfilename);
+#endif
+
EncoderSession_destroy(e);
return ret;
@@ -1951,8 +1866,12 @@ FLAC__bool EncoderSession_init_encoder(EncoderSession *e, encode_options_t optio
flac_decoder_data->num_metadata_blocks = j;
if(options.padding > 0)
p = options.padding;
- if(p < 0)
- p = e->total_samples_to_encode / sample_rate < 20*60? FLAC_ENCODE__DEFAULT_PADDING : FLAC_ENCODE__DEFAULT_PADDING*8;
+ if(p < 0) {
+ if(sample_rate == 0)
+ p = FLAC_ENCODE__DEFAULT_PADDING;
+ else
+ p = e->total_samples_to_encode / sample_rate < 20*60? FLAC_ENCODE__DEFAULT_PADDING : FLAC_ENCODE__DEFAULT_PADDING*8;
+ }
if(p > 0)
p += (e->replay_gain ? GRABBAG__REPLAYGAIN_MAX_TAG_SPACE_REQUIRED : 0);
p = min(p, (int)((1u << FLAC__STREAM_METADATA_LENGTH_LEN) - 1));
@@ -2015,7 +1934,10 @@ FLAC__bool EncoderSession_init_encoder(EncoderSession *e, encode_options_t optio
if(options.padding != 0) {
padding.is_last = false; /* the encoder will set this for us */
padding.type = FLAC__METADATA_TYPE_PADDING;
- padding.length = (uint32_t)(options.padding>0? options.padding : (e->total_samples_to_encode / sample_rate < 20*60? FLAC_ENCODE__DEFAULT_PADDING : FLAC_ENCODE__DEFAULT_PADDING*8)) + (e->replay_gain ? GRABBAG__REPLAYGAIN_MAX_TAG_SPACE_REQUIRED : 0);
+ if(sample_rate == 0)
+ padding.length = (uint32_t)(options.padding>0? options.padding : FLAC_ENCODE__DEFAULT_PADDING) + (e->replay_gain ? GRABBAG__REPLAYGAIN_MAX_TAG_SPACE_REQUIRED : 0);
+ else
+ padding.length = (uint32_t)(options.padding>0? options.padding : (e->total_samples_to_encode / sample_rate < 20*60? FLAC_ENCODE__DEFAULT_PADDING : FLAC_ENCODE__DEFAULT_PADDING*8)) + (e->replay_gain ? GRABBAG__REPLAYGAIN_MAX_TAG_SPACE_REQUIRED : 0);
padding.length = min(padding.length, (1u << FLAC__STREAM_METADATA_LENGTH_LEN) - 1);
static_metadata_append(&static_metadata, &padding, /*needs_delete=*/false);
}
@@ -2065,19 +1987,25 @@ FLAC__bool EncoderSession_init_encoder(EncoderSession *e, encode_options_t optio
}
break;
case CST_MAX_LPC_ORDER:
+#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
FLAC__stream_encoder_set_max_lpc_order(e->encoder, options.compression_settings[ic].value.t_unsigned);
+#endif
break;
case CST_QLP_COEFF_PRECISION:
FLAC__stream_encoder_set_qlp_coeff_precision(e->encoder, options.compression_settings[ic].value.t_unsigned);
break;
case CST_DO_QLP_COEFF_PREC_SEARCH:
+#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
FLAC__stream_encoder_set_do_qlp_coeff_prec_search(e->encoder, options.compression_settings[ic].value.t_bool);
+#endif
break;
case CST_DO_ESCAPE_CODING:
FLAC__stream_encoder_set_do_escape_coding(e->encoder, options.compression_settings[ic].value.t_bool);
break;
case CST_DO_EXHAUSTIVE_MODEL_SEARCH:
+#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
FLAC__stream_encoder_set_do_exhaustive_model_search(e->encoder, options.compression_settings[ic].value.t_bool);
+#endif
break;
case CST_MIN_RESIDUAL_PARTITION_ORDER:
FLAC__stream_encoder_set_min_residual_partition_order(e->encoder, options.compression_settings[ic].value.t_unsigned);
@@ -2090,8 +2018,10 @@ FLAC__bool EncoderSession_init_encoder(EncoderSession *e, encode_options_t optio
break;
}
}
+#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
if(*apodizations)
FLAC__stream_encoder_set_apodization(e->encoder, apodizations);
+#endif
FLAC__stream_encoder_set_total_samples_estimate(e->encoder, e->total_samples_to_encode);
FLAC__stream_encoder_set_metadata(e->encoder, (num_metadata > 0)? metadata : 0, num_metadata);
FLAC__stream_encoder_set_limit_min_bitrate(e->encoder, options.limit_min_bitrate);
@@ -2180,14 +2110,13 @@ FLAC__bool convert_to_seek_table_template(const char *requested_seek_points, int
if(num_requested_seek_points == 0 && 0 == cuesheet)
return true;
- if(num_requested_seek_points < 0) {
#if FLAC__HAS_OGG
- /*@@@@@@ workaround ogg bug: too many seekpoints makes table not fit in one page */
- if(e->use_ogg && e->total_samples_to_encode > 0 && e->total_samples_to_encode / e->info.sample_rate / 10 > 230)
- requested_seek_points = "230x;";
- else
+ if(e->use_ogg)
+ return true;
#endif
- requested_seek_points = "10s;";
+
+ if(num_requested_seek_points < 0) {
+ requested_seek_points = "10s;";
num_requested_seek_points = 1;
}
@@ -2226,7 +2155,10 @@ FLAC__bool convert_to_seek_table_template(const char *requested_seek_points, int
FLAC__bool canonicalize_until_specification(utils__SkipUntilSpecification *spec, const char *inbasefilename, uint32_t sample_rate, FLAC__uint64 skip, FLAC__uint64 total_samples_in_input)
{
/* convert from mm:ss.sss to sample number if necessary */
- flac__utils_canonicalize_skip_until_specification(spec, sample_rate);
+ if(!flac__utils_canonicalize_skip_until_specification(spec, sample_rate)) {
+ flac__utils_printf(stderr, 1, "%s: ERROR, value of --until is too large\n", inbasefilename);
+ return false;
+ }
/* special case: if "--until=-0", use the special value '0' to mean "end-of-stream" */
if(spec->is_relative && spec->value.samples == 0) {
@@ -2390,7 +2322,7 @@ FLAC__bool format_input(FLAC__int32 *dest[], uint32_t wide_samples, FLAC__bool i
uint32_t t;
t = ubuffer.u8[b];
t |= (uint32_t)(ubuffer.u8[b+1]) << 8;
- t |= (int32_t)(ubuffer.s8[b+2]) << 16;
+ t |= (uint32_t)((int32_t)(ubuffer.s8[b+2])) << 16;
out[channel][wide_sample] = t;
b += 3*channels;
}
@@ -2876,7 +2808,7 @@ FLAC__bool read_sane_extended(FILE *f, FLAC__uint32 *val, const char *fn)
return false;
e = ((FLAC__uint16)(buf[0])<<8 | (FLAC__uint16)(buf[1]))-0x3FFF;
shift = 63-e;
- if((buf[0]>>7)==1U || e<0 || e>63) {
+ if((buf[0]>>7)==1U || e<0 || e>=63) {
flac__utils_printf(stderr, 1, "%s: ERROR: invalid floating-point value\n", fn);
return false;
}
diff --git a/src/flac/encode.h b/src/flac/encode.h
index 5cb2cb78..2d65c506 100644
--- a/src/flac/encode.h
+++ b/src/flac/encode.h
@@ -1,6 +1,6 @@
/* flac - Command-line FLAC encoder/decoder
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -76,14 +76,10 @@ typedef struct {
FLAC__bool cued_seekpoints;
FLAC__bool channel_map_none; /* --channel-map=none specified, eventually will expand to take actual channel map */
- /* options related to --replay-gain and --sector-align */
FLAC__bool is_first_file;
FLAC__bool is_last_file;
- FLAC__int32 **align_reservoir;
- unsigned *align_reservoir_samples;
FLAC__bool replay_gain;
FLAC__bool ignore_chunk_sizes;
- FLAC__bool sector_align;
FLAC__bool error_on_compression_fail;
FLAC__bool limit_min_bitrate;
FLAC__bool relaxed_foreign_metadata_handling;
diff --git a/src/flac/foreign_metadata.c b/src/flac/foreign_metadata.c
index 63f982cc..f63fc3e6 100644
--- a/src/flac/foreign_metadata.c
+++ b/src/flac/foreign_metadata.c
@@ -1,6 +1,6 @@
/* flac - Command-line FLAC encoder/decoder
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -99,7 +99,12 @@ static FLAC__bool compare_data_(FILE *fin, FILE *fout, size_t size, const char *
static FLAC__bool append_block_(foreign_metadata_t *fm, FLAC__off_t offset, FLAC__uint32 size, const char **error)
{
- foreign_block_t *fb = safe_realloc_nofree_muladd2_(fm->blocks, sizeof(foreign_block_t), /*times (*/fm->num_blocks, /*+*/1/*)*/);
+ foreign_block_t *fb;
+ if(size >= ((1u << FLAC__STREAM_METADATA_LENGTH_LEN) - FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8)) {
+ if(error) *error = "found foreign metadata chunk is too large (max is 16MiB per chunk)";
+ return false;
+ }
+ fb = safe_realloc_nofree_muladd2_(fm->blocks, sizeof(foreign_block_t), /*times (*/fm->num_blocks, /*+*/1/*)*/);
if(fb) {
fb[fm->num_blocks].offset = offset;
fb[fm->num_blocks].size = size;
diff --git a/src/flac/foreign_metadata.h b/src/flac/foreign_metadata.h
index 83d8e81f..fa68d46f 100644
--- a/src/flac/foreign_metadata.h
+++ b/src/flac/foreign_metadata.h
@@ -1,6 +1,6 @@
/* flac - Command-line FLAC encoder/decoder
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/flac/iffscan.c b/src/flac/iffscan.c
index 5b868fd1..a5472e0c 100644
--- a/src/flac/iffscan.c
+++ b/src/flac/iffscan.c
@@ -1,6 +1,6 @@
/* iffscan - Simple AIFF/RIFF chunk scanner
* Copyright (C) 2007-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/flac/local_string_utils.h b/src/flac/local_string_utils.h
index e869d701..01f891f7 100644
--- a/src/flac/local_string_utils.h
+++ b/src/flac/local_string_utils.h
@@ -1,6 +1,6 @@
/* flac - Command-line FLAC encoder/decoder
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/flac/main.c b/src/flac/main.c
index 56c2dfc4..c22e602c 100644
--- a/src/flac/main.c
+++ b/src/flac/main.c
@@ -1,6 +1,6 @@
/* flac - Command-line FLAC encoder/decoder
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -151,7 +151,6 @@ static struct share__option long_options_[] = {
{ "lax" , share__no_argument, 0, 0 },
{ "replay-gain" , share__no_argument, 0, 0 },
{ "ignore-chunk-sizes" , share__no_argument, 0, 0 },
- { "sector-align" , share__no_argument, 0, 0 }, /* DEPRECATED */
{ "seekpoint" , share__required_argument, 0, 'S' },
{ "padding" , share__required_argument, 0, 'P' },
#if FLAC__HAS_OGG
@@ -194,7 +193,6 @@ static struct share__option long_options_[] = {
{ "no-keep-foreign-metadata" , share__no_argument, 0, 0 },
{ "no-replay-gain" , share__no_argument, 0, 0 },
{ "no-ignore-chunk-sizes" , share__no_argument, 0, 0 },
- { "no-sector-align" , share__no_argument, 0, 0 }, /* DEPRECATED */
{ "no-utf8-convert" , share__no_argument, 0, 0 },
{ "no-lax" , share__no_argument, 0, 0 },
#if FLAC__HAS_OGG
@@ -257,7 +255,6 @@ static struct {
FLAC__bool keep_foreign_metadata_if_present;
FLAC__bool replay_gain;
FLAC__bool ignore_chunk_sizes;
- FLAC__bool sector_align;
FLAC__bool utf8_convert; /* true by default, to convert tag strings from locale to utf-8, false if --no-utf8-convert used */
const char *cmdline_forced_outfilename;
const char *output_prefix;
@@ -302,10 +299,6 @@ static struct {
* miscellaneous globals
*/
-static FLAC__int32 align_reservoir_0[588], align_reservoir_1[588]; /* for carrying over samples from --sector-align */ /* DEPRECATED */
-static FLAC__int32 *align_reservoir[2] = { align_reservoir_0, align_reservoir_1 };
-static uint32_t align_reservoir_samples = 0; /* 0 .. 587 */
-
#ifndef FUZZ_TOOL_FLAC
int main(int argc, char *argv[])
@@ -441,8 +434,6 @@ int do_it(void)
if(option_values.ignore_chunk_sizes) {
if(option_values.mode_decode)
return usage_error("ERROR: --ignore-chunk-sizes only allowed for encoding\n");
- if(0 != option_values.sector_align)
- return usage_error("ERROR: --ignore-chunk-sizes not allowed with --sector-align\n");
if(0 != option_values.until_specification)
return usage_error("ERROR: --ignore-chunk-sizes not allowed with --until\n");
if(0 != option_values.cue_specification)
@@ -450,22 +441,6 @@ int do_it(void)
if(0 != option_values.cuesheet_filename)
return usage_error("ERROR: --ignore-chunk-sizes not allowed with --cuesheet\n");
}
- if(option_values.sector_align) {
- if(option_values.mode_decode)
- return usage_error("ERROR: --sector-align only allowed for encoding\n");
- if(0 != option_values.skip_specification)
- return usage_error("ERROR: --sector-align not allowed with --skip\n");
- if(0 != option_values.until_specification)
- return usage_error("ERROR: --sector-align not allowed with --until\n");
- if(0 != option_values.cue_specification)
- return usage_error("ERROR: --sector-align not allowed with --cue\n");
- if(option_values.format_channels >= 0 && option_values.format_channels != 2)
- return usage_error("ERROR: --sector-align can only be done with stereo input\n");
- if(option_values.format_bps >= 0 && option_values.format_bps != 16)
- return usage_error("ERROR: --sector-align can only be done with 16-bit samples\n");
- if(option_values.format_sample_rate >= 0 && option_values.format_sample_rate != 44100)
- return usage_error("ERROR: --sector-align can only be done with a sample rate of 44100\n");
- }
if(option_values.replay_gain) {
if(option_values.force_to_stdout)
return usage_error("ERROR: --replay-gain not allowed with -c/--stdout\n");
@@ -505,7 +480,7 @@ int do_it(void)
flac__utils_printf(stderr, 2, "\n");
flac__utils_printf(stderr, 2, "flac %s\n", FLAC__VERSION_STRING);
- flac__utils_printf(stderr, 2, "Copyright (C) 2000-2009 Josh Coalson, 2011-2022 Xiph.Org Foundation\n");
+ flac__utils_printf(stderr, 2, "Copyright (C) 2000-2009 Josh Coalson, 2011-2023 Xiph.Org Foundation\n");
flac__utils_printf(stderr, 2, "flac comes with ABSOLUTELY NO WARRANTY. This is free software, and you are\n");
flac__utils_printf(stderr, 2, "welcome to redistribute it under certain conditions. Type `flac' for details.\n\n");
@@ -543,8 +518,10 @@ int do_it(void)
for(i = 0, retval = 0; i < option_values.num_files; i++) {
if(0 == strcmp(option_values.filenames[i], "-") && !first)
continue;
- retval |= encode_file(option_values.filenames[i], first, i == (option_values.num_files-1));
- first = false;
+ if(encode_file(option_values.filenames[i], first, i == (option_values.num_files-1)))
+ retval = 1;
+ else
+ first = false;
}
if(option_values.replay_gain && retval == 0) {
float album_gain, album_peak;
@@ -571,6 +548,7 @@ FLAC__bool init_options(void)
{
option_values.show_help = false;
option_values.show_explain = false;
+ option_values.show_version = false;
option_values.mode_decode = false;
option_values.verify = false;
option_values.treat_warnings_as_errors = false;
@@ -602,7 +580,6 @@ FLAC__bool init_options(void)
option_values.keep_foreign_metadata_if_present = false;
option_values.replay_gain = false;
option_values.ignore_chunk_sizes = false;
- option_values.sector_align = false;
option_values.utf8_convert = true;
option_values.cmdline_forced_outfilename = 0;
option_values.output_prefix = 0;
@@ -821,11 +798,6 @@ int parse_option(int short_option, const char *long_option, const char *option_a
else if(0 == strcmp(long_option, "ignore-chunk-sizes")) {
option_values.ignore_chunk_sizes = true;
}
- else if(0 == strcmp(long_option, "sector-align")) {
- flac__utils_printf(stderr, 1, "WARNING: --sector-align is DEPRECATED and may not exist in future versions of flac.\n");
- flac__utils_printf(stderr, 1, " shntool provides similar functionality\n");
- option_values.sector_align = true;
- }
#if FLAC__HAS_OGG
else if(0 == strcmp(long_option, "ogg")) {
option_values.use_ogg = true;
@@ -908,9 +880,6 @@ int parse_option(int short_option, const char *long_option, const char *option_a
else if(0 == strcmp(long_option, "no-ignore-chunk-sizes")) {
option_values.ignore_chunk_sizes = false;
}
- else if(0 == strcmp(long_option, "no-sector-align")) {
- option_values.sector_align = false;
- }
else if(0 == strcmp(long_option, "no-utf8-convert")) {
option_values.utf8_convert = false;
}
@@ -1243,7 +1212,7 @@ static void usage_header(void)
printf("===============================================================================\n");
printf("flac - Command-line FLAC encoder/decoder version %s\n", FLAC__VERSION_STRING);
printf("Copyright (C) 2000-2009 Josh Coalson\n");
- printf("Copyright (C) 2011-2022 Xiph.Org Foundation\n");
+ printf("Copyright (C) 2011-2023 Xiph.Org Foundation\n");
printf("\n");
printf("This program is free software; you can redistribute it and/or\n");
printf("modify it under the terms of the GNU General Public License\n");
@@ -1337,7 +1306,6 @@ void show_help(void)
printf(" -V, --verify Verify a correct encoding\n");
printf(" --lax Allow encoder to generate non-Subset files\n");
printf(" --ignore-chunk-sizes Ignore data chunk sizes in WAVE/AIFF files\n");
- printf(" --sector-align (DEPRECATED) Align multiple files on sector boundaries\n");
printf(" --replay-gain Calculate ReplayGain & store in FLAC tags\n");
printf(" --cuesheet=FILENAME Import cuesheet and store in CUESHEET block\n");
printf(" --picture=SPECIFICATION Import picture and store in PICTURE block\n");
@@ -1403,7 +1371,6 @@ void show_help(void)
printf(" --no-residual-gnuplot\n");
printf(" --no-residual-text\n");
printf(" --no-ignore-chunk-sizes\n");
- printf(" --no-sector-align\n");
printf(" --no-seektable\n");
printf(" --no-silent\n");
printf(" --no-force\n");
@@ -1546,10 +1513,6 @@ void show_explain(void)
printf(" --ignore-chunk-sizes Ignore data chunk sizes in WAVE/AIFF files;\n");
printf(" useful when piping data from programs which\n");
printf(" generate bogus data chunk sizes.\n");
- printf(" --sector-align Align encoding of multiple CD format WAVE files\n");
- printf(" on sector boundaries. This option is DEPRECATED\n");
- printf(" and may not exist in future versions of flac.\n");
- printf(" shntool offers similar functionality.\n");
printf(" --replay-gain Calculate ReplayGain values and store them as\n");
printf(" FLAC tags. Title gains/peaks will be computed\n");
printf(" for each file, and an album gain/peak will be\n");
@@ -1770,7 +1733,6 @@ void show_explain(void)
printf(" --no-residual-gnuplot\n");
printf(" --no-residual-text\n");
printf(" --no-ignore-chunk-sizes\n");
- printf(" --no-sector-align\n");
printf(" --no-seektable\n");
printf(" --no-silent\n");
printf(" --no-force\n");
@@ -1803,13 +1765,11 @@ int encode_file(const char *infilename, FLAC__bool is_first_file, FLAC__bool is_
return 1;
}
-#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
if(0 == strcmp(infilename, "-")) {
infilesize = (FLAC__off_t)(-1);
encode_infile = grabbag__file_get_binary_stdin();
}
else
-#endif
{
infilesize = grabbag__file_get_filesize(infilename);
if(0 == (encode_infile = flac_fopen(infilename, "rb"))) {
@@ -1963,17 +1923,6 @@ int encode_file(const char *infilename, FLAC__bool is_first_file, FLAC__bool is_
}
}
- if(option_values.sector_align && (input_format == FORMAT_FLAC || input_format == FORMAT_OGGFLAC)) {
- flac__utils_printf(stderr, 1, "ERROR: can't use --sector-align when the input file is FLAC or Ogg FLAC\n");
- conditional_fclose(encode_infile);
- return 1;
- }
- if(option_values.sector_align && input_format == FORMAT_RAW && infilesize < 0) {
- flac__utils_printf(stderr, 1, "ERROR: can't use --sector-align when the input size is unknown\n");
- conditional_fclose(encode_infile);
- return 1;
- }
-
if(input_format == FORMAT_RAW) {
if(option_values.format_is_big_endian < 0 || option_values.format_is_unsigned_samples < 0 || option_values.format_channels < 0 || option_values.format_bps < 0 || option_values.format_sample_rate < 0) {
conditional_fclose(encode_infile);
@@ -2035,11 +1984,8 @@ int encode_file(const char *infilename, FLAC__bool is_first_file, FLAC__bool is_
encode_options.channel_map_none = option_values.channel_map_none;
encode_options.is_first_file = is_first_file;
encode_options.is_last_file = is_last_file;
- encode_options.align_reservoir = align_reservoir;
- encode_options.align_reservoir_samples = &align_reservoir_samples;
encode_options.replay_gain = option_values.replay_gain;
encode_options.ignore_chunk_sizes = option_values.ignore_chunk_sizes;
- encode_options.sector_align = option_values.sector_align;
encode_options.vorbis_comment = option_values.vorbis_comment;
FLAC__ASSERT(sizeof(encode_options.pictures) >= sizeof(option_values.pictures));
memcpy(encode_options.pictures, option_values.pictures, sizeof(option_values.pictures));
@@ -2362,12 +2308,6 @@ int decode_file(const char *infilename)
decode_options.channel_map_none = option_values.channel_map_none;
decode_options.format = output_format;
-#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
- /* Can't fuzz from stdin */
- if(0 == strcmp(infilename, "-") || 0 == strcmp(outfilename, "-"))
- return 1;
-#endif
-
if(output_format == FORMAT_RAW) {
decode_options.format_options.raw.is_big_endian = option_values.format_is_big_endian;
decode_options.format_options.raw.is_unsigned_samples = option_values.format_is_unsigned_samples;
diff --git a/src/flac/utils.c b/src/flac/utils.c
index d236dc8e..446150d4 100644
--- a/src/flac/utils.c
+++ b/src/flac/utils.c
@@ -1,6 +1,6 @@
/* flac - Command-line FLAC encoder/decoder
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -56,8 +56,18 @@ static FLAC__bool local__parse_uint64_(const char *s, FLAC__uint64 *value)
return false;
while('\0' != (c = *s++))
- if(c >= '0' && c <= '9')
- ret = ret * 10 + (c - '0');
+ if(c >= '0' && c <= '9') {
+ if(ret > UINT64_MAX / 10) /* check for overflow */
+ return false;
+ else if(ret == UINT64_MAX / 10) {
+ FLAC__uint64 tmp = ret;
+ ret = ret * 10 + (c - '0');
+ if(ret < tmp)
+ return false;
+ }
+ else
+ ret = ret * 10 + (c - '0');
+ }
else
return false;
@@ -300,6 +310,8 @@ FLAC__bool flac__utils_parse_skip_until_specification(const char *s, utils__Skip
if(local__parse_uint64_(s, &val)) {
spec->value_is_samples = true;
+ if(val > INT64_MAX)
+ return false;
spec->value.samples = (FLAC__int64)val;
if(is_negative)
spec->value.samples = -(spec->value.samples);
@@ -318,13 +330,17 @@ FLAC__bool flac__utils_parse_skip_until_specification(const char *s, utils__Skip
return true;
}
-void flac__utils_canonicalize_skip_until_specification(utils__SkipUntilSpecification *spec, uint32_t sample_rate)
+FLAC__bool flac__utils_canonicalize_skip_until_specification(utils__SkipUntilSpecification *spec, uint32_t sample_rate)
{
FLAC__ASSERT(0 != spec);
if(!spec->value_is_samples) {
- spec->value.samples = (FLAC__int64)(spec->value.seconds * (double)sample_rate);
+ double samples = spec->value.seconds * (double)sample_rate;
+ if(samples >= (double)INT64_MAX || samples <= (double)INT64_MIN)
+ return false;
+ spec->value.samples = (FLAC__int64)(samples);
spec->value_is_samples = true;
}
+ return true;
}
FLAC__bool flac__utils_parse_cue_specification(const char *s, utils__CueSpecification *spec)
diff --git a/src/flac/utils.h b/src/flac/utils.h
index 2c1f1536..931b4a6e 100644
--- a/src/flac/utils.h
+++ b/src/flac/utils.h
@@ -1,6 +1,6 @@
/* flac - Command-line FLAC encoder/decoder
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -66,7 +66,7 @@ void stats_print_name(int level, const char *name);
void stats_print_info(int level, const char *format, ...);
FLAC__bool flac__utils_parse_skip_until_specification(const char *s, utils__SkipUntilSpecification *spec);
-void flac__utils_canonicalize_skip_until_specification(utils__SkipUntilSpecification *spec, uint32_t sample_rate);
+FLAC__bool flac__utils_canonicalize_skip_until_specification(utils__SkipUntilSpecification *spec, uint32_t sample_rate);
FLAC__bool flac__utils_parse_cue_specification(const char *s, utils__CueSpecification *spec);
void flac__utils_canonicalize_cue_specification(const utils__CueSpecification *cue_spec, const FLAC__StreamMetadata_CueSheet *cuesheet, FLAC__uint64 total_samples, utils__SkipUntilSpecification *skip_spec, utils__SkipUntilSpecification *until_spec);
diff --git a/src/flac/version.rc b/src/flac/version.rc
new file mode 100644
index 00000000..00842b92
--- /dev/null
+++ b/src/flac/version.rc
@@ -0,0 +1,38 @@
+#include <winver.h>
+#include "config.h"
+
+#if (defined GIT_COMMIT_HASH && defined GIT_COMMIT_DATE)
+# ifdef GIT_COMMIT_TAG
+# define VERSIONSTRING GIT_COMMIT_TAG
+# else
+# define VERSIONSTRING "git-" GIT_COMMIT_HASH
+# endif
+#else
+# define VERSIONSTRING PACKAGE_VERSION
+#endif
+
+#define xstr(s) str(s)
+#define str(s) #s
+
+VS_VERSION_INFO VERSIONINFO
+FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
+FILEFLAGS 0
+FILEOS VOS__WINDOWS32
+FILETYPE VFT_DLL
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904b0"
+ BEGIN
+ VALUE "FileDescription", "flac command line tool for Windows"
+ VALUE "ProductName", "Free Lossless Audio Codec"
+ VALUE "ProductVersion", VERSIONSTRING
+ VALUE "CompanyName", "Xiph.Org"
+ VALUE "LegalCopyright", "2000-2009 Josh Coalson, 2011-2023 Xiph.Org Foundation"
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x409, 1200
+ END
+END
diff --git a/src/flac/vorbiscomment.c b/src/flac/vorbiscomment.c
index 434b5202..3941ec24 100644
--- a/src/flac/vorbiscomment.c
+++ b/src/flac/vorbiscomment.c
@@ -1,6 +1,6 @@
/* flac - Command-line FLAC encoder/decoder
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/flac/vorbiscomment.h b/src/flac/vorbiscomment.h
index 6da6452d..a6dcb164 100644
--- a/src/flac/vorbiscomment.h
+++ b/src/flac/vorbiscomment.h
@@ -1,6 +1,6 @@
/* flac - Command-line FLAC encoder/decoder
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/libFLAC++/CMakeLists.txt b/src/libFLAC++/CMakeLists.txt
index 81d466a4..3be43ba1 100644
--- a/src/libFLAC++/CMakeLists.txt
+++ b/src/libFLAC++/CMakeLists.txt
@@ -1,7 +1,8 @@
add_library(FLAC++
metadata.cpp
stream_decoder.cpp
- stream_encoder.cpp)
+ stream_encoder.cpp
+ version.rc)
set_property(TARGET FLAC++ PROPERTY PROJECT_LABEL "libFLAC++")
target_compile_definitions(FLAC++
PRIVATE $<$<BOOL:${BUILD_SHARED_LIBS}>:FLACPP_API_EXPORTS>
@@ -15,7 +16,7 @@ target_include_directories(FLAC++ INTERFACE
target_link_libraries(FLAC++ PUBLIC FLAC)
if(BUILD_SHARED_LIBS)
set_target_properties(FLAC++ PROPERTIES
- VERSION 10.0.0
+ VERSION 10.0.1
SOVERSION 10)
if(NOT WIN32)
set_target_properties(FLAC++ PROPERTIES CXX_VISIBILITY_PRESET hidden)
diff --git a/src/libFLAC++/Makefile.am b/src/libFLAC++/Makefile.am
index 77d2e6fd..0b2853b2 100644
--- a/src/libFLAC++/Makefile.am
+++ b/src/libFLAC++/Makefile.am
@@ -1,6 +1,6 @@
# libFLAC++ - Free Lossless Audio Codec library
# Copyright (C) 2002-2009 Josh Coalson
-# Copyright (C) 2011-2022 Xiph.Org Foundation
+# Copyright (C) 2011-2023 Xiph.Org Foundation
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -41,17 +41,28 @@ AM_CPPFLAGS = -I$(top_builddir) -I$(srcdir)/include -I$(top_srcdir)/include
EXTRA_DIST = \
CMakeLists.txt \
flac++.pc.in \
- libFLAC++.m4
+ libFLAC++.m4 \
+ version.rc
libFLAC___sources = \
metadata.cpp \
stream_decoder.cpp \
stream_encoder.cpp
+if OS_IS_WINDOWS
+if HAVE_WINDRES
+libFLAC___la_DEPENDENCIES = version.o
+windows_resource_link = -Wl,version.o
+endif
+endif
+
# see 'http://www.gnu.org/software/libtool/manual/libtool.html#Libtool-versioning' for numbering convention
-libFLAC___la_LDFLAGS = $(AM_LDFLAGS) -no-undefined -version-info 10:0:0
+libFLAC___la_LDFLAGS = $(AM_LDFLAGS) -no-undefined -version-info 10:1:0 $(windows_resource_link)
libFLAC___la_LIBADD = ../libFLAC/libFLAC.la
libFLAC___la_SOURCES = $(libFLAC___sources)
libFLAC___static_la_SOURCES = $(libFLAC___sources)
libFLAC___static_la_LIBADD = ../libFLAC/libFLAC-static.la
+
+.rc.o:
+ $(RC) $(AM_CPPFLAGS) $< $@
diff --git a/src/libFLAC++/metadata.cpp b/src/libFLAC++/metadata.cpp
index c6dd9372..beab1109 100644
--- a/src/libFLAC++/metadata.cpp
+++ b/src/libFLAC++/metadata.cpp
@@ -1,6 +1,6 @@
/* libFLAC++ - Free Lossless Audio Codec library
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC++/stream_decoder.cpp b/src/libFLAC++/stream_decoder.cpp
index 7adb8107..6e351d94 100644
--- a/src/libFLAC++/stream_decoder.cpp
+++ b/src/libFLAC++/stream_decoder.cpp
@@ -1,6 +1,6 @@
/* libFLAC++ - Free Lossless Audio Codec library
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC++/stream_encoder.cpp b/src/libFLAC++/stream_encoder.cpp
index 43ec1afd..83771294 100644
--- a/src/libFLAC++/stream_encoder.cpp
+++ b/src/libFLAC++/stream_encoder.cpp
@@ -1,6 +1,6 @@
/* libFLAC++ - Free Lossless Audio Codec library
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC++/version.rc b/src/libFLAC++/version.rc
new file mode 100644
index 00000000..14efba06
--- /dev/null
+++ b/src/libFLAC++/version.rc
@@ -0,0 +1,40 @@
+#include <winver.h>
+#include "config.h"
+#include "FLAC++/export.h"
+
+#if (defined GIT_COMMIT_HASH && defined GIT_COMMIT_DATE)
+# ifdef GIT_COMMIT_TAG
+# define VERSIONSTRING GIT_COMMIT_TAG
+# else
+# define VERSIONSTRING "git-" GIT_COMMIT_HASH
+# endif
+#else
+# define VERSIONSTRING PACKAGE_VERSION
+#endif
+
+#define xstr(s) str(s)
+#define str(s) #s
+
+VS_VERSION_INFO VERSIONINFO
+FILEVERSION FLACPP_API_VERSION_CURRENT,FLACPP_API_VERSION_REVISION,0,0
+FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
+FILEFLAGS 0
+FILEOS VOS__WINDOWS32
+FILETYPE VFT_DLL
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904b0"
+ BEGIN
+ VALUE "FileDescription", "libFLAC++ for Windows"
+ VALUE "ProductName", "Free Lossless Audio Codec"
+ VALUE "ProductVersion", VERSIONSTRING
+ VALUE "CompanyName", "Xiph.Org"
+ VALUE "LegalCopyright", "2000-2009 Josh Coalson, 2011-2023 Xiph.Org Foundation"
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x409, 1200
+ END
+END
diff --git a/src/libFLAC/CMakeLists.txt b/src/libFLAC/CMakeLists.txt
index e6c20735..cf7368f6 100644
--- a/src/libFLAC/CMakeLists.txt
+++ b/src/libFLAC/CMakeLists.txt
@@ -63,6 +63,7 @@ add_library(FLAC
stream_encoder_intrin_ssse3.c
stream_encoder_intrin_avx2.c
stream_encoder_framing.c
+ version.rc
window.c
$<$<BOOL:${WIN32}>:../../include/share/win_utf8_io.h>
$<$<BOOL:${WIN32}>:../share/win_utf8_io/win_utf8_io.c>
@@ -90,7 +91,7 @@ if(TARGET Ogg::ogg)
endif()
if(BUILD_SHARED_LIBS)
set_target_properties(FLAC PROPERTIES
- VERSION 12.0.0
+ VERSION 12.1.0
SOVERSION 12)
if(NOT WIN32)
set_target_properties(FLAC PROPERTIES C_VISIBILITY_PRESET hidden)
diff --git a/src/libFLAC/Makefile.am b/src/libFLAC/Makefile.am
index 40e3308d..618939df 100644
--- a/src/libFLAC/Makefile.am
+++ b/src/libFLAC/Makefile.am
@@ -1,6 +1,6 @@
# libFLAC - Free Lossless Audio Codec library
# Copyright (C) 2001-2009 Josh Coalson
-# Copyright (C) 2011-2022 Xiph.Org Foundation
+# Copyright (C) 2011-2023 Xiph.Org Foundation
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -56,12 +56,18 @@ EXTRA_DIST = \
CMakeLists.txt \
flac.pc.in \
libFLAC.m4 \
+ version.rc \
+ deduplication/bitreader_read_rice_signed_block.c \
deduplication/lpc_compute_autocorrelation_intrin.c \
deduplication/lpc_compute_autocorrelation_intrin_sse2.c \
deduplication/lpc_compute_autocorrelation_intrin_neon.c
if OS_IS_WINDOWS
windows_unicode_compat = ../share/win_utf8_io/win_utf8_io.c
+if HAVE_WINDRES
+libFLAC_la_DEPENDENCIES = version.o
+windows_resource_link = -Wl,version.o
+endif
endif
if FLaC__HAS_OGG
@@ -73,7 +79,7 @@ extra_ogg_sources = \
endif
# see 'http://www.gnu.org/software/libtool/manual/libtool.html#Libtool-versioning' for numbering convention
-libFLAC_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined -version-info 12:0:0
+libFLAC_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined -version-info 13:0:1 $(windows_resource_link)
libFLAC_sources = \
bitmath.c \
@@ -112,3 +118,6 @@ libFLAC_la_SOURCES = $(libFLAC_sources)
# needed for test_libFLAC
libFLAC_static_la_SOURCES = $(libFLAC_sources)
+
+.rc.o:
+ $(RC) $(AM_CPPFLAGS) $< $@
diff --git a/src/libFLAC/bitmath.c b/src/libFLAC/bitmath.c
index 7c73cc05..077486b6 100644
--- a/src/libFLAC/bitmath.c
+++ b/src/libFLAC/bitmath.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2001-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/bitreader.c b/src/libFLAC/bitreader.c
index 56f992e4..829b308e 100644
--- a/src/libFLAC/bitreader.c
+++ b/src/libFLAC/bitreader.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -39,6 +39,7 @@
#include "private/bitmath.h"
#include "private/bitreader.h"
#include "private/crc.h"
+#include "private/cpu.h"
#include "private/macros.h"
#include "FLAC/assert.h"
#include "share/compat.h"
@@ -163,11 +164,11 @@ static FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br)
brword preswap_backup;
#endif
- /* invalidate last seen framesync */
- br->last_seen_framesync = -1;
-
/* first shift the unconsumed buffer data toward the front as much as possible */
if(br->consumed_words > 0) {
+ /* invalidate last seen framesync */
+ br->last_seen_framesync = -1;
+
crc16_update_block_(br); /* CRC consumed words */
start = br->consumed_words;
@@ -831,149 +832,13 @@ FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, uint3
/* this is by far the most heavily used reader call. it ain't pretty but it's fast */
FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], uint32_t nvals, uint32_t parameter)
-{
- /* try and get br->consumed_words and br->consumed_bits into register;
- * must remember to flush them back to *br before calling other
- * bitreader functions that use them, and before returning */
- uint32_t cwords, words, lsbs, msbs, x, y, limit;
- uint32_t ucbits; /* keep track of the number of unconsumed bits in word */
- brword b;
- int *val, *end;
-
- FLAC__ASSERT(0 != br);
- FLAC__ASSERT(0 != br->buffer);
- /* WATCHOUT: code does not work with <32bit words; we can make things much faster with this assertion */
- FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
- FLAC__ASSERT(parameter < 32);
- /* the above two asserts also guarantee that the binary part never straddles more than 2 words, so we don't have to loop to read it */
-
- limit = UINT32_MAX >> parameter; /* Maximal msbs that can occur with residual bounded to int32_t */
-
- val = vals;
- end = vals + nvals;
-
- if(parameter == 0) {
- while(val < end) {
- /* read the unary MSBs and end bit */
- if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
- return false;
- /* Checking limit here would be overzealous: coding UINT32_MAX
- * with parameter == 0 would take 4GiB */
- *val++ = (int)(msbs >> 1) ^ -(int)(msbs & 1);
- }
-
- return true;
- }
-
- FLAC__ASSERT(parameter > 0);
-
- cwords = br->consumed_words;
- words = br->words;
-
- /* if we've not consumed up to a partial tail word... */
- if(cwords >= words) {
- x = 0;
- goto process_tail;
- }
-
- ucbits = FLAC__BITS_PER_WORD - br->consumed_bits;
- b = br->buffer[cwords] << br->consumed_bits; /* keep unconsumed bits aligned to left */
-
- while(val < end) {
- /* read the unary MSBs and end bit */
- x = y = COUNT_ZERO_MSBS2(b);
- if(x == FLAC__BITS_PER_WORD) {
- x = ucbits;
- do {
- /* didn't find stop bit yet, have to keep going... */
- cwords++;
- if (cwords >= words)
- goto incomplete_msbs;
- b = br->buffer[cwords];
- y = COUNT_ZERO_MSBS2(b);
- x += y;
- } while(y == FLAC__BITS_PER_WORD);
- }
- b <<= y;
- b <<= 1; /* account for stop bit */
- ucbits = (ucbits - x - 1) % FLAC__BITS_PER_WORD;
- msbs = x;
+#include "deduplication/bitreader_read_rice_signed_block.c"
- if(x > limit)
- return false;
-
- /* read the binary LSBs */
- x = (FLAC__uint32)(b >> (FLAC__BITS_PER_WORD - parameter)); /* parameter < 32, so we can cast to 32-bit uint32_t */
- if(parameter <= ucbits) {
- ucbits -= parameter;
- b <<= parameter;
- } else {
- /* there are still bits left to read, they will all be in the next word */
- cwords++;
- if (cwords >= words)
- goto incomplete_lsbs;
- b = br->buffer[cwords];
- ucbits += FLAC__BITS_PER_WORD - parameter;
- x |= (FLAC__uint32)(b >> ucbits);
- b <<= FLAC__BITS_PER_WORD - ucbits;
- }
- lsbs = x;
-
- /* compose the value */
- x = (msbs << parameter) | lsbs;
- *val++ = (int)(x >> 1) ^ -(int)(x & 1);
-
- continue;
-
- /* at this point we've eaten up all the whole words */
-process_tail:
- do {
- if(0) {
-incomplete_msbs:
- br->consumed_bits = 0;
- br->consumed_words = cwords;
- }
-
- /* read the unary MSBs and end bit */
- if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
- return false;
- msbs += x;
- x = ucbits = 0;
-
- if(0) {
-incomplete_lsbs:
- br->consumed_bits = 0;
- br->consumed_words = cwords;
- }
-
- /* read the binary LSBs */
- if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, parameter - ucbits))
- return false;
- lsbs = x | lsbs;
-
- /* compose the value */
- x = (msbs << parameter) | lsbs;
- *val++ = (int)(x >> 1) ^ -(int)(x & 1);
- x = 0;
-
- cwords = br->consumed_words;
- words = br->words;
- ucbits = FLAC__BITS_PER_WORD - br->consumed_bits;
- b = cwords < br->capacity ? br->buffer[cwords] << br->consumed_bits : 0;
- } while(cwords >= words && val < end);
- }
-
- if(ucbits == 0 && cwords < words) {
- /* don't leave the head word with no unconsumed bits */
- cwords++;
- ucbits = FLAC__BITS_PER_WORD;
- }
-
- br->consumed_bits = FLAC__BITS_PER_WORD - ucbits;
- br->consumed_words = cwords;
-
- return true;
-}
+#ifdef FLAC__BMI2_SUPPORTED
+FLAC__SSE_TARGET("bmi2")
+FLAC__bool FLAC__bitreader_read_rice_signed_block_bmi2(FLAC__BitReader *br, int vals[], uint32_t nvals, uint32_t parameter)
+#include "deduplication/bitreader_read_rice_signed_block.c"
+#endif
#if 0 /* UNUSED */
FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, uint32_t parameter)
diff --git a/src/libFLAC/bitwriter.c b/src/libFLAC/bitwriter.c
index 423faec8..1d7be808 100644
--- a/src/libFLAC/bitwriter.c
+++ b/src/libFLAC/bitwriter.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/cpu.c b/src/libFLAC/cpu.c
index 51f72ddf..d088e3c0 100644
--- a/src/libFLAC/cpu.c
+++ b/src/libFLAC/cpu.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2001-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -76,6 +76,7 @@ static const uint32_t FLAC__CPUINFO_X86_CPUID_FMA = 0x00001000;
/* these are flags in EBX of CPUID AX=00000007 */
static const uint32_t FLAC__CPUINFO_X86_CPUID_AVX2 = 0x00000020;
+static const uint32_t FLAC__CPUINFO_X86_CPUID_BMI2 = 0x00000100;
static uint32_t
cpu_xgetbv_x86(void)
@@ -186,6 +187,7 @@ x86_cpu_info (FLAC__CPUInfo *info)
info->x86.fma = (flags_ecx & FLAC__CPUINFO_X86_CPUID_FMA ) ? true : false;
cpuinfo_x86(7, &flags_eax, &flags_ebx, &flags_ecx, &flags_edx);
info->x86.avx2 = (flags_ebx & FLAC__CPUINFO_X86_CPUID_AVX2 ) ? true : false;
+ info->x86.bmi2 = (flags_ebx & FLAC__CPUINFO_X86_CPUID_BMI2 ) ? true : false;
}
#if defined FLAC__CPU_IA32
@@ -206,6 +208,7 @@ x86_cpu_info (FLAC__CPUInfo *info)
dfprintf(stderr, " AVX ........ %c\n", info->x86.avx ? 'Y' : 'n');
dfprintf(stderr, " FMA ........ %c\n", info->x86.fma ? 'Y' : 'n');
dfprintf(stderr, " AVX2 ....... %c\n", info->x86.avx2 ? 'Y' : 'n');
+ dfprintf(stderr, " BMI2 ....... %c\n", info->x86.bmi2 ? 'Y' : 'n');
}
/*
diff --git a/src/libFLAC/crc.c b/src/libFLAC/crc.c
index 4f47e986..9e488e9b 100644
--- a/src/libFLAC/crc.c
+++ b/src/libFLAC/crc.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/deduplication/bitreader_read_rice_signed_block.c b/src/libFLAC/deduplication/bitreader_read_rice_signed_block.c
new file mode 100644
index 00000000..75ed47f7
--- /dev/null
+++ b/src/libFLAC/deduplication/bitreader_read_rice_signed_block.c
@@ -0,0 +1,143 @@
+{
+ /* try and get br->consumed_words and br->consumed_bits into register;
+ * must remember to flush them back to *br before calling other
+ * bitreader functions that use them, and before returning */
+ uint32_t cwords, words, lsbs, msbs, x, y, limit;
+ uint32_t ucbits; /* keep track of the number of unconsumed bits in word */
+ brword b;
+ int *val, *end;
+
+ FLAC__ASSERT(0 != br);
+ FLAC__ASSERT(0 != br->buffer);
+ /* WATCHOUT: code does not work with <32bit words; we can make things much faster with this assertion */
+ FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
+ FLAC__ASSERT(parameter < 32);
+ /* the above two asserts also guarantee that the binary part never straddles more than 2 words, so we don't have to loop to read it */
+
+ limit = UINT32_MAX >> parameter; /* Maximal msbs that can occur with residual bounded to int32_t */
+
+ val = vals;
+ end = vals + nvals;
+
+ if(parameter == 0) {
+ while(val < end) {
+ /* read the unary MSBs and end bit */
+ if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
+ return false;
+ /* Checking limit here would be overzealous: coding UINT32_MAX
+ * with parameter == 0 would take 4GiB */
+ *val++ = (int)(msbs >> 1) ^ -(int)(msbs & 1);
+ }
+
+ return true;
+ }
+
+ FLAC__ASSERT(parameter > 0);
+
+ cwords = br->consumed_words;
+ words = br->words;
+
+ /* if we've not consumed up to a partial tail word... */
+ if(cwords >= words) {
+ x = 0;
+ goto process_tail;
+ }
+
+ ucbits = FLAC__BITS_PER_WORD - br->consumed_bits;
+ b = br->buffer[cwords] << br->consumed_bits; /* keep unconsumed bits aligned to left */
+
+ while(val < end) {
+ /* read the unary MSBs and end bit */
+ x = y = COUNT_ZERO_MSBS2(b);
+ if(x == FLAC__BITS_PER_WORD) {
+ x = ucbits;
+ do {
+ /* didn't find stop bit yet, have to keep going... */
+ cwords++;
+ if (cwords >= words)
+ goto incomplete_msbs;
+ b = br->buffer[cwords];
+ y = COUNT_ZERO_MSBS2(b);
+ x += y;
+ } while(y == FLAC__BITS_PER_WORD);
+ }
+ b <<= y;
+ b <<= 1; /* account for stop bit */
+ ucbits = (ucbits - x - 1) % FLAC__BITS_PER_WORD;
+ msbs = x;
+
+ if(x > limit)
+ return false;
+
+ /* read the binary LSBs */
+ x = (FLAC__uint32)(b >> (FLAC__BITS_PER_WORD - parameter)); /* parameter < 32, so we can cast to 32-bit uint32_t */
+ if(parameter <= ucbits) {
+ ucbits -= parameter;
+ b <<= parameter;
+ } else {
+ /* there are still bits left to read, they will all be in the next word */
+ cwords++;
+ if (cwords >= words)
+ goto incomplete_lsbs;
+ b = br->buffer[cwords];
+ ucbits += FLAC__BITS_PER_WORD - parameter;
+ x |= (FLAC__uint32)(b >> ucbits);
+ b <<= FLAC__BITS_PER_WORD - ucbits;
+ }
+ lsbs = x;
+
+ /* compose the value */
+ x = (msbs << parameter) | lsbs;
+ *val++ = (int)(x >> 1) ^ -(int)(x & 1);
+
+ continue;
+
+ /* at this point we've eaten up all the whole words */
+process_tail:
+ do {
+ if(0) {
+incomplete_msbs:
+ br->consumed_bits = 0;
+ br->consumed_words = cwords;
+ }
+
+ /* read the unary MSBs and end bit */
+ if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
+ return false;
+ msbs += x;
+ x = ucbits = 0;
+
+ if(0) {
+incomplete_lsbs:
+ br->consumed_bits = 0;
+ br->consumed_words = cwords;
+ }
+
+ /* read the binary LSBs */
+ if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, parameter - ucbits))
+ return false;
+ lsbs = x | lsbs;
+
+ /* compose the value */
+ x = (msbs << parameter) | lsbs;
+ *val++ = (int)(x >> 1) ^ -(int)(x & 1);
+ x = 0;
+
+ cwords = br->consumed_words;
+ words = br->words;
+ ucbits = FLAC__BITS_PER_WORD - br->consumed_bits;
+ b = cwords < br->capacity ? br->buffer[cwords] << br->consumed_bits : 0;
+ } while(cwords >= words && val < end);
+ }
+
+ if(ucbits == 0 && cwords < words) {
+ /* don't leave the head word with no unconsumed bits */
+ cwords++;
+ ucbits = FLAC__BITS_PER_WORD;
+ }
+
+ br->consumed_bits = FLAC__BITS_PER_WORD - ucbits;
+ br->consumed_words = cwords;
+
+ return true;
+}
diff --git a/src/libFLAC/fixed.c b/src/libFLAC/fixed.c
index ee883aac..04235ba0 100644
--- a/src/libFLAC/fixed.c
+++ b/src/libFLAC/fixed.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/fixed_intrin_avx2.c b/src/libFLAC/fixed_intrin_avx2.c
index 668e8d3e..85fc4a6d 100644
--- a/src/libFLAC/fixed_intrin_avx2.c
+++ b/src/libFLAC/fixed_intrin_avx2.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -80,16 +80,16 @@ uint32_t FLAC__fixed_compute_best_predictor_wide_intrin_avx2(const FLAC__int32 d
prev_err2_scalar[i] = prev_err1_scalar[i] - (data[-2+i*(data_len_int/4)] - data[-3+i*(data_len_int/4)]);
prev_err3_scalar[i] = prev_err2_scalar[i] - (data[-2+i*(data_len_int/4)] - 2*data[-3+i*(data_len_int/4)] + data[-4+i*(data_len_int/4)]);
}
- prev_err0 = _mm256_loadu_si256((const __m256i*)prev_err0_scalar);
- prev_err1 = _mm256_loadu_si256((const __m256i*)prev_err1_scalar);
- prev_err2 = _mm256_loadu_si256((const __m256i*)prev_err2_scalar);
- prev_err3 = _mm256_loadu_si256((const __m256i*)prev_err3_scalar);
+ prev_err0 = _mm256_loadu_si256((const __m256i*)(void*)prev_err0_scalar);
+ prev_err1 = _mm256_loadu_si256((const __m256i*)(void*)prev_err1_scalar);
+ prev_err2 = _mm256_loadu_si256((const __m256i*)(void*)prev_err2_scalar);
+ prev_err3 = _mm256_loadu_si256((const __m256i*)(void*)prev_err3_scalar);
for(i = 0; i < data_len_int / 4; i++){
data_scalar[0] = data[i];
data_scalar[1] = data[i+data_len/4];
data_scalar[2] = data[i+2*data_len/4];
data_scalar[3] = data[i+3*data_len/4];
- tempA = _mm256_loadu_si256((const __m256i*)data_scalar);
+ tempA = _mm256_loadu_si256((const __m256i*)(void*)data_scalar);
/* Next three intrinsics calculate tempB as abs of tempA */
bitmask = _mm256_cmpgt_epi64(_mm256_set1_epi64x(0), tempA);
tempB = _mm256_xor_si256(tempA, bitmask);
@@ -124,15 +124,15 @@ uint32_t FLAC__fixed_compute_best_predictor_wide_intrin_avx2(const FLAC__int32 d
tempB = _mm256_sub_epi64(tempB, bitmask);
total_err4 = _mm256_add_epi64(total_err4,tempB);
}
- _mm256_storeu_si256((__m256i*)data_scalar,total_err0);
+ _mm256_storeu_si256((__m256i*)(void*)data_scalar,total_err0);
total_error_0 = data_scalar[0] + data_scalar[1] + data_scalar[2] + data_scalar[3];
- _mm256_storeu_si256((__m256i*)data_scalar,total_err1);
+ _mm256_storeu_si256((__m256i*)(void*)data_scalar,total_err1);
total_error_1 = data_scalar[0] + data_scalar[1] + data_scalar[2] + data_scalar[3];
- _mm256_storeu_si256((__m256i*)data_scalar,total_err2);
+ _mm256_storeu_si256((__m256i*)(void*)data_scalar,total_err2);
total_error_2 = data_scalar[0] + data_scalar[1] + data_scalar[2] + data_scalar[3];
- _mm256_storeu_si256((__m256i*)data_scalar,total_err3);
+ _mm256_storeu_si256((__m256i*)(void*)data_scalar,total_err3);
total_error_3 = data_scalar[0] + data_scalar[1] + data_scalar[2] + data_scalar[3];
- _mm256_storeu_si256((__m256i*)data_scalar,total_err4);
+ _mm256_storeu_si256((__m256i*)(void*)data_scalar,total_err4);
total_error_4 = data_scalar[0] + data_scalar[1] + data_scalar[2] + data_scalar[3];
/* Ignore the remainder, we're ignore the first few samples too */
@@ -236,22 +236,22 @@ uint32_t FLAC__fixed_compute_best_predictor_limit_residual_intrin_avx2(const FLA
prev_err2_scalar[i] = prev_err1_scalar[i] - ((FLAC__int64)(data[-2+i*(data_len_int/4)]) - data[-3+i*(data_len_int/4)]);
prev_err3_scalar[i] = prev_err2_scalar[i] - ((FLAC__int64)(data[-2+i*(data_len_int/4)]) - 2*(FLAC__int64)(data[-3+i*(data_len_int/4)]) + data[-4+i*(data_len_int/4)]);
}
- prev_err0 = _mm256_loadu_si256((const __m256i*)prev_err0_scalar);
- prev_err1 = _mm256_loadu_si256((const __m256i*)prev_err1_scalar);
- prev_err2 = _mm256_loadu_si256((const __m256i*)prev_err2_scalar);
- prev_err3 = _mm256_loadu_si256((const __m256i*)prev_err3_scalar);
+ prev_err0 = _mm256_loadu_si256((const __m256i*)(void*)prev_err0_scalar);
+ prev_err1 = _mm256_loadu_si256((const __m256i*)(void*)prev_err1_scalar);
+ prev_err2 = _mm256_loadu_si256((const __m256i*)(void*)prev_err2_scalar);
+ prev_err3 = _mm256_loadu_si256((const __m256i*)(void*)prev_err3_scalar);
for(i = 0; i < data_len_int / 4; i++){
data_scalar[0] = data[i];
data_scalar[1] = data[i+data_len/4];
data_scalar[2] = data[i+2*data_len/4];
data_scalar[3] = data[i+3*data_len/4];
- tempA = _mm256_loadu_si256((const __m256i*)data_scalar);
+ tempA = _mm256_loadu_si256((const __m256i*)(void*)data_scalar);
/* Next three intrinsics calculate tempB as abs of tempA */
bitmask = _mm256_cmpgt_epi64(_mm256_set1_epi64x(0), tempA);
tempB = _mm256_xor_si256(tempA, bitmask);
tempB = _mm256_sub_epi64(tempB, bitmask);
total_err0 = _mm256_add_epi64(total_err0,tempB);
- shadow_err0 = _mm256_xor_si256(shadow_err0,tempB);
+ shadow_err0 = _mm256_or_si256(shadow_err0,tempB);
tempB = _mm256_sub_epi64(tempA,prev_err0);
prev_err0 = tempA;
/* Next three intrinsics calculate tempA as abs of tempB */
@@ -259,7 +259,7 @@ uint32_t FLAC__fixed_compute_best_predictor_limit_residual_intrin_avx2(const FLA
tempA = _mm256_xor_si256(tempB, bitmask);
tempA = _mm256_sub_epi64(tempA, bitmask);
total_err1 = _mm256_add_epi64(total_err1,tempA);
- shadow_err1 = _mm256_xor_si256(shadow_err1,tempA);
+ shadow_err1 = _mm256_or_si256(shadow_err1,tempA);
tempA = _mm256_sub_epi64(tempB,prev_err1);
prev_err1 = tempB;
/* Next three intrinsics calculate tempB as abs of tempA */
@@ -267,7 +267,7 @@ uint32_t FLAC__fixed_compute_best_predictor_limit_residual_intrin_avx2(const FLA
tempB = _mm256_xor_si256(tempA, bitmask);
tempB = _mm256_sub_epi64(tempB, bitmask);
total_err2 = _mm256_add_epi64(total_err2,tempB);
- shadow_err2 = _mm256_xor_si256(shadow_err2,tempB);
+ shadow_err2 = _mm256_or_si256(shadow_err2,tempB);
tempB = _mm256_sub_epi64(tempA,prev_err2);
prev_err2 = tempA;
/* Next three intrinsics calculate tempA as abs of tempB */
@@ -275,7 +275,7 @@ uint32_t FLAC__fixed_compute_best_predictor_limit_residual_intrin_avx2(const FLA
tempA = _mm256_xor_si256(tempB, bitmask);
tempA = _mm256_sub_epi64(tempA, bitmask);
total_err3 = _mm256_add_epi64(total_err3,tempA);
- shadow_err3 = _mm256_xor_si256(shadow_err3,tempA);
+ shadow_err3 = _mm256_or_si256(shadow_err3,tempA);
tempA = _mm256_sub_epi64(tempB,prev_err3);
prev_err3 = tempB;
/* Next three intrinsics calculate tempB as abs of tempA */
@@ -283,28 +283,28 @@ uint32_t FLAC__fixed_compute_best_predictor_limit_residual_intrin_avx2(const FLA
tempB = _mm256_xor_si256(tempA, bitmask);
tempB = _mm256_sub_epi64(tempB, bitmask);
total_err4 = _mm256_add_epi64(total_err4,tempB);
- shadow_err4 = _mm256_xor_si256(shadow_err4,tempB);
+ shadow_err4 = _mm256_or_si256(shadow_err4,tempB);
}
- _mm256_storeu_si256((__m256i*)data_scalar,total_err0);
+ _mm256_storeu_si256((__m256i*)(void*)data_scalar,total_err0);
total_error_0 += data_scalar[0] + data_scalar[1] + data_scalar[2] + data_scalar[3];
- _mm256_storeu_si256((__m256i*)data_scalar,total_err1);
+ _mm256_storeu_si256((__m256i*)(void*)data_scalar,total_err1);
total_error_1 += data_scalar[0] + data_scalar[1] + data_scalar[2] + data_scalar[3];
- _mm256_storeu_si256((__m256i*)data_scalar,total_err2);
+ _mm256_storeu_si256((__m256i*)(void*)data_scalar,total_err2);
total_error_2 += data_scalar[0] + data_scalar[1] + data_scalar[2] + data_scalar[3];
- _mm256_storeu_si256((__m256i*)data_scalar,total_err3);
+ _mm256_storeu_si256((__m256i*)(void*)data_scalar,total_err3);
total_error_3 += data_scalar[0] + data_scalar[1] + data_scalar[2] + data_scalar[3];
- _mm256_storeu_si256((__m256i*)data_scalar,total_err4);
+ _mm256_storeu_si256((__m256i*)(void*)data_scalar,total_err4);
total_error_4 += data_scalar[0] + data_scalar[1] + data_scalar[2] + data_scalar[3];
- _mm256_storeu_si256((__m256i*)data_scalar,shadow_err0);
- shadow_error_0 += data_scalar[0] | data_scalar[1] | data_scalar[2] | data_scalar[3];
- _mm256_storeu_si256((__m256i*)data_scalar,shadow_err1);
- shadow_error_1 += data_scalar[0] | data_scalar[1] | data_scalar[2] | data_scalar[3];
- _mm256_storeu_si256((__m256i*)data_scalar,shadow_err2);
- shadow_error_2 += data_scalar[0] | data_scalar[1] | data_scalar[2] | data_scalar[3];
- _mm256_storeu_si256((__m256i*)data_scalar,shadow_err3);
- shadow_error_3 += data_scalar[0] | data_scalar[1] | data_scalar[2] | data_scalar[3];
- _mm256_storeu_si256((__m256i*)data_scalar,shadow_err4);
- shadow_error_4 += data_scalar[0] | data_scalar[1] | data_scalar[2] | data_scalar[3];
+ _mm256_storeu_si256((__m256i*)(void*)data_scalar,shadow_err0);
+ shadow_error_0 |= data_scalar[0] | data_scalar[1] | data_scalar[2] | data_scalar[3];
+ _mm256_storeu_si256((__m256i*)(void*)data_scalar,shadow_err1);
+ shadow_error_1 |= data_scalar[0] | data_scalar[1] | data_scalar[2] | data_scalar[3];
+ _mm256_storeu_si256((__m256i*)(void*)data_scalar,shadow_err2);
+ shadow_error_2 |= data_scalar[0] | data_scalar[1] | data_scalar[2] | data_scalar[3];
+ _mm256_storeu_si256((__m256i*)(void*)data_scalar,shadow_err3);
+ shadow_error_3 |= data_scalar[0] | data_scalar[1] | data_scalar[2] | data_scalar[3];
+ _mm256_storeu_si256((__m256i*)(void*)data_scalar,shadow_err4);
+ shadow_error_4 |= data_scalar[0] | data_scalar[1] | data_scalar[2] | data_scalar[3];
/* Take care of remaining sample */
for(i = (data_len/4)*4; i < data_len_int; i++) {
diff --git a/src/libFLAC/fixed_intrin_sse2.c b/src/libFLAC/fixed_intrin_sse2.c
index 89a9d72d..b92c13c1 100644
--- a/src/libFLAC/fixed_intrin_sse2.c
+++ b/src/libFLAC/fixed_intrin_sse2.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/fixed_intrin_sse42.c b/src/libFLAC/fixed_intrin_sse42.c
index 6be407e2..0556eaad 100644
--- a/src/libFLAC/fixed_intrin_sse42.c
+++ b/src/libFLAC/fixed_intrin_sse42.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -130,7 +130,7 @@ uint32_t FLAC__fixed_compute_best_predictor_limit_residual_intrin_sse42(const FL
tempB = _mm_xor_si128(tempA, bitmask);
tempB = _mm_sub_epi64(tempB, bitmask);
total_err0 = _mm_add_epi64(total_err0,tempB);
- shadow_err0 = _mm_xor_si128(shadow_err0,tempB);
+ shadow_err0 = _mm_or_si128(shadow_err0,tempB);
tempB = _mm_sub_epi64(tempA,prev_err0);
prev_err0 = tempA;
/* Next three intrinsics calculate tempA as abs of tempB */
@@ -138,7 +138,7 @@ uint32_t FLAC__fixed_compute_best_predictor_limit_residual_intrin_sse42(const FL
tempA = _mm_xor_si128(tempB, bitmask);
tempA = _mm_sub_epi64(tempA, bitmask);
total_err1 = _mm_add_epi64(total_err1,tempA);
- shadow_err1 = _mm_xor_si128(shadow_err1,tempA);
+ shadow_err1 = _mm_or_si128(shadow_err1,tempA);
tempA = _mm_sub_epi64(tempB,prev_err1);
prev_err1 = tempB;
/* Next three intrinsics calculate tempB as abs of tempA */
@@ -146,7 +146,7 @@ uint32_t FLAC__fixed_compute_best_predictor_limit_residual_intrin_sse42(const FL
tempB = _mm_xor_si128(tempA, bitmask);
tempB = _mm_sub_epi64(tempB, bitmask);
total_err2 = _mm_add_epi64(total_err2,tempB);
- shadow_err2 = _mm_xor_si128(shadow_err2,tempB);
+ shadow_err2 = _mm_or_si128(shadow_err2,tempB);
tempB = _mm_sub_epi64(tempA,prev_err2);
prev_err2 = tempA;
/* Next three intrinsics calculate tempA as abs of tempB */
@@ -154,7 +154,7 @@ uint32_t FLAC__fixed_compute_best_predictor_limit_residual_intrin_sse42(const FL
tempA = _mm_xor_si128(tempB, bitmask);
tempA = _mm_sub_epi64(tempA, bitmask);
total_err3 = _mm_add_epi64(total_err3,tempA);
- shadow_err3 = _mm_xor_si128(shadow_err3,tempA);
+ shadow_err3 = _mm_or_si128(shadow_err3,tempA);
tempA = _mm_sub_epi64(tempB,prev_err3);
prev_err3 = tempB;
/* Next three intrinsics calculate tempB as abs of tempA */
@@ -162,7 +162,7 @@ uint32_t FLAC__fixed_compute_best_predictor_limit_residual_intrin_sse42(const FL
tempB = _mm_xor_si128(tempA, bitmask);
tempB = _mm_sub_epi64(tempB, bitmask);
total_err4 = _mm_add_epi64(total_err4,tempB);
- shadow_err4 = _mm_xor_si128(shadow_err4,tempB);
+ shadow_err4 = _mm_or_si128(shadow_err4,tempB);
}
_mm_storeu_si128((__m128i*)data_scalar,total_err0);
total_error_0 += data_scalar[0] + data_scalar[1];
@@ -175,15 +175,15 @@ uint32_t FLAC__fixed_compute_best_predictor_limit_residual_intrin_sse42(const FL
_mm_storeu_si128((__m128i*)data_scalar,total_err4);
total_error_4 += data_scalar[0] + data_scalar[1];
_mm_storeu_si128((__m128i*)data_scalar,shadow_err0);
- shadow_error_0 += data_scalar[0] | data_scalar[1];
+ shadow_error_0 |= data_scalar[0] | data_scalar[1];
_mm_storeu_si128((__m128i*)data_scalar,shadow_err1);
- shadow_error_1 += data_scalar[0] | data_scalar[1];
+ shadow_error_1 |= data_scalar[0] | data_scalar[1];
_mm_storeu_si128((__m128i*)data_scalar,shadow_err2);
- shadow_error_2 += data_scalar[0] | data_scalar[1];
+ shadow_error_2 |= data_scalar[0] | data_scalar[1];
_mm_storeu_si128((__m128i*)data_scalar,shadow_err3);
- shadow_error_3 += data_scalar[0] | data_scalar[1];
+ shadow_error_3 |= data_scalar[0] | data_scalar[1];
_mm_storeu_si128((__m128i*)data_scalar,shadow_err4);
- shadow_error_4 += data_scalar[0] | data_scalar[1];
+ shadow_error_4 |= data_scalar[0] | data_scalar[1];
/* Take care of remaining sample */
if(data_len_int % 2 > 0) {
diff --git a/src/libFLAC/fixed_intrin_ssse3.c b/src/libFLAC/fixed_intrin_ssse3.c
index 1f0e63dc..551693bf 100644
--- a/src/libFLAC/fixed_intrin_ssse3.c
+++ b/src/libFLAC/fixed_intrin_ssse3.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/float.c b/src/libFLAC/float.c
index 1e258275..a06ad285 100644
--- a/src/libFLAC/float.c
+++ b/src/libFLAC/float.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2004-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/format.c b/src/libFLAC/format.c
index 31ffdc2f..8bbffbef 100644
--- a/src/libFLAC/format.c
+++ b/src/libFLAC/format.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -55,7 +55,7 @@ FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC git-" GIT_COMMIT_H
#else
/* PACKAGE_VERSION should come from configure */
FLAC_API const char *FLAC__VERSION_STRING = PACKAGE_VERSION;
-FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC " PACKAGE_VERSION " 20221022";
+FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC " PACKAGE_VERSION " 20230623";
#endif
FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4] = { 'f','L','a','C' };
@@ -208,7 +208,7 @@ FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[] = {
FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(uint32_t sample_rate)
{
- if(sample_rate == 0 || sample_rate > FLAC__MAX_SAMPLE_RATE) {
+ if(sample_rate > FLAC__MAX_SAMPLE_RATE) {
return false;
}
else
@@ -247,6 +247,9 @@ FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_S
FLAC__ASSERT(0 != seek_table);
+ if((FLAC__uint64)(seek_table->num_points) * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH >= (1u << FLAC__STREAM_METADATA_LENGTH_LEN))
+ return false;
+
for(i = 0; i < seek_table->num_points; i++) {
if(got_prev) {
if(
diff --git a/src/libFLAC/include/Makefile.am b/src/libFLAC/include/Makefile.am
index 007a929b..8484d128 100644
--- a/src/libFLAC/include/Makefile.am
+++ b/src/libFLAC/include/Makefile.am
@@ -1,6 +1,6 @@
# libFLAC - Free Lossless Audio Codec library
# Copyright (C) 2001-2009 Josh Coalson
-# Copyright (C) 2011-2022 Xiph.Org Foundation
+# Copyright (C) 2011-2023 Xiph.Org Foundation
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/include/private/Makefile.am b/src/libFLAC/include/private/Makefile.am
index 8e6755ea..3e63d310 100644
--- a/src/libFLAC/include/private/Makefile.am
+++ b/src/libFLAC/include/private/Makefile.am
@@ -1,6 +1,6 @@
# libFLAC - Free Lossless Audio Codec library
# Copyright (C) 2001-2009 Josh Coalson
-# Copyright (C) 2011-2022 Xiph.Org Foundation
+# Copyright (C) 2011-2023 Xiph.Org Foundation
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/include/private/all.h b/src/libFLAC/include/private/all.h
index c64f9acd..10b69495 100644
--- a/src/libFLAC/include/private/all.h
+++ b/src/libFLAC/include/private/all.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/include/private/bitmath.h b/src/libFLAC/include/private/bitmath.h
index b1dc4e86..12e062f8 100644
--- a/src/libFLAC/include/private/bitmath.h
+++ b/src/libFLAC/include/private/bitmath.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2001-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/include/private/bitreader.h b/src/libFLAC/include/private/bitreader.h
index 2943a955..c36c9266 100644
--- a/src/libFLAC/include/private/bitreader.h
+++ b/src/libFLAC/include/private/bitreader.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -88,6 +88,10 @@ FLAC__bool FLAC__bitreader_read_byte_block_aligned_no_crc(FLAC__BitReader *br, F
FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, uint32_t *val);
FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, uint32_t parameter);
FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], uint32_t nvals, uint32_t parameter);
+#ifdef FLAC__BMI2_SUPPORTED
+FLAC__bool FLAC__bitreader_read_rice_signed_block_bmi2(FLAC__BitReader *br, int vals[], uint32_t nvals, uint32_t parameter);
+#endif
+
#if 0 /* UNUSED */
FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, uint32_t parameter);
FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, uint32_t *val, uint32_t parameter);
diff --git a/src/libFLAC/include/private/bitwriter.h b/src/libFLAC/include/private/bitwriter.h
index 6029790b..39bcf254 100644
--- a/src/libFLAC/include/private/bitwriter.h
+++ b/src/libFLAC/include/private/bitwriter.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/include/private/cpu.h b/src/libFLAC/include/private/cpu.h
index 1e444c09..8843c74b 100644
--- a/src/libFLAC/include/private/cpu.h
+++ b/src/libFLAC/include/private/cpu.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2001-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -90,6 +90,7 @@
#define FLAC__AVX_SUPPORTED 1
#define FLAC__AVX2_SUPPORTED 1
#define FLAC__FMA_SUPPORTED 1
+ #define FLAC__BMI2_SUPPORTED 1
#endif
#elif defined __GNUC__ && !defined __clang__ && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9)) /* GCC 4.9+ */
#define FLAC__SSE_TARGET(x) __attribute__ ((__target__ (x)))
@@ -102,6 +103,7 @@
#define FLAC__AVX_SUPPORTED 1
#define FLAC__AVX2_SUPPORTED 1
#define FLAC__FMA_SUPPORTED 1
+ #define FLAC__BMI2_SUPPORTED 1
#endif
#elif defined _MSC_VER
#define FLAC__SSE_TARGET(x)
@@ -178,6 +180,7 @@ typedef struct {
FLAC__bool avx;
FLAC__bool avx2;
FLAC__bool fma;
+ FLAC__bool bmi2;
} FLAC__CPUInfo_x86;
typedef struct {
diff --git a/src/libFLAC/include/private/crc.h b/src/libFLAC/include/private/crc.h
index 8c8fcd4c..fe445020 100644
--- a/src/libFLAC/include/private/crc.h
+++ b/src/libFLAC/include/private/crc.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/include/private/fixed.h b/src/libFLAC/include/private/fixed.h
index 4ee1fd22..c4efecd5 100644
--- a/src/libFLAC/include/private/fixed.h
+++ b/src/libFLAC/include/private/fixed.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/include/private/float.h b/src/libFLAC/include/private/float.h
index 096db7d2..bec26345 100644
--- a/src/libFLAC/include/private/float.h
+++ b/src/libFLAC/include/private/float.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2004-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/include/private/format.h b/src/libFLAC/include/private/format.h
index d5c6aa49..7630f6fa 100644
--- a/src/libFLAC/include/private/format.h
+++ b/src/libFLAC/include/private/format.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/include/private/lpc.h b/src/libFLAC/include/private/lpc.h
index eed7b666..766f0560 100644
--- a/src/libFLAC/include/private/lpc.h
+++ b/src/libFLAC/include/private/lpc.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/include/private/macros.h b/src/libFLAC/include/private/macros.h
index ee0d997b..8204ed54 100644
--- a/src/libFLAC/include/private/macros.h
+++ b/src/libFLAC/include/private/macros.h
@@ -1,5 +1,5 @@
/* libFLAC - Free Lossless Audio Codec library
- * Copyright (C) 2012-2022 Xiph.Org Foundation
+ * Copyright (C) 2012-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/include/private/memory.h b/src/libFLAC/include/private/memory.h
index b55c9624..4221bcfd 100644
--- a/src/libFLAC/include/private/memory.h
+++ b/src/libFLAC/include/private/memory.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2001-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/include/private/metadata.h b/src/libFLAC/include/private/metadata.h
index 409b62cd..d3ceb53f 100644
--- a/src/libFLAC/include/private/metadata.h
+++ b/src/libFLAC/include/private/metadata.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/include/private/ogg_decoder_aspect.h b/src/libFLAC/include/private/ogg_decoder_aspect.h
index 2be979cc..c9236410 100644
--- a/src/libFLAC/include/private/ogg_decoder_aspect.h
+++ b/src/libFLAC/include/private/ogg_decoder_aspect.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/include/private/ogg_encoder_aspect.h b/src/libFLAC/include/private/ogg_encoder_aspect.h
index 35a1ddf5..0e9bb4bc 100644
--- a/src/libFLAC/include/private/ogg_encoder_aspect.h
+++ b/src/libFLAC/include/private/ogg_encoder_aspect.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/include/private/ogg_helper.h b/src/libFLAC/include/private/ogg_helper.h
index 3e15acca..67685787 100644
--- a/src/libFLAC/include/private/ogg_helper.h
+++ b/src/libFLAC/include/private/ogg_helper.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec
* Copyright (C) 2004-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/include/private/ogg_mapping.h b/src/libFLAC/include/private/ogg_mapping.h
index 224f7dc2..1a213a4f 100644
--- a/src/libFLAC/include/private/ogg_mapping.h
+++ b/src/libFLAC/include/private/ogg_mapping.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec
* Copyright (C) 2004-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/include/private/stream_encoder.h b/src/libFLAC/include/private/stream_encoder.h
index 1d22937e..0a1b672a 100644
--- a/src/libFLAC/include/private/stream_encoder.h
+++ b/src/libFLAC/include/private/stream_encoder.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/include/private/stream_encoder_framing.h b/src/libFLAC/include/private/stream_encoder_framing.h
index 2799c698..705965ae 100644
--- a/src/libFLAC/include/private/stream_encoder_framing.h
+++ b/src/libFLAC/include/private/stream_encoder_framing.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -36,7 +36,7 @@
#include "FLAC/format.h"
#include "bitwriter.h"
-FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw);
+FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw, FLAC__bool update_vendor_string);
FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw);
FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, uint32_t subframe_bps, uint32_t wasted_bits, FLAC__BitWriter *bw);
FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, uint32_t residual_samples, uint32_t subframe_bps, uint32_t wasted_bits, FLAC__BitWriter *bw);
diff --git a/src/libFLAC/include/private/window.h b/src/libFLAC/include/private/window.h
index 4aaaaea6..87a3fdf1 100644
--- a/src/libFLAC/include/private/window.h
+++ b/src/libFLAC/include/private/window.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2006-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/include/protected/Makefile.am b/src/libFLAC/include/protected/Makefile.am
index 30d03665..97e85a84 100644
--- a/src/libFLAC/include/protected/Makefile.am
+++ b/src/libFLAC/include/protected/Makefile.am
@@ -1,6 +1,6 @@
# libFLAC - Free Lossless Audio Codec library
# Copyright (C) 2001-2009 Josh Coalson
-# Copyright (C) 2011-2022 Xiph.Org Foundation
+# Copyright (C) 2011-2023 Xiph.Org Foundation
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/include/protected/all.h b/src/libFLAC/include/protected/all.h
index ad302308..9f6de97a 100644
--- a/src/libFLAC/include/protected/all.h
+++ b/src/libFLAC/include/protected/all.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2001-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/include/protected/stream_decoder.h b/src/libFLAC/include/protected/stream_decoder.h
index f1c5d0eb..4a9c7686 100644
--- a/src/libFLAC/include/protected/stream_decoder.h
+++ b/src/libFLAC/include/protected/stream_decoder.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/include/protected/stream_encoder.h b/src/libFLAC/include/protected/stream_encoder.h
index 3e045583..863e43b3 100644
--- a/src/libFLAC/include/protected/stream_encoder.h
+++ b/src/libFLAC/include/protected/stream_encoder.h
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2001-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/lpc.c b/src/libFLAC/lpc.c
index 7c16cdf6..bcb8673c 100644
--- a/src/libFLAC/lpc.c
+++ b/src/libFLAC/lpc.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/lpc_intrin_avx2.c b/src/libFLAC/lpc_intrin_avx2.c
index 48bd7a85..7f1c03ed 100644
--- a/src/libFLAC/lpc_intrin_avx2.c
+++ b/src/libFLAC/lpc_intrin_avx2.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/lpc_intrin_fma.c b/src/libFLAC/lpc_intrin_fma.c
index 396ff302..c0740a88 100644
--- a/src/libFLAC/lpc_intrin_fma.c
+++ b/src/libFLAC/lpc_intrin_fma.c
@@ -1,5 +1,5 @@
/* libFLAC - Free Lossless Audio Codec library
- * Copyright (C) 2022 Xiph.Org Foundation
+ * Copyright (C) 2022-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/lpc_intrin_neon.c b/src/libFLAC/lpc_intrin_neon.c
index 0ba45016..b9945d58 100644
--- a/src/libFLAC/lpc_intrin_neon.c
+++ b/src/libFLAC/lpc_intrin_neon.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/lpc_intrin_sse2.c b/src/libFLAC/lpc_intrin_sse2.c
index f1ad018d..d16a085f 100644
--- a/src/libFLAC/lpc_intrin_sse2.c
+++ b/src/libFLAC/lpc_intrin_sse2.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/lpc_intrin_sse41.c b/src/libFLAC/lpc_intrin_sse41.c
index 136f71ca..756c5dd8 100644
--- a/src/libFLAC/lpc_intrin_sse41.c
+++ b/src/libFLAC/lpc_intrin_sse41.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/memory.c b/src/libFLAC/memory.c
index 2dad6e7d..ad5371ee 100644
--- a/src/libFLAC/memory.c
+++ b/src/libFLAC/memory.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2001-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/metadata_iterators.c b/src/libFLAC/metadata_iterators.c
index ad8be8e1..20e926be 100644
--- a/src/libFLAC/metadata_iterators.c
+++ b/src/libFLAC/metadata_iterators.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2001-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -1142,6 +1142,12 @@ static FLAC__bool chain_merge_adjacent_padding_(FLAC__Metadata_Chain *chain, FLA
static FLAC__off_t chain_prepare_for_write_(FLAC__Metadata_Chain *chain, FLAC__bool use_padding)
{
FLAC__off_t current_length = chain_calculate_length_(chain);
+ FLAC__Metadata_Node * i;
+
+ /* Check all is_last settings on the blocks */
+ for(i = chain->head; i->next != NULL; i = i->next)
+ i->data->is_last = 0;
+ chain->tail->data->is_last = 1;
if(use_padding) {
/* if the metadata shrank and the last block is padding, we just extend the last padding block */
@@ -2337,7 +2343,7 @@ FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_vorbis_comment_entr
if(max_length < entry->length) {
entry->length = 0;
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA;
- } else max_length -= entry->length;
+ }
if(0 != entry->entry)
free(entry->entry);
@@ -2407,7 +2413,7 @@ FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_vorbis_comment_cb_(
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR;
}
- return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK;
+ return status;
}
FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_cuesheet_track_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_CueSheet_Track *track)
@@ -2512,7 +2518,7 @@ FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_cuesheet_cb_(FLAC__
block->num_tracks = unpack_uint32_(buffer, len);
if(block->num_tracks == 0) {
- block->tracks = 0;
+ return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA;
}
else if(0 == (block->tracks = calloc(block->num_tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track))))
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR;
diff --git a/src/libFLAC/metadata_object.c b/src/libFLAC/metadata_object.c
index b013cfa0..73e76076 100644
--- a/src/libFLAC/metadata_object.c
+++ b/src/libFLAC/metadata_object.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2001-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -39,8 +39,10 @@
#include "private/metadata.h"
#include "private/memory.h"
+#include "private/stream_encoder_framing.h"
#include "FLAC/assert.h"
+#include "FLAC/stream_decoder.h"
#include "share/alloc.h"
#include "share/compat.h"
@@ -929,6 +931,9 @@ FLAC_API FLAC__bool FLAC__metadata_object_seektable_resize_points(FLAC__StreamMe
FLAC__ASSERT(object != NULL);
FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE);
+ if((FLAC__uint64)(new_num_points) * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH >= (1u << FLAC__STREAM_METADATA_LENGTH_LEN))
+ return false;
+
if (object->data.seek_table.points == 0) {
FLAC__ASSERT(object->data.seek_table.num_points == 0);
if (new_num_points == 0)
@@ -1852,3 +1857,162 @@ FLAC_API FLAC__bool FLAC__metadata_object_picture_is_legal(const FLAC__StreamMet
return FLAC__format_picture_is_legal(&object->data.picture, violation);
}
+
+FLAC_API FLAC__byte * FLAC__metadata_object_get_raw(const FLAC__StreamMetadata *object)
+{
+ FLAC__BitWriter *bw;
+ const FLAC__byte * buffer;
+ FLAC__byte * output;
+ size_t bytes;
+
+ FLAC__ASSERT(object != NULL);
+
+ if((bw = FLAC__bitwriter_new()) == NULL)
+ return 0;
+ if(!FLAC__bitwriter_init(bw)) {
+ FLAC__bitwriter_delete(bw);
+ return 0;
+ }
+ if(!FLAC__add_metadata_block(object, bw, false)) {
+ FLAC__bitwriter_delete(bw);
+ return 0;
+ }
+
+ if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes)) {
+ FLAC__bitwriter_delete(bw);
+ return 0;
+ }
+
+ /* Extra check whether length of bitwriter agrees with length of metadata block */
+ if(bytes != (object->length+FLAC__STREAM_METADATA_HEADER_LENGTH)) {
+ FLAC__bitwriter_delete(bw);
+ return 0;
+ }
+
+ output = safe_malloc_(bytes);
+ if(output == 0) {
+ FLAC__bitwriter_delete(bw);
+ return 0;
+ }
+
+ memcpy(output,buffer,bytes);
+ FLAC__bitwriter_delete(bw);
+ return output;
+}
+
+/* The following callbacks are for FLAC__metadata_object_set_raw */
+
+static FLAC__StreamDecoderReadStatus read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte *buffer, size_t *bytes, void *client_data);
+static FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
+static void metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
+static void error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
+
+typedef struct {
+ FLAC__StreamMetadata *object;
+ FLAC__bool got_error;
+ FLAC__byte *buffer;
+ FLAC__int32 length;
+ FLAC__int32 tell;
+} set_raw_client_data;
+
+FLAC_API FLAC__StreamMetadata * FLAC__metadata_object_set_raw(FLAC__byte *buffer, FLAC__uint32 length)
+{
+ set_raw_client_data cd;
+ FLAC__StreamDecoder * decoder;
+
+ cd.buffer = buffer;
+ cd.length = length;
+ cd.got_error = false;
+ cd.object = 0;
+ cd.tell = -4;
+
+ decoder = FLAC__stream_decoder_new();
+
+ if(0 == decoder)
+ return 0;
+
+ FLAC__stream_decoder_set_md5_checking(decoder, false);
+ FLAC__stream_decoder_set_metadata_respond_all(decoder);
+
+ if(FLAC__stream_decoder_init_stream(decoder, read_callback_, NULL, NULL, NULL, NULL, write_callback_, metadata_callback_, error_callback_, &cd) != FLAC__STREAM_DECODER_INIT_STATUS_OK || cd.got_error) {
+ (void)FLAC__stream_decoder_finish(decoder);
+ FLAC__stream_decoder_delete(decoder);
+ return 0;
+ }
+
+ if((!FLAC__stream_decoder_process_until_end_of_metadata(decoder) && FLAC__stream_decoder_get_state(decoder) != FLAC__STREAM_DECODER_END_OF_STREAM) || cd.got_error) {
+ (void)FLAC__stream_decoder_finish(decoder);
+ FLAC__stream_decoder_delete(decoder);
+ if(0 != cd.object)
+ FLAC__metadata_object_delete(cd.object);
+ return 0;
+ }
+
+ (void)FLAC__stream_decoder_finish(decoder);
+ FLAC__stream_decoder_delete(decoder);
+
+ return cd.object;
+
+}
+
+FLAC__StreamDecoderReadStatus read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte *buffer, size_t *bytes, void *client_data)
+{
+ set_raw_client_data *cd = (set_raw_client_data *)client_data;
+ (void)decoder;
+
+ if(cd->tell == -4) {
+ if(*bytes < 4)
+ return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
+ buffer[0] = 'f';
+ buffer[1] = 'L';
+ buffer[2] = 'a';
+ buffer[3] = 'C';
+ *bytes = 4;
+ cd->tell = 0;
+ return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
+ }
+ else if(cd->tell < 0)
+ return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
+ else if(cd->tell == cd->length) {
+ *bytes = 0;
+ return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
+ }
+ else {
+ if((FLAC__int32)(*bytes) > (cd->length - cd->tell))
+ *bytes = cd->length - cd->tell;
+ memcpy(buffer, cd->buffer+cd->tell, *bytes);
+ cd->tell += *bytes;
+ return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
+ }
+}
+
+FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
+{
+ (void)decoder, (void)frame, (void)buffer, (void)client_data;
+
+ return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
+}
+
+void metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
+{
+ set_raw_client_data *cd = (set_raw_client_data *)client_data;
+ (void)decoder;
+
+ /*
+ * we assume we only get here when the one metadata block we were
+ * looking for was passed to us
+ */
+ if(!cd->got_error && 0 == cd->object) {
+ if(0 == (cd->object = FLAC__metadata_object_clone(metadata)))
+ cd->got_error = true;
+ }
+}
+
+void error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
+{
+ set_raw_client_data *cd = (set_raw_client_data *)client_data;
+ (void)decoder;
+
+ if(status != FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC)
+ cd->got_error = true;
+}
diff --git a/src/libFLAC/ogg_decoder_aspect.c b/src/libFLAC/ogg_decoder_aspect.c
index e331db30..58a29346 100644
--- a/src/libFLAC/ogg_decoder_aspect.c
+++ b/src/libFLAC/ogg_decoder_aspect.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/ogg_encoder_aspect.c b/src/libFLAC/ogg_encoder_aspect.c
index ae055c84..a88713b1 100644
--- a/src/libFLAC/ogg_encoder_aspect.c
+++ b/src/libFLAC/ogg_encoder_aspect.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/ogg_helper.c b/src/libFLAC/ogg_helper.c
index acd945ac..a4be34d2 100644
--- a/src/libFLAC/ogg_helper.c
+++ b/src/libFLAC/ogg_helper.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec
* Copyright (C) 2004-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/ogg_mapping.c b/src/libFLAC/ogg_mapping.c
index 1bd8c3cb..756c7165 100644
--- a/src/libFLAC/ogg_mapping.c
+++ b/src/libFLAC/ogg_mapping.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec
* Copyright (C) 2004-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/stream_decoder.c b/src/libFLAC/stream_decoder.c
index fcd55881..98825839 100644
--- a/src/libFLAC/stream_decoder.c
+++ b/src/libFLAC/stream_decoder.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -45,6 +45,7 @@
#include "protected/stream_decoder.h"
#include "private/bitreader.h"
#include "private/bitmath.h"
+#include "private/cpu.h"
#include "private/crc.h"
#include "private/fixed.h"
#include "private/format.h"
@@ -147,6 +148,7 @@ typedef struct FLAC__StreamDecoderPrivate {
size_t metadata_filter_ids_count, metadata_filter_ids_capacity; /* units for both are IDs, not bytes */
FLAC__Frame frame;
FLAC__bool cached; /* true if there is a byte in lookahead */
+ FLAC__CPUInfo cpuinfo;
FLAC__byte header_warmup[2]; /* contains the sync code and reserved bits */
FLAC__byte lookahead; /* temp storage when we need to look ahead one byte in the stream */
/* unaligned (original) pointers to allocated data */
@@ -164,6 +166,7 @@ typedef struct FLAC__StreamDecoderPrivate {
FLAC__uint64 target_sample;
uint32_t unparseable_frame_count; /* used to tell whether we're decoding a future version of FLAC or just got a bad sync */
FLAC__bool got_a_frame; /* hack needed in Ogg FLAC seek routine to check when process_single() actually writes a frame */
+ FLAC__bool (*local_bitreader_read_rice_signed_block)(FLAC__BitReader *br, int vals[], uint32_t nvals, uint32_t parameter);
} FLAC__StreamDecoderPrivate;
/***********************************************************************
@@ -369,6 +372,15 @@ static FLAC__StreamDecoderInitStatus init_stream_internal_(
return decoder->protected_->initstate = FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE;
#endif
+ FLAC__cpu_info(&decoder->private_->cpuinfo);
+ decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block;
+
+#ifdef FLAC__BMI2_SUPPORTED
+ if (decoder->private_->cpuinfo.x86.bmi2) {
+ decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block_bmi2;
+ }
+#endif
+
/* from here on, errors are fatal */
if(!FLAC__bitreader_init(decoder->private_->input, read_callback_, decoder)) {
@@ -1403,12 +1415,14 @@ FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder)
/* just in case we already have a seek table, and reading the next one fails: */
decoder->private_->has_seek_table = false;
- if(!read_metadata_seektable_(decoder, is_last, length))
- return false;
+ if(length > 0) {
+ if(!read_metadata_seektable_(decoder, is_last, length))
+ return false;
- decoder->private_->has_seek_table = true;
- if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_SEEKTABLE] && decoder->private_->metadata_callback)
- decoder->private_->metadata_callback(decoder, &decoder->private_->seek_table, decoder->private_->client_data);
+ decoder->private_->has_seek_table = true;
+ if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_SEEKTABLE] && decoder->private_->metadata_callback)
+ decoder->private_->metadata_callback(decoder, &decoder->private_->seek_table, decoder->private_->client_data);
+ }
}
else {
FLAC__bool skip_it = !decoder->private_->metadata_filter[type];
@@ -1689,24 +1703,20 @@ FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__Stre
FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
if (!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->vendor_string.length))
return false; /* read_callback_ sets the state for us */
- if (obj->vendor_string.length > 0) {
- if (length < obj->vendor_string.length) {
- obj->vendor_string.length = 0;
- obj->vendor_string.entry = 0;
- goto skip;
- }
- else
- length -= obj->vendor_string.length;
- if (0 == (obj->vendor_string.entry = safe_malloc_add_2op_(obj->vendor_string.length, /*+*/1))) {
- decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
- return false;
- }
- if (!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->vendor_string.entry, obj->vendor_string.length))
- return false; /* read_callback_ sets the state for us */
- obj->vendor_string.entry[obj->vendor_string.length] = '\0';
+ if (length < obj->vendor_string.length) {
+ obj->vendor_string.length = 0;
+ obj->vendor_string.entry = 0;
+ goto skip;
}
else
- obj->vendor_string.entry = 0;
+ length -= obj->vendor_string.length;
+ if (0 == (obj->vendor_string.entry = safe_malloc_add_2op_(obj->vendor_string.length, /*+*/1))) {
+ decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
+ return false;
+ }
+ if (!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->vendor_string.entry, obj->vendor_string.length))
+ return false; /* read_callback_ sets the state for us */
+ obj->vendor_string.entry[obj->vendor_string.length] = '\0';
/* read num comments */
FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN == 32);
@@ -1741,31 +1751,27 @@ FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__Stre
obj->num_comments = i;
return false; /* read_callback_ sets the state for us */
}
- if (obj->comments[i].length > 0) {
- if (length < obj->comments[i].length) {
- obj->num_comments = i;
- FLAC__bitreader_limit_invalidate(decoder->private_->input);
- return false;
- }
- else
- length -= obj->comments[i].length;
- if (0 == (obj->comments[i].entry = safe_malloc_add_2op_(obj->comments[i].length, /*+*/1))) {
- decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
- obj->num_comments = i;
- return false;
- }
- memset (obj->comments[i].entry, 0, obj->comments[i].length) ;
- if (!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->comments[i].entry, obj->comments[i].length)) {
- /* Current i-th entry is bad, so we delete it. */
- free (obj->comments[i].entry) ;
- obj->comments[i].entry = NULL ;
- obj->num_comments = i;
- goto skip;
- }
- obj->comments[i].entry[obj->comments[i].length] = '\0';
+ if (length < obj->comments[i].length) {
+ obj->num_comments = i;
+ FLAC__bitreader_limit_invalidate(decoder->private_->input);
+ return false;
}
else
- obj->comments[i].entry = 0;
+ length -= obj->comments[i].length;
+ if (0 == (obj->comments[i].entry = safe_malloc_add_2op_(obj->comments[i].length, /*+*/1))) {
+ decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
+ obj->num_comments = i;
+ return false;
+ }
+ memset (obj->comments[i].entry, 0, obj->comments[i].length) ;
+ if (!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->comments[i].entry, obj->comments[i].length)) {
+ /* Current i-th entry is bad, so we delete it. */
+ free (obj->comments[i].entry) ;
+ obj->comments[i].entry = NULL ;
+ obj->num_comments = i;
+ goto skip;
+ }
+ obj->comments[i].entry[obj->comments[i].length] = '\0';
}
}
}
@@ -1867,6 +1873,10 @@ FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMet
}
}
}
+ else { /* obj->num_tracks == 0 */
+ FLAC__bitreader_limit_invalidate(decoder->private_->input);
+ return false;
+ }
return true;
}
@@ -2087,6 +2097,8 @@ FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FL
else
return false;
}
+ if(decoder->protected_->state != FLAC__STREAM_DECODER_READ_FRAME)
+ break;
}
if(decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM)
@@ -2149,10 +2161,20 @@ FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FL
decoder->private_->last_frame.header.channels == decoder->private_->frame.header.channels &&
decoder->private_->last_frame.header.bits_per_sample == decoder->private_->frame.header.bits_per_sample &&
decoder->private_->last_frame.header.blocksize >= 16) {
-
FLAC__Frame empty_frame;
+ FLAC__int32 * empty_buffer[FLAC__MAX_CHANNELS] = {NULL};
empty_frame.header = decoder->private_->last_frame.header;
empty_frame.footer.crc = 0;
+ for(i = 0; i < empty_frame.header.channels; i++) {
+ empty_buffer[i] = safe_calloc_(empty_frame.header.blocksize, sizeof(FLAC__int32));
+ if(empty_buffer[i] == NULL) {
+ for(i = 0; i < empty_frame.header.channels; i++)
+ if(empty_buffer[i] != NULL)
+ free(empty_buffer[i]);
+ decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
+ return false;
+ }
+ }
/* No repairs larger than 5 seconds or 50 frames are made, to not
* unexpectedly create enormous files when one of the headers was
* corrupt after all */
@@ -2170,21 +2192,24 @@ FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FL
FLAC__ASSERT(empty_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
decoder->private_->samples_decoded = empty_frame.header.number.sample_number + empty_frame.header.blocksize;
- if(!allocate_output_(decoder, empty_frame.header.blocksize, empty_frame.header.channels, empty_frame.header.bits_per_sample))
- return false;
-
for(channel = 0; channel < empty_frame.header.channels; channel++) {
empty_frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_CONSTANT;
empty_frame.subframes[channel].data.constant.value = 0;
empty_frame.subframes[channel].wasted_bits = 0;
- memset(decoder->private_->output[channel], 0, sizeof(FLAC__int32) * empty_frame.header.blocksize);
}
- if(write_audio_frame_to_client_(decoder, &empty_frame, (const FLAC__int32 * const *)decoder->private_->output) != FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE) {
+ if(write_audio_frame_to_client_(decoder, &empty_frame, (const FLAC__int32 * const *)empty_buffer) != FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE) {
decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
+ for(i = 0; i < empty_frame.header.channels; i++)
+ if(empty_buffer[i] != NULL)
+ free(empty_buffer[i]);
return false;
}
}
+ for(i = 0; i < empty_frame.header.channels; i++)
+ if(empty_buffer[i] != NULL)
+ free(empty_buffer[i]);
+
}
}
}
@@ -2496,6 +2521,14 @@ FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder)
x = (x << 8) | _x;
}
decoder->private_->frame.header.blocksize = x+1;
+ if(decoder->private_->frame.header.blocksize > 65535) { /* invalid blocksize (65536) specified */
+ decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
+ decoder->private_->cached = true;
+ send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
+ decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
+ return true;
+ }
+
}
if(sample_rate_hint) {
@@ -2940,7 +2973,7 @@ FLAC__bool read_residual_partitioned_rice_(FLAC__StreamDecoder *decoder, uint32_
if(rice_parameter < pesc) {
partitioned_rice_contents->raw_bits[partition] = 0;
u = (partition == 0) ? partition_samples - predictor_order : partition_samples;
- if(!FLAC__bitreader_read_rice_signed_block(decoder->private_->input, residual + sample, u, rice_parameter)){
+ if(!decoder->private_->local_bitreader_read_rice_signed_block(decoder->private_->input, residual + sample, u, rice_parameter)){
if(decoder->protected_->state == FLAC__STREAM_DECODER_READ_FRAME) {
/* no error was set, read_callback_ didn't set it, so
* invalid rice symbol was found */
@@ -3198,8 +3231,12 @@ FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder
if(delta > 0) {
uint32_t channel;
const FLAC__int32 *newbuffer[FLAC__MAX_CHANNELS];
- for(channel = 0; channel < frame->header.channels; channel++)
+ for(channel = 0; channel < frame->header.channels; channel++) {
newbuffer[channel] = buffer[channel] + delta;
+ decoder->private_->last_frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_VERBATIM;
+ decoder->private_->last_frame.subframes[channel].data.verbatim.data_type = FLAC__VERBATIM_SUBFRAME_DATA_TYPE_INT32;
+ decoder->private_->last_frame.subframes[channel].data.verbatim.data.int32 = newbuffer[channel];
+ }
decoder->private_->last_frame.header.blocksize -= delta;
decoder->private_->last_frame.header.number.sample_number += (FLAC__uint64)delta;
/* write the relevant samples */
diff --git a/src/libFLAC/stream_encoder.c b/src/libFLAC/stream_encoder.c
index 189b1203..c1c03e49 100644
--- a/src/libFLAC/stream_encoder.c
+++ b/src/libFLAC/stream_encoder.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -1064,7 +1064,6 @@ static FLAC__StreamEncoderInitStatus init_stream_internal_(
# ifdef FLAC__SSE4_2_SUPPORTED
if (encoder->private_->cpuinfo.x86.sse42) {
encoder->private_->local_fixed_compute_best_predictor_limit_residual = FLAC__fixed_compute_best_predictor_limit_residual_intrin_sse42;
-
}
# endif
# ifdef FLAC__AVX2_SUPPORTED
@@ -1209,7 +1208,7 @@ static FLAC__StreamEncoderInitStatus init_stream_internal_(
memset(encoder->private_->streaminfo.data.stream_info.md5sum, 0, 16); /* we don't know this yet; have to fill it in later */
if(encoder->protected_->do_md5)
FLAC__MD5Init(&encoder->private_->md5context);
- if(!FLAC__add_metadata_block(&encoder->private_->streaminfo, encoder->private_->frame)) {
+ if(!FLAC__add_metadata_block(&encoder->private_->streaminfo, encoder->private_->frame, true)) {
encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
}
@@ -1245,7 +1244,7 @@ static FLAC__StreamEncoderInitStatus init_stream_internal_(
vorbis_comment.data.vorbis_comment.vendor_string.entry = 0;
vorbis_comment.data.vorbis_comment.num_comments = 0;
vorbis_comment.data.vorbis_comment.comments = 0;
- if(!FLAC__add_metadata_block(&vorbis_comment, encoder->private_->frame)) {
+ if(!FLAC__add_metadata_block(&vorbis_comment, encoder->private_->frame, true)) {
encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
}
@@ -1260,7 +1259,7 @@ static FLAC__StreamEncoderInitStatus init_stream_internal_(
*/
for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
encoder->protected_->metadata[i]->is_last = (i == encoder->protected_->num_metadata_blocks - 1);
- if(!FLAC__add_metadata_block(encoder->protected_->metadata[i], encoder->private_->frame)) {
+ if(!FLAC__add_metadata_block(encoder->protected_->metadata[i], encoder->private_->frame, true)) {
encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
}
@@ -2249,7 +2248,7 @@ FLAC_API FLAC__bool FLAC__stream_encoder_get_limit_min_bitrate(const FLAC__Strea
FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], uint32_t samples)
{
uint32_t i, j = 0, k = 0, channel;
- const uint32_t channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize, bps = encoder->protected_->bits_per_sample;
+ const uint32_t channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
const FLAC__int32 sample_max = INT32_MAX >> (32 - encoder->protected_->bits_per_sample);
const FLAC__int32 sample_min = INT32_MIN >> (32 - encoder->protected_->bits_per_sample);
@@ -2278,24 +2277,7 @@ FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, c
}
memcpy(&encoder->private_->integer_signal[channel][encoder->private_->current_sample_number], &buffer[channel][j], sizeof(buffer[channel][0]) * n);
}
-
- if(encoder->protected_->do_mid_side_stereo) {
- FLAC__ASSERT(channels == 2);
- /* "i <= blocksize" to overread 1 sample; see comment in OVERREAD_ decl */
- if(bps < 32)
- for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
- encoder->private_->integer_signal_mid_side[1][i] = buffer[0][j] - buffer[1][j];
- encoder->private_->integer_signal_mid_side[0][i] = (buffer[0][j] + buffer[1][j]) >> 1; /* NOTE: not the same as 'mid = (buffer[0][j] + buffer[1][j]) / 2' ! */
- }
- else
- for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
- encoder->private_->integer_signal_33bit_side[i] = (FLAC__int64)buffer[0][j] - (FLAC__int64)buffer[1][j];
- encoder->private_->integer_signal_mid_side[0][i] = ((FLAC__int64)buffer[0][j] + (FLAC__int64)buffer[1][j]) >> 1; /* NOTE: not the same as 'mid = (buffer[0][j] + buffer[1][j]) / 2' ! */
- }
- }
- else
- j += n;
-
+ j += n;
encoder->private_->current_sample_number += n;
/* we only process if we have a full block + 1 extra sample; final block is always handled by FLAC__stream_encoder_finish() */
@@ -2307,13 +2289,6 @@ FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, c
/* move unprocessed overread samples to beginnings of arrays */
for(channel = 0; channel < channels; channel++)
encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
- if(encoder->protected_->do_mid_side_stereo) {
- encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
- if(bps < 32)
- encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
- else
- encoder->private_->integer_signal_33bit_side[0] = encoder->private_->integer_signal_33bit_side[blocksize];
- }
encoder->private_->current_sample_number = 1;
}
} while(j < samples);
@@ -2324,7 +2299,7 @@ FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, c
FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], uint32_t samples)
{
uint32_t i, j, k, channel;
- const uint32_t channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize, bps = encoder->protected_->bits_per_sample;
+ const uint32_t channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
const FLAC__int32 sample_max = INT32_MAX >> (32 - encoder->protected_->bits_per_sample);
const FLAC__int32 sample_min = INT32_MIN >> (32 - encoder->protected_->bits_per_sample);
@@ -2336,87 +2311,33 @@ FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder
return false;
j = k = 0;
- /*
- * we have several flavors of the same basic loop, optimized for
- * different conditions:
- */
- if(encoder->protected_->do_mid_side_stereo && channels == 2) {
- /*
- * stereo coding: unroll channel loop
- */
- do {
- if(encoder->protected_->verify)
- append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, flac_min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
+ do {
+ if(encoder->protected_->verify)
+ append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, flac_min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
/* "i <= blocksize" to overread 1 sample; see comment in OVERREAD_ decl */
- for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
- if(buffer[k] < sample_min || buffer[k] > sample_max ||
- buffer[k+1] < sample_min || buffer[k+1] > sample_max){
+ for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
+ for(channel = 0; channel < channels; channel++){
+ if(buffer[k] < sample_min || buffer[k] > sample_max){
encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
return false;
}
- encoder->private_->integer_signal[0][i] = buffer[k++];
- encoder->private_->integer_signal[1][i] = buffer[k++];
- if(bps < 32){
- encoder->private_->integer_signal_mid_side[1][i] = encoder->private_->integer_signal[0][i] - encoder->private_->integer_signal[1][i];
- encoder->private_->integer_signal_mid_side[0][i] = (encoder->private_->integer_signal[0][i] + encoder->private_->integer_signal[1][i]) >> 1;
- }
- else {
- encoder->private_->integer_signal_33bit_side[i] = (FLAC__int64)encoder->private_->integer_signal[0][i] - (FLAC__int64)encoder->private_->integer_signal[1][i];
- encoder->private_->integer_signal_mid_side[0][i] = ((FLAC__int64)encoder->private_->integer_signal[0][i] + (FLAC__int64)encoder->private_->integer_signal[1][i]) >> 1;
- }
- }
- encoder->private_->current_sample_number = i;
- /* we only process if we have a full block + 1 extra sample; final block is always handled by FLAC__stream_encoder_finish() */
- if(i > blocksize) {
- if(!process_frame_(encoder, /*is_last_block=*/false))
- return false;
- /* move unprocessed overread samples to beginnings of arrays */
- FLAC__ASSERT(i == blocksize+OVERREAD_);
- FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
- encoder->private_->integer_signal[0][0] = encoder->private_->integer_signal[0][blocksize];
- encoder->private_->integer_signal[1][0] = encoder->private_->integer_signal[1][blocksize];
- encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
- if(bps < 32)
- encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
- else
- encoder->private_->integer_signal_33bit_side[0] = encoder->private_->integer_signal_33bit_side[blocksize];
- encoder->private_->current_sample_number = 1;
+ encoder->private_->integer_signal[channel][i] = buffer[k++];
}
- } while(j < samples);
- }
- else {
- /*
- * independent channel coding: buffer each channel in inner loop
- */
- do {
- if(encoder->protected_->verify)
- append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, flac_min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
-
- /* "i <= blocksize" to overread 1 sample; see comment in OVERREAD_ decl */
- for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
- for(channel = 0; channel < channels; channel++){
- if(buffer[k] < sample_min || buffer[k] > sample_max){
- encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
- return false;
- }
- encoder->private_->integer_signal[channel][i] = buffer[k++];
- }
- }
- encoder->private_->current_sample_number = i;
- /* we only process if we have a full block + 1 extra sample; final block is always handled by FLAC__stream_encoder_finish() */
- if(i > blocksize) {
- if(!process_frame_(encoder, /*is_last_block=*/false))
- return false;
- /* move unprocessed overread samples to beginnings of arrays */
- FLAC__ASSERT(i == blocksize+OVERREAD_);
- FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
- for(channel = 0; channel < channels; channel++)
- encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
- encoder->private_->current_sample_number = 1;
- }
- } while(j < samples);
- }
+ }
+ encoder->private_->current_sample_number = i;
+ /* we only process if we have a full block + 1 extra sample; final block is always handled by FLAC__stream_encoder_finish() */
+ if(i > blocksize) {
+ if(!process_frame_(encoder, /*is_last_block=*/false))
+ return false;
+ /* move unprocessed overread samples to beginnings of arrays */
+ FLAC__ASSERT(i == blocksize+OVERREAD_);
+ FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
+ for(channel = 0; channel < channels; channel++)
+ encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
+ encoder->private_->current_sample_number = 1;
+ }
+ } while(j < samples);
return true;
}
@@ -3281,6 +3202,25 @@ FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder)
FLAC__ASSERT(do_independent || do_mid_side);
/*
+ * Prepare mid-side signals if applicable
+ */
+ if(do_mid_side) {
+ uint32_t i;
+ FLAC__ASSERT(encoder->protected_->channels == 2);
+ if(encoder->protected_->bits_per_sample < 32)
+ for(i = 0; i < encoder->protected_->blocksize; i++) {
+ encoder->private_->integer_signal_mid_side[1][i] = encoder->private_->integer_signal[0][i] - encoder->private_->integer_signal[1][i];
+ encoder->private_->integer_signal_mid_side[0][i] = (encoder->private_->integer_signal[0][i] + encoder->private_->integer_signal[1][i]) >> 1; /* NOTE: not the same as 'mid = (signal[0][j] + signal[1][j]) / 2' ! */
+ }
+ else
+ for(i = 0; i <= encoder->protected_->blocksize; i++) {
+ encoder->private_->integer_signal_33bit_side[i] = (FLAC__int64)encoder->private_->integer_signal[0][i] - (FLAC__int64)encoder->private_->integer_signal[1][i];
+ encoder->private_->integer_signal_mid_side[0][i] = ((FLAC__int64)encoder->private_->integer_signal[0][i] + (FLAC__int64)encoder->private_->integer_signal[1][i]) >> 1; /* NOTE: not the same as 'mid = (signal[0][j] + signal[1][j]) / 2' ! */
+ }
+ }
+
+
+ /*
* Check for wasted bits; set effective bps for each subframe
*/
if(do_independent) {
diff --git a/src/libFLAC/stream_encoder_framing.c b/src/libFLAC/stream_encoder_framing.c
index 0a7095ab..0e07a317 100644
--- a/src/libFLAC/stream_encoder_framing.c
+++ b/src/libFLAC/stream_encoder_framing.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -44,7 +44,7 @@
static FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method);
static FLAC__bool add_residual_partitioned_rice_(FLAC__BitWriter *bw, const FLAC__int32 residual[], const uint32_t residual_samples, const uint32_t predictor_order, const uint32_t rice_parameters[], const uint32_t raw_bits[], const uint32_t partition_order, const FLAC__bool is_extended);
-FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw)
+FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw, FLAC__bool update_vendor_string)
{
uint32_t i, j, metadata_length;
const uint32_t vendor_string_length = (uint32_t)strlen(FLAC__VENDOR_STRING);
@@ -62,7 +62,7 @@ FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__
* First, for VORBIS_COMMENTs, adjust the length to reflect our vendor string
*/
metadata_length = metadata->length;
- if(metadata->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
+ if(metadata->type == FLAC__METADATA_TYPE_VORBIS_COMMENT && update_vendor_string) {
FLAC__ASSERT(metadata->data.vorbis_comment.vendor_string.length == 0 || 0 != metadata->data.vorbis_comment.vendor_string.entry);
metadata_length -= metadata->data.vorbis_comment.vendor_string.length;
metadata_length += vendor_string_length;
@@ -130,10 +130,18 @@ FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__
}
break;
case FLAC__METADATA_TYPE_VORBIS_COMMENT:
- if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, vendor_string_length))
- return false;
- if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)FLAC__VENDOR_STRING, vendor_string_length))
- return false;
+ if(update_vendor_string) {
+ if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, vendor_string_length))
+ return false;
+ if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)FLAC__VENDOR_STRING, vendor_string_length))
+ return false;
+ }
+ else {
+ if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.vendor_string.length))
+ return false;
+ if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.vorbis_comment.vendor_string.entry, metadata->data.vorbis_comment.vendor_string.length))
+ return false;
+ }
if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.num_comments))
return false;
for(i = 0; i < metadata->data.vorbis_comment.num_comments; i++) {
diff --git a/src/libFLAC/stream_encoder_intrin_avx2.c b/src/libFLAC/stream_encoder_intrin_avx2.c
index 665f8036..b37efb38 100644
--- a/src/libFLAC/stream_encoder_intrin_avx2.c
+++ b/src/libFLAC/stream_encoder_intrin_avx2.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/stream_encoder_intrin_sse2.c b/src/libFLAC/stream_encoder_intrin_sse2.c
index fdab55b8..dd25fa65 100644
--- a/src/libFLAC/stream_encoder_intrin_sse2.c
+++ b/src/libFLAC/stream_encoder_intrin_sse2.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/stream_encoder_intrin_ssse3.c b/src/libFLAC/stream_encoder_intrin_ssse3.c
index 6f217521..241f723a 100644
--- a/src/libFLAC/stream_encoder_intrin_ssse3.c
+++ b/src/libFLAC/stream_encoder_intrin_ssse3.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/libFLAC/version.rc b/src/libFLAC/version.rc
new file mode 100644
index 00000000..019da1dd
--- /dev/null
+++ b/src/libFLAC/version.rc
@@ -0,0 +1,40 @@
+#include <winver.h>
+#include "config.h"
+#include "FLAC/export.h"
+
+#if (defined GIT_COMMIT_HASH && defined GIT_COMMIT_DATE)
+# ifdef GIT_COMMIT_TAG
+# define VERSIONSTRING GIT_COMMIT_TAG
+# else
+# define VERSIONSTRING "git-" GIT_COMMIT_HASH
+# endif
+#else
+# define VERSIONSTRING PACKAGE_VERSION
+#endif
+
+#define xstr(s) str(s)
+#define str(s) #s
+
+VS_VERSION_INFO VERSIONINFO
+FILEVERSION FLAC_API_VERSION_CURRENT,FLAC_API_VERSION_REVISION,0,0
+FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
+FILEFLAGS 0
+FILEOS VOS__WINDOWS32
+FILETYPE VFT_DLL
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904b0"
+ BEGIN
+ VALUE "FileDescription", "libFLAC for Windows"
+ VALUE "ProductName", "Free Lossless Audio Codec"
+ VALUE "ProductVersion", VERSIONSTRING
+ VALUE "CompanyName", "Xiph.Org"
+ VALUE "LegalCopyright", "2000-2009 Josh Coalson, 2011-2023 Xiph.Org Foundation"
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x409, 1200
+ END
+END
diff --git a/src/libFLAC/window.c b/src/libFLAC/window.c
index 4ee6f79d..69d5464a 100644
--- a/src/libFLAC/window.c
+++ b/src/libFLAC/window.c
@@ -1,6 +1,6 @@
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2006-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/metaflac/CMakeLists.txt b/src/metaflac/CMakeLists.txt
index 677ab1a5..b8af7058 100644
--- a/src/metaflac/CMakeLists.txt
+++ b/src/metaflac/CMakeLists.txt
@@ -9,6 +9,7 @@ add_executable(metaflac
options.c
usage.c
utils.c
+ version.rc
$<$<BOOL:${WIN32}>:../../include/share/win_utf8_io.h>
$<$<BOOL:${WIN32}>:../share/win_utf8_io/win_utf8_io.c>)
target_link_libraries(metaflac FLAC getopt utf8)
diff --git a/src/metaflac/Makefile.am b/src/metaflac/Makefile.am
index 446a3c37..8c212ff4 100644
--- a/src/metaflac/Makefile.am
+++ b/src/metaflac/Makefile.am
@@ -1,6 +1,6 @@
# metaflac - Command-line FLAC metadata editor
# Copyright (C) 2000-2009 Josh Coalson
-# Copyright (C) 2011-2022 Xiph.Org Foundation
+# Copyright (C) 2011-2023 Xiph.Org Foundation
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -16,12 +16,21 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+if OS_IS_WINDOWS
+win_utf8_lib = $(top_builddir)/src/share/win_utf8_io/libwin_utf8_io.la
+if HAVE_WINDRES
+metaflac_DEPENDENCIES = version.o
+windows_resource_link = -Wl,version.o
+endif
+endif
+
bin_PROGRAMS = metaflac
AM_CFLAGS = @OGG_CFLAGS@
AM_CPPFLAGS = -I$(top_builddir) -I$(srcdir)/include -I$(top_srcdir)/include
EXTRA_DIST = \
- CMakeLists.txt
+ CMakeLists.txt \
+ version.rc
metaflac_SOURCES = \
main.c \
@@ -39,11 +48,7 @@ metaflac_SOURCES = \
options.h \
usage.h \
utils.h
-metaflac_LDFLAGS = $(AM_LDFLAGS)
-
-if OS_IS_WINDOWS
-win_utf8_lib = $(top_builddir)/src/share/win_utf8_io/libwin_utf8_io.la
-endif
+metaflac_LDFLAGS = $(AM_LDFLAGS) $(windows_resource_link)
metaflac_LDADD = \
$(top_builddir)/src/share/grabbag/libgrabbag.la \
@@ -55,3 +60,6 @@ metaflac_LDADD = \
@LTLIBICONV@
CLEANFILES = metaflac.exe
+
+.rc.o:
+ $(RC) $(AM_CPPFLAGS) $< $@
diff --git a/src/metaflac/main.c b/src/metaflac/main.c
index cd488e7c..bb662935 100644
--- a/src/metaflac/main.c
+++ b/src/metaflac/main.c
@@ -1,6 +1,6 @@
/* metaflac - Command-line FLAC metadata editor
* Copyright (C) 2001-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -28,7 +28,11 @@
#include <string.h>
#include "share/compat.h"
+#ifndef FUZZ_TOOL_METAFLAC
int main(int argc, char *argv[])
+#else
+static int main_to_fuzz(int argc, char *argv[])
+#endif
{
CommandLineOptions options;
int ret = 0;
diff --git a/src/metaflac/operations.c b/src/metaflac/operations.c
index 09b225cc..d81d87a7 100644
--- a/src/metaflac/operations.c
+++ b/src/metaflac/operations.c
@@ -1,6 +1,6 @@
/* metaflac - Command-line FLAC metadata editor
* Copyright (C) 2001-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -49,6 +49,7 @@ static FLAC__bool do_shorthand_operation__add_padding(const char *filename, FLAC
static FLAC__bool passes_filter(const CommandLineOptions *options, const FLAC__StreamMetadata *block, unsigned block_number);
static void write_metadata(const char *filename, FLAC__StreamMetadata *block, unsigned block_number, FLAC__bool raw, FLAC__bool hexdump_application);
+static void write_metadata_binary(FLAC__StreamMetadata *block, FLAC__byte *block_raw, FLAC__bool headerless);
/* from operations_shorthand_seektable.c */
extern FLAC__bool do_shorthand_operation__add_seekpoints(const char *filename, FLAC__Metadata_Chain *chain, const char *specification, FLAC__bool *needs_write);
@@ -189,8 +190,20 @@ FLAC__bool do_major_operation__list(const char *filename, FLAC__Metadata_Chain *
ok &= (0 != block);
if(!ok)
flac_fprintf(stderr, "%s: ERROR: couldn't get block from chain\n", filename);
- else if(passes_filter(options, FLAC__metadata_iterator_get_block(iterator), block_number))
- write_metadata(filename, block, block_number, !options->utf8_convert, options->application_data_format_is_hexdump);
+ else if(passes_filter(options, FLAC__metadata_iterator_get_block(iterator), block_number)) {
+ if(!options->data_format_is_binary && !options->data_format_is_binary_headerless)
+ write_metadata(filename, block, block_number, !options->utf8_convert, options->application_data_format_is_hexdump);
+ else {
+ FLAC__byte * block_raw = FLAC__metadata_object_get_raw(block);
+ if(block_raw == 0) {
+ flac_fprintf(stderr, "%s: ERROR: couldn't get block in raw form\n", filename);
+ FLAC__metadata_iterator_delete(iterator);
+ return false;
+ }
+ write_metadata_binary(block, block_raw, options->data_format_is_binary_headerless);
+ free(block_raw);
+ }
+ }
block_number++;
} while(ok && FLAC__metadata_iterator_next(iterator));
@@ -201,9 +214,124 @@ FLAC__bool do_major_operation__list(const char *filename, FLAC__Metadata_Chain *
FLAC__bool do_major_operation__append(FLAC__Metadata_Chain *chain, const CommandLineOptions *options)
{
- (void) chain, (void) options;
- flac_fprintf(stderr, "ERROR: --append not implemented yet\n");
- return false;
+ FLAC__byte header[FLAC__STREAM_METADATA_HEADER_LENGTH];
+ FLAC__byte *buffer;
+ FLAC__uint32 buffer_size, num_objects = 0, i, append_after = UINT32_MAX;
+ FLAC__StreamMetadata *object;
+ FLAC__Metadata_Iterator *iterator = 0;
+ FLAC__bool has_vorbiscomment = false;
+
+ /* First, find out after which block appending should take place */
+ for(i = 0; i < options->args.num_arguments; i++) {
+ if(options->args.arguments[i].type == ARG__BLOCK_NUMBER) {
+ if(append_after != UINT32_MAX || options->args.arguments[i].value.block_number.num_entries > 1) {
+ flac_fprintf(stderr, "ERROR: more than one block number specified with --append\n");
+ return false;
+ }
+ append_after = options->args.arguments[i].value.block_number.entries[0];
+ }
+ }
+
+ iterator = FLAC__metadata_iterator_new();
+
+ if(0 == iterator)
+ die("out of memory allocating iterator");
+
+ FLAC__metadata_iterator_init(iterator, chain);
+
+ /* Find out whether there is already a vorbis comment block present */
+ do {
+ FLAC__MetadataType type = FLAC__metadata_iterator_get_block_type(iterator);
+ if(type == FLAC__METADATA_TYPE_VORBIS_COMMENT)
+ has_vorbiscomment = true;
+ }
+ while(FLAC__metadata_iterator_next(iterator));
+
+ /* Reset iterator */
+ FLAC__metadata_iterator_init(iterator, chain);
+
+ /* Go to requested block */
+ for(i = 0; i < append_after; i++) {
+ if(!FLAC__metadata_iterator_next(iterator))
+ break;
+ }
+
+#ifdef _WIN32
+ _setmode(fileno(stdin),_O_BINARY);
+#endif
+
+ /* Read header from stdin */
+ while(fread(header, 1, FLAC__STREAM_METADATA_HEADER_LENGTH, stdin) == FLAC__STREAM_METADATA_HEADER_LENGTH) {
+
+ buffer_size = ((FLAC__uint32)(header[1]) << 16) + ((FLAC__uint32)(header[2]) << 8) + header[3];
+ buffer = safe_malloc_(buffer_size + FLAC__STREAM_METADATA_HEADER_LENGTH);
+ if(0 == buffer)
+ die("out of memory allocating read buffer");
+ memcpy(buffer, header, FLAC__STREAM_METADATA_HEADER_LENGTH);
+
+ num_objects++;
+
+ if(fread(buffer+FLAC__STREAM_METADATA_HEADER_LENGTH, 1, buffer_size, stdin) < buffer_size) {
+ flac_fprintf(stderr, "ERROR: couldn't read metadata block #%u from stdin\n",(num_objects));
+ free(buffer);
+ FLAC__metadata_iterator_delete(iterator);
+ return false;
+ }
+
+ if((object = FLAC__metadata_object_set_raw(buffer, buffer_size + FLAC__STREAM_METADATA_HEADER_LENGTH)) == NULL) {
+ flac_fprintf(stderr, "ERROR: couldn't parse supplied metadata block #%u\n",(num_objects));
+ free(buffer);
+ FLAC__metadata_iterator_delete(iterator);
+ return false;
+ }
+ free(buffer);
+
+ if(has_vorbiscomment && object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
+ flac_fprintf(stderr, "ERROR: can't add another vorbis comment block to file, it already has one\n");
+ FLAC__metadata_object_delete(object);
+ FLAC__metadata_iterator_delete(iterator);
+ return false;
+ }
+
+
+ if(object->type == FLAC__METADATA_TYPE_STREAMINFO) {
+ flac_fprintf(stderr, "ERROR: can't add streaminfo to file\n");
+ FLAC__metadata_object_delete(object);
+ FLAC__metadata_iterator_delete(iterator);
+ return false;
+ }
+
+ if(object->type == FLAC__METADATA_TYPE_SEEKTABLE) {
+ flac_fprintf(stderr, "ERROR: can't add seektable to file, please use --add-seekpoint instead\n");
+ FLAC__metadata_object_delete(object);
+ FLAC__metadata_iterator_delete(iterator);
+ return false;
+ }
+
+ if(!FLAC__metadata_iterator_insert_block_after(iterator, object)) {
+ flac_fprintf(stderr, "ERROR: couldn't add supplied metadata block #%u to file\n",(num_objects));
+ FLAC__metadata_object_delete(object);
+ FLAC__metadata_iterator_delete(iterator);
+ return false;
+ }
+ /* Now check whether what type of block was added */
+ {
+ FLAC__MetadataType type = FLAC__metadata_iterator_get_block_type(iterator);
+ if(type == FLAC__METADATA_TYPE_VORBIS_COMMENT)
+ has_vorbiscomment = true;
+ }
+ }
+
+#ifdef _WIN32
+ _setmode(fileno(stdin),_O_TEXT);
+#endif
+
+ if(num_objects == 0)
+ flac_fprintf(stderr, "ERROR: unable to find a metadata block in the supplied input\n");
+
+ FLAC__metadata_iterator_delete(iterator);
+
+ return true;
}
FLAC__bool do_major_operation__remove(FLAC__Metadata_Chain *chain, const CommandLineOptions *options)
@@ -444,8 +572,11 @@ FLAC__bool do_shorthand_operation__add_replay_gain(char **filenames, unsigned nu
flac_fprintf(stderr, "%s: ERROR: # of channels (%u) is not supported, must be 1 or 2\n", filenames[i], channels);
return false;
}
+ if(bits_per_sample < FLAC__MIN_BITS_PER_SAMPLE || bits_per_sample > FLAC__MAX_BITS_PER_SAMPLE) {
+ flac_fprintf(stderr, "%s: ERROR: resolution (%u) is not supported, must be between %u and %u\n", filenames[i], bits_per_sample, FLAC__MIN_BITS_PER_SAMPLE, FLAC__MAX_BITS_PER_SAMPLE);
+ return false;
+ }
}
- FLAC__ASSERT(bits_per_sample >= FLAC__MIN_BITS_PER_SAMPLE && bits_per_sample <= FLAC__MAX_BITS_PER_SAMPLE);
if(!grabbag__replaygain_init(sample_rate)) {
FLAC__ASSERT(0);
@@ -672,3 +803,21 @@ void write_metadata(const char *filename, FLAC__StreamMetadata *block, unsigned
}
#undef PPR
}
+
+void write_metadata_binary(FLAC__StreamMetadata *block, FLAC__byte *block_raw, FLAC__bool headerless)
+{
+#ifdef _WIN32
+ fflush(stdout);
+ _setmode(fileno(stdout),_O_BINARY);
+#endif
+ if(!headerless)
+ local_fwrite(block_raw, 1, block->length+FLAC__STREAM_METADATA_HEADER_LENGTH, stdout);
+ else if(block->type == FLAC__METADATA_TYPE_APPLICATION && block->length > 3)
+ local_fwrite(block_raw+FLAC__STREAM_METADATA_HEADER_LENGTH+4, 1, block->length-4, stdout);
+ else
+ local_fwrite(block_raw+FLAC__STREAM_METADATA_HEADER_LENGTH, 1, block->length, stdout);
+#ifdef _WIN32
+ fflush(stdout);
+ _setmode(fileno(stdout),_O_TEXT);
+#endif
+}
diff --git a/src/metaflac/operations.h b/src/metaflac/operations.h
index a5c1ebbb..79e1c3ba 100644
--- a/src/metaflac/operations.h
+++ b/src/metaflac/operations.h
@@ -1,6 +1,6 @@
/* metaflac - Command-line FLAC metadata editor
* Copyright (C) 2001-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/metaflac/operations_shorthand.h b/src/metaflac/operations_shorthand.h
index 6567efe2..1877c268 100644
--- a/src/metaflac/operations_shorthand.h
+++ b/src/metaflac/operations_shorthand.h
@@ -1,6 +1,6 @@
/* metaflac - Command-line FLAC metadata editor
* Copyright (C) 2001-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/metaflac/operations_shorthand_cuesheet.c b/src/metaflac/operations_shorthand_cuesheet.c
index 72154efb..13c4dedb 100644
--- a/src/metaflac/operations_shorthand_cuesheet.c
+++ b/src/metaflac/operations_shorthand_cuesheet.c
@@ -1,6 +1,6 @@
/* metaflac - Command-line FLAC metadata editor
* Copyright (C) 2001-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -69,6 +69,12 @@ FLAC__bool do_shorthand_operation__cuesheet(const char *filename, FLAC__Metadata
return false;
}
+ if(sample_rate == 0) {
+ flac_fprintf(stderr, "%s: ERROR: cannot parse cuesheet when sample rate is unknown\n", filename);
+ FLAC__metadata_iterator_delete(iterator);
+ return false;
+ }
+
switch(operation->type) {
case OP__IMPORT_CUESHEET_FROM:
if(0 != cuesheet) {
@@ -144,6 +150,7 @@ FLAC__bool import_cs_from(const char *filename, FLAC__StreamMetadata **cuesheet,
if(!FLAC__format_cuesheet_is_legal(&(*cuesheet)->data.cue_sheet, /*check_cd_da_subset=*/false, &error_message)) {
flac_fprintf(stderr, "%s: ERROR parsing cuesheet \"%s\": %s\n", filename, cs_filename, error_message);
+ FLAC__metadata_object_delete(*cuesheet);
return false;
}
@@ -209,6 +216,11 @@ FLAC__bool export_cs_to(const char *filename, const FLAC__StreamMetadata *cueshe
if(f != stdout)
fclose(f);
+#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
+ /* Delete output file when fuzzing */
+ if(f != stdout)
+ flac_unlink(cs_filename);
+#endif
return true;
}
diff --git a/src/metaflac/operations_shorthand_picture.c b/src/metaflac/operations_shorthand_picture.c
index 1c5ecf40..6bb459ba 100644
--- a/src/metaflac/operations_shorthand_picture.c
+++ b/src/metaflac/operations_shorthand_picture.c
@@ -1,6 +1,6 @@
/* metaflac - Command-line FLAC metadata editor
* Copyright (C) 2001-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -136,6 +136,8 @@ FLAC__bool import_pic_from(const char *filename, FLAC__StreamMetadata **picture,
if(!FLAC__format_picture_is_legal(&(*picture)->data.picture, &error_message)) {
flac_fprintf(stderr, "%s: ERROR: new PICTURE block for \"%s\" is illegal: %s\n", filename, specification, error_message);
+ FLAC__metadata_object_delete(*picture);
+ *picture = 0;
return false;
}
@@ -172,5 +174,11 @@ FLAC__bool export_pic_to(const char *filename, const FLAC__StreamMetadata *pictu
if(f != stdout)
fclose(f);
+#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
+ /* Delete output file when fuzzing */
+ if(f != stdout)
+ flac_unlink(pic_filename);
+#endif
+
return true;
}
diff --git a/src/metaflac/operations_shorthand_seektable.c b/src/metaflac/operations_shorthand_seektable.c
index 50136581..c9175b36 100644
--- a/src/metaflac/operations_shorthand_seektable.c
+++ b/src/metaflac/operations_shorthand_seektable.c
@@ -1,6 +1,6 @@
/* metaflac - Command-line FLAC metadata editor
* Copyright (C) 2001-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -55,6 +55,7 @@ FLAC__bool do_shorthand_operation__add_seekpoints(const char *filename, FLAC__Me
if(total_samples == 0) {
flac_fprintf(stderr, "%s: ERROR: cannot add seekpoints because STREAMINFO block does not specify total_samples\n", filename);
+ FLAC__metadata_iterator_delete(iterator);
return false;
}
@@ -68,6 +69,7 @@ FLAC__bool do_shorthand_operation__add_seekpoints(const char *filename, FLAC__Me
if(!FLAC__metadata_iterator_insert_block_after(iterator, block)) {
print_error_with_chain_status(chain, "%s: ERROR: adding new SEEKTABLE block to metadata", filename);
FLAC__metadata_object_delete(block);
+ FLAC__metadata_iterator_delete(iterator);
return false;
}
/* iterator is left pointing to new block */
diff --git a/src/metaflac/operations_shorthand_streaminfo.c b/src/metaflac/operations_shorthand_streaminfo.c
index 0fe471ec..32198416 100644
--- a/src/metaflac/operations_shorthand_streaminfo.c
+++ b/src/metaflac/operations_shorthand_streaminfo.c
@@ -1,6 +1,6 @@
/* metaflac - Command-line FLAC metadata editor
* Copyright (C) 2001-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/metaflac/operations_shorthand_vorbiscomment.c b/src/metaflac/operations_shorthand_vorbiscomment.c
index bf135d4b..27c9e4c8 100644
--- a/src/metaflac/operations_shorthand_vorbiscomment.c
+++ b/src/metaflac/operations_shorthand_vorbiscomment.c
@@ -1,6 +1,6 @@
/* metaflac - Command-line FLAC metadata editor
* Copyright (C) 2001-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -419,5 +419,12 @@ FLAC__bool export_vc_to(const char *filename, FLAC__StreamMetadata *block, const
if(f != stdout)
fclose(f);
+
+#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
+ /* Delete output file when fuzzing */
+ if(f != stdout)
+ flac_unlink(vc_filename->value);
+#endif
+
return ret;
}
diff --git a/src/metaflac/options.c b/src/metaflac/options.c
index 10d05906..1b4b6f62 100644
--- a/src/metaflac/options.c
+++ b/src/metaflac/options.c
@@ -1,6 +1,6 @@
/* metaflac - Command-line FLAC metadata editor
* Copyright (C) 2001-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -139,6 +139,8 @@ void init_options(CommandLineOptions *options)
options->cued_seekpoints = true;
options->show_long_help = false;
options->show_version = false;
+ options->data_format_is_binary = false;
+ options->data_format_is_binary_headerless = false;
options->application_data_format_is_hexdump = false;
options->ops.operations = 0;
@@ -210,7 +212,7 @@ FLAC__bool parse_options(int argc, char *argv[], CommandLineOptions *options)
}
/* check for only one FLAC file used with certain options */
- if(options->num_files > 1) {
+ if(!had_error && options->num_files > 1) {
if(0 != find_shorthand_operation(options, OP__IMPORT_CUESHEET_FROM)) {
flac_fprintf(stderr, "ERROR: you may only specify one FLAC file when using '--import-cuesheet-from'\n");
had_error = true;
@@ -713,6 +715,8 @@ FLAC__bool parse_option(int option_index, const char *option_argument, CommandLi
flac_fprintf(stderr, "ERROR (--%s): illegal data format \"%s\"\n", opt, option_argument);
ok = false;
}
+ options->data_format_is_binary = arg->value.data_format.is_binary;
+ options->data_format_is_binary_headerless = arg->value.data_format.is_headerless;
}
else if(0 == strcmp(opt, "application-data-format")) {
FLAC__ASSERT(0 != option_argument);
@@ -1108,10 +1112,18 @@ FLAC__bool parse_block_type(const char *in, Argument_BlockType *out)
FLAC__bool parse_data_format(const char *in, Argument_DataFormat *out)
{
- if(0 == strcmp(in, "binary"))
+ if(0 == strcmp(in, "binary-headerless")) {
+ out->is_binary = false;
+ out->is_headerless = true;
+ }
+ else if(0 == strcmp(in, "binary")) {
out->is_binary = true;
- else if(0 == strcmp(in, "text"))
+ out->is_headerless = false;
+ }
+ else if(0 == strcmp(in, "text")) {
out->is_binary = false;
+ out->is_headerless = false;
+ }
else
return false;
return true;
diff --git a/src/metaflac/options.h b/src/metaflac/options.h
index d13e2d88..984f2e11 100644
--- a/src/metaflac/options.h
+++ b/src/metaflac/options.h
@@ -1,6 +1,6 @@
/* metaflac - Command-line FLAC metadata editor
* Copyright (C) 2001-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -131,6 +131,7 @@ typedef struct {
typedef struct {
FLAC__bool is_binary;
+ FLAC__bool is_headerless;
} Argument_DataFormat;
typedef struct {
@@ -190,6 +191,8 @@ typedef struct {
FLAC__bool cued_seekpoints;
FLAC__bool show_long_help;
FLAC__bool show_version;
+ FLAC__bool data_format_is_binary;
+ FLAC__bool data_format_is_binary_headerless;
FLAC__bool application_data_format_is_hexdump;
struct {
Operation *operations;
diff --git a/src/metaflac/usage.c b/src/metaflac/usage.c
index 62c2f1a8..58afc0ea 100644
--- a/src/metaflac/usage.c
+++ b/src/metaflac/usage.c
@@ -1,6 +1,6 @@
/* metaflac - Command-line FLAC metadata editor
* Copyright (C) 2001-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -21,6 +21,7 @@
# include <config.h>
#endif
+#include "utils.h"
#include "usage.h"
#include "FLAC/format.h"
#include <stdarg.h>
@@ -32,7 +33,7 @@ static void usage_header(FILE *out)
fprintf(out, "==============================================================================\n");
fprintf(out, "metaflac - Command-line FLAC metadata editor version %s\n", FLAC__VERSION_STRING);
fprintf(out, "Copyright (C) 2001-2009 Josh Coalson\n");
- fprintf(out, "Copyright (C) 2011-2022 Xiph.Org Foundation\n");
+ fprintf(out, "Copyright (C) 2011-2023 Xiph.Org Foundation\n");
fprintf(out, "\n");
fprintf(out, "This program is free software; you can redistribute it and/or\n");
fprintf(out, "modify it under the terms of the GNU General Public License\n");
@@ -61,7 +62,9 @@ static void usage_summary(FILE *out)
fprintf(out, "Options:\n");
fprintf(out, "--preserve-modtime Preserve the original modification time in spite of edits\n");
fprintf(out, "--with-filename Prefix each output line with the FLAC file name\n");
- fprintf(out, " (the default if more than one FLAC file is specified)\n");
+ fprintf(out, " (the default if more than one FLAC file is specified).\n");
+ fprintf(out, " This option has no effect for options exporting to a\n");
+ fprintf(out, " file, like --export-tags-to.\n");
fprintf(out, "--no-filename Do not prefix each output line with the FLAC file name\n");
fprintf(out, " (the default if only one FLAC file is specified)\n");
fprintf(out, "--no-utf8-convert Do not convert tags from UTF-8 to local charset,\n");
@@ -274,23 +277,30 @@ int long_usage(const char *message, ...)
fprintf(out, " NOTE: if both --block-number and --[except-]block-type are specified,\n");
fprintf(out, " the result is the logical AND of both arguments.\n");
fprintf(out, "\n");
-#if 0
- /*@@@ not implemented yet */
- fprintf(out, " --data-format=binary|text\n");
+ fprintf(out, " --data-format=binary|binary-headerless|text\n");
fprintf(out, " By default a human-readable text representation of the data is displayed.\n");
fprintf(out, " You may specify --data-format=binary to dump the raw binary form of each\n");
- fprintf(out, " metadata block. The output can be read in using a subsequent call to\n");
- fprintf(out, " "metaflac --append --from-file=..."\n");
+ fprintf(out, " metadata block. Specify --data-format=binary-headerless to omit output of\n");
+ fprintf(out, " metadata block headers, including the id of APPLICATION metadata blocks.\n");
+ fprintf(out, " The output can be read in using a subsequent call to\n");
+ fprintf(out, " \"metaflac --append\"\n");
fprintf(out, "\n");
-#endif
fprintf(out, " --application-data-format=hexdump|text\n");
fprintf(out, " If the application block you are displaying contains binary data but your\n");
fprintf(out, " --data-format=text, you can display a hex dump of the application data\n");
fprintf(out, " contents instead using --application-data-format=hexdump\n");
fprintf(out, "\n");
-#if 0
- /*@@@ not implemented yet */
fprintf(out, "--append\n");
+ fprintf(out, " Insert a metadata block from a file. This must be a binary block as\n");
+ fprintf(out, " exported with --list --data-format=binary. The insertion point is\n");
+ fprintf(out, " defined with --block-number=#. The new block will be added after the\n");
+ fprintf(out, " given block number. This prevents the illegal insertion of a block\n");
+ fprintf(out, " before the first STREAMINFO block. You may not --append another\n");
+ fprintf(out, " STREAMINFO block. It is possible to copy a metadata block from one\n");
+ fprintf(out, " file to another with this option. For example use\n");
+ fprintf(out, " metaflac --list --data-format=binary --block-number=6 file.flac > block\n");
+ fprintf(out, " to export the block, and then import it with\n");
+ fprintf(out, " metaflac --append anotherfile.flac < block\n");
fprintf(out, " Insert a metadata block from a file. The input file must be in the same\n");
fprintf(out, " format as generated with --list.\n");
fprintf(out, "\n");
@@ -300,6 +310,8 @@ int long_usage(const char *message, ...)
fprintf(out, " of a block before the first STREAMINFO block. You may not --append another\n");
fprintf(out, " STREAMINFO block.\n");
fprintf(out, "\n");
+#if 0
+ /*@@@ not implemented yet */
fprintf(out, " --from-file=filename\n");
fprintf(out, " Mandatory 'option' to specify the input file containing the block contents.\n");
fprintf(out, "\n");
diff --git a/src/metaflac/usage.h b/src/metaflac/usage.h
index 86893edc..1366417a 100644
--- a/src/metaflac/usage.h
+++ b/src/metaflac/usage.h
@@ -1,6 +1,6 @@
/* metaflac - Command-line FLAC metadata editor
* Copyright (C) 2001-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/metaflac/utils.c b/src/metaflac/utils.c
index e3f27601..045719a7 100644
--- a/src/metaflac/utils.c
+++ b/src/metaflac/utils.c
@@ -1,6 +1,6 @@
/* metaflac - Command-line FLAC metadata editor
* Copyright (C) 2001-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -76,12 +76,18 @@ void local_strcat(char **dest, const char *source)
*dest = safe_realloc_add_3op_(*dest, ndest, /*+*/nsource, /*+*/1);
if(*dest == NULL)
die("out of memory growing string");
+ /* If ndest == 0, strlen in safe_strncat reads
+ * uninitialized data. To prevent that, set first character
+ * to zero */
+ if(ndest == 0)
+ *dest[0] = 0;
safe_strncat(*dest, source, outlen);
}
static inline int local_isprint(int c)
{
if (c < 32) return 0;
+ if (c > 127) return 0;
return isprint(c);
}
diff --git a/src/metaflac/utils.h b/src/metaflac/utils.h
index 41c395be..972a4501 100644
--- a/src/metaflac/utils.h
+++ b/src/metaflac/utils.h
@@ -1,6 +1,6 @@
/* metaflac - Command-line FLAC metadata editor
* Copyright (C) 2001-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -23,6 +23,11 @@
#include "FLAC/metadata.h"
#include <stdio.h> /* for FILE */
+#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
+#undef stderr
+#define stderr stdout
+#endif
+
void die(const char *message);
#ifdef FLAC__VALGRIND_TESTING
size_t local_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
diff --git a/src/metaflac/version.rc b/src/metaflac/version.rc
new file mode 100644
index 00000000..51172024
--- /dev/null
+++ b/src/metaflac/version.rc
@@ -0,0 +1,38 @@
+#include <winver.h>
+#include "config.h"
+
+#if (defined GIT_COMMIT_HASH && defined GIT_COMMIT_DATE)
+# ifdef GIT_COMMIT_TAG
+# define VERSIONSTRING GIT_COMMIT_TAG
+# else
+# define VERSIONSTRING "git-" GIT_COMMIT_HASH
+# endif
+#else
+# define VERSIONSTRING PACKAGE_VERSION
+#endif
+
+#define xstr(s) str(s)
+#define str(s) #s
+
+VS_VERSION_INFO VERSIONINFO
+FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
+FILEFLAGS 0
+FILEOS VOS__WINDOWS32
+FILETYPE VFT_DLL
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904b0"
+ BEGIN
+ VALUE "FileDescription", "metaflac command line tool for Windows"
+ VALUE "ProductName", "Free Lossless Audio Codec"
+ VALUE "ProductVersion", VERSIONSTRING
+ VALUE "CompanyName", "Xiph.Org"
+ VALUE "LegalCopyright", "2000-2009 Josh Coalson, 2011-2023 Xiph.Org Foundation"
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x409, 1200
+ END
+END
diff --git a/src/share/Makefile.am b/src/share/Makefile.am
index 412a7dff..caf61226 100644
--- a/src/share/Makefile.am
+++ b/src/share/Makefile.am
@@ -1,6 +1,6 @@
# FLAC - Free Lossless Audio Codec
# Copyright (C) 2002-2009 Josh Coalson
-# Copyright (C) 2011-2022 Xiph.Org Foundation
+# Copyright (C) 2011-2023 Xiph.Org Foundation
#
# This file is part the FLAC project. FLAC is comprised of several
# components distributed under different licenses. The codec libraries
diff --git a/src/share/getopt/getopt1.c b/src/share/getopt/getopt1.c
index 740e498b..fc526784 100644
--- a/src/share/getopt/getopt1.c
+++ b/src/share/getopt/getopt1.c
@@ -36,9 +36,6 @@
# include <config.h>
#endif
-#include "share/getopt.h"
-/*[JEC] was:#include "getopt.h"*/
-
#if !defined __STDC__ || !__STDC__
/* This is a separate conditional since some stdc systems
reject `defined (const)'. */
@@ -49,6 +46,9 @@
#include <stdio.h>
+#include "share/getopt.h"
+/*[JEC] was:#include "getopt.h"*/
+
/* Comment out all this code if we are using the GNU C Library, and are not
actually compiling the library itself. This code is part of the GNU C
Library, but also included in many other GNU distributions. Compiling
@@ -79,13 +79,7 @@
#define NULL 0
#endif
-int
-share__getopt_long (argc, argv, options, long_options, opt_index)
- int argc;
- char *const *argv;
- const char *options;
- const struct share__option *long_options;
- int *opt_index;
+int share__getopt_long(int argc, char *const *argv, const char *options, const struct share__option *long_options, int *opt_index)
{
return share___getopt_internal (argc, argv, options, long_options, opt_index, 0);
}
@@ -95,13 +89,7 @@ share__getopt_long (argc, argv, options, long_options, opt_index)
but does match a short option, it is parsed as a short option
instead. */
-int
-share__getopt_long_only (argc, argv, options, long_options, opt_index)
- int argc;
- char *const *argv;
- const char *options;
- const struct share__option *long_options;
- int *opt_index;
+int share__getopt_long_only(int argc, char *const *argv, const char *options, const struct share__option *long_options, int *opt_index)
{
return share___getopt_internal (argc, argv, options, long_options, opt_index, 1);
}
@@ -113,10 +101,7 @@ share__getopt_long_only (argc, argv, options, long_options, opt_index)
#include <stdio.h>
-int
-main (argc, argv)
- int argc;
- char **argv;
+int main(int argc, char **argv)
{
int c;
int digit_optind = 0;
diff --git a/src/share/grabbag/alloc.c b/src/share/grabbag/alloc.c
index edf189a0..4e5fb60c 100644
--- a/src/share/grabbag/alloc.c
+++ b/src/share/grabbag/alloc.c
@@ -1,6 +1,6 @@
/* alloc - Convenience routines for safely allocating memory
* Copyright (C) 2007-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/share/grabbag/cuesheet.c b/src/share/grabbag/cuesheet.c
index 1e1a132b..0d19ee72 100644
--- a/src/share/grabbag/cuesheet.c
+++ b/src/share/grabbag/cuesheet.c
@@ -1,6 +1,6 @@
/* grabbag - Convenience lib for various routines common to several tools
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -24,6 +24,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <limits.h>
#include "FLAC/assert.h"
#include "share/compat.h"
#include "share/grabbag.h"
@@ -44,17 +45,21 @@ void grabbag__cuesheet_frame_to_msf(uint32_t frame, uint32_t *minutes, uint32_t
}
/* since we only care about values >= 0 or error, returns < 0 for any illegal string, else value */
-static int local__parse_int_(const char *s)
+static FLAC__int64 local__parse_int64_(const char *s)
{
- int ret = 0;
+ FLAC__int64 ret = 0;
char c;
if(*s == '\0')
return -1;
while('\0' != (c = *s++))
- if(c >= '0' && c <= '9')
- ret = ret * 10 + (c - '0');
+ if(c >= '0' && c <= '9') {
+ if(ret >= (INT64_MAX / 10))
+ return -1;
+ else
+ ret = ret * 10 + (c - '0');
+ }
else
return -1;
@@ -62,21 +67,12 @@ static int local__parse_int_(const char *s)
}
/* since we only care about values >= 0 or error, returns < 0 for any illegal string, else value */
-static FLAC__int64 local__parse_int64_(const char *s)
+static int local__parse_int_(const char *s)
{
- FLAC__int64 ret = 0;
- char c;
-
- if(*s == '\0')
+ FLAC__int64 ret64 = local__parse_int64_(s);
+ if(ret64 < 0 || ret64 > INT_MAX)
return -1;
-
- while('\0' != (c = *s++))
- if(c >= '0' && c <= '9')
- ret = ret * 10 + (c - '0');
- else
- return -1;
-
- return ret;
+ return ret64;
}
/* accept minute:second:frame syntax of '[0-9]+:[0-9][0-9]?:[0-9][0-9]?', but max second of 59 and max frame of 74, e.g. 0:0:0, 123:45:67
@@ -88,18 +84,27 @@ static FLAC__int64 local__parse_msf_(const char *s, uint32_t sample_rate)
FLAC__int64 ret, field;
char c;
+ if(sample_rate == 0)
+ return -1;
+
c = *s++;
if(c >= '0' && c <= '9')
field = (c - '0');
else
return -1;
while(':' != (c = *s++)) {
- if(c >= '0' && c <= '9')
- field = field * 10 + (c - '0');
+ if(c >= '0' && c <= '9') {
+ if(field >= (INT64_MAX / 10))
+ return -1;
+ else
+ field = field * 10 + (c - '0');
+ }
else
return -1;
}
+ if(field >= INT64_MAX / (60 * sample_rate))
+ return -1;
ret = field * 60 * sample_rate;
c = *s++;
@@ -121,7 +126,12 @@ static FLAC__int64 local__parse_msf_(const char *s, uint32_t sample_rate)
if(field >= 60)
return -1;
- ret += field * sample_rate;
+ {
+ FLAC__int64 tmp = ret;
+ ret += field * sample_rate;
+ if(ret < tmp)
+ return -1;
+ }
c = *s++;
if(c >= '0' && c <= '9')
@@ -143,7 +153,12 @@ static FLAC__int64 local__parse_msf_(const char *s, uint32_t sample_rate)
if(field >= 75)
return -1;
- ret += field * (sample_rate / 75);
+ {
+ FLAC__int64 tmp = ret;
+ ret += field * (sample_rate / 75);
+ if(ret < tmp)
+ return -1;
+ }
return ret;
}
@@ -158,21 +173,29 @@ static FLAC__int64 local__parse_ms_(const char *s, uint32_t sample_rate)
double x;
char c, *end;
+ if(sample_rate == 0)
+ return -1;
+
c = *s++;
if(c >= '0' && c <= '9')
field = (c - '0');
else
return -1;
while(':' != (c = *s++)) {
- if(c >= '0' && c <= '9')
- field = field * 10 + (c - '0');
+ if(c >= '0' && c <= '9') {
+ if(field >= (INT64_MAX / 10))
+ return -1;
+ else
+ field = field * 10 + (c - '0');
+ }
else
return -1;
}
+ if(field >= INT64_MAX / (60 * sample_rate))
+ return -1;
ret = field * 60 * sample_rate;
- s++; /* skip the ':' */
if(strspn(s, "0123456789.") != strlen(s))
return -1;
x = strtod(s, &end);
@@ -626,6 +649,8 @@ void grabbag__cuesheet_emit(FILE *file, const FLAC__StreamMetadata *cuesheet, co
fprintf(file, "CATALOG %s\n", cs->media_catalog_number);
fprintf(file, "FILE %s\n", file_reference);
+ FLAC__ASSERT(cs->num_tracks > 0);
+
for(track_num = 0; track_num < cs->num_tracks-1; track_num++) {
const FLAC__StreamMetadata_CueSheet_Track *track = cs->tracks + track_num;
diff --git a/src/share/grabbag/file.c b/src/share/grabbag/file.c
index 1a781526..307645f5 100644
--- a/src/share/grabbag/file.c
+++ b/src/share/grabbag/file.c
@@ -1,6 +1,6 @@
/* grabbag - Convenience lib for various routines common to several tools
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
diff --git a/src/share/grabbag/picture.c b/src/share/grabbag/picture.c
index 9be95ea3..9a4aafe2 100644
--- a/src/share/grabbag/picture.c
+++ b/src/share/grabbag/picture.c
@@ -1,6 +1,6 @@
/* grabbag - Convenience lib for various routines common to several tools
* Copyright (C) 2006-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/share/grabbag/replaygain.c b/src/share/grabbag/replaygain.c
index 7d81e0fe..32c96031 100644
--- a/src/share/grabbag/replaygain.c
+++ b/src/share/grabbag/replaygain.c
@@ -1,6 +1,6 @@
/* grabbag - Convenience lib for various routines common to several tools
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -641,6 +641,8 @@ FLAC__bool grabbag__replaygain_load_from_vorbiscomment(const FLAC__StreamMetadat
res = false;
if(res && !parse_double_(block->data.vorbis_comment.comments + peak_offset, peak))
res = false;
+ if(res && *peak < 0.0)
+ res = false;
setlocale(LC_ALL, saved_locale);
free(saved_locale);
diff --git a/src/share/grabbag/seektable.c b/src/share/grabbag/seektable.c
index 96b56c31..01caa998 100644
--- a/src/share/grabbag/seektable.c
+++ b/src/share/grabbag/seektable.c
@@ -1,6 +1,6 @@
/* grabbag - Convenience lib for various routines common to several tools
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -61,8 +61,7 @@ FLAC__bool grabbag__seektable_convert_specification_to_template(const char *spec
}
}
else if(q[-1] == 's') { /* -S #s */
- if(total_samples_to_encode > 0) { /* we can only do these if we know the number of samples to encode up front */
- FLAC__ASSERT(sample_rate > 0);
+ if(total_samples_to_encode > 0 && sample_rate > 0) { /* we can only do these if we know the number of samples and sample rate to encode up front */
if(0 != spec_has_real_points)
*spec_has_real_points = true;
if(!only_explicit_placeholders) {
diff --git a/src/share/grabbag/snprintf.c b/src/share/grabbag/snprintf.c
index 4453a1bd..bd7ffba8 100644
--- a/src/share/grabbag/snprintf.c
+++ b/src/share/grabbag/snprintf.c
@@ -1,5 +1,5 @@
/* grabbag - Convenience lib for various routines common to several tools
- * Copyright (C) 2013-2022 Xiph.Org Foundation
+ * Copyright (C) 2013-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/src/share/replaygain_synthesis/replaygain_synthesis.c b/src/share/replaygain_synthesis/replaygain_synthesis.c
index 328afd10..8d4fda6b 100644
--- a/src/share/replaygain_synthesis/replaygain_synthesis.c
+++ b/src/share/replaygain_synthesis/replaygain_synthesis.c
@@ -1,6 +1,6 @@
/* replaygain_synthesis - Routines for applying ReplayGain to a signal
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
diff --git a/src/share/utf8/iconvert.c b/src/share/utf8/iconvert.c
index 876c06e8..9a1e3f6b 100644
--- a/src/share/utf8/iconvert.c
+++ b/src/share/utf8/iconvert.c
@@ -62,7 +62,7 @@ int iconvert(const char *fromcode, const char *tocode,
char *ib;
char *ob;
char *utfbuf = 0, *outbuf, *newbuf;
- size_t utflen, outlen, ibl, obl, k;
+ size_t utflen, outlen, ibl, obl, obp, k;
char tbuf[2048];
cd1 = iconv_open("UTF-8", fromcode);
@@ -124,11 +124,12 @@ int iconvert(const char *fromcode, const char *tocode,
if(utflen*2 < utflen) /* overflow check */
goto fail;
utflen *= 2;
+ obp = ob - utfbuf; /* save position */
newbuf = realloc(utfbuf, utflen);
if (!newbuf)
goto fail;
- ob = (ob - utfbuf) + newbuf;
- obl = utflen - (ob - newbuf);
+ ob = newbuf + obp;
+ obl = utflen - obp;
utfbuf = newbuf;
}
else {
@@ -161,6 +162,8 @@ int iconvert(const char *fromcode, const char *tocode,
/* Truncate the buffer to be tidy */
utflen = ob - utfbuf;
+ if (utflen == 0)
+ goto fail;
newbuf = realloc(utfbuf, utflen);
if (!newbuf)
goto fail;
diff --git a/src/share/win_utf8_io/win_utf8_io.c b/src/share/win_utf8_io/win_utf8_io.c
index 65b56997..3ae35b31 100644
--- a/src/share/win_utf8_io/win_utf8_io.c
+++ b/src/share/win_utf8_io/win_utf8_io.c
@@ -1,5 +1,5 @@
/* libFLAC - Free Lossless Audio Codec library
- * Copyright (C) 2013-2022 Xiph.Org Foundation
+ * Copyright (C) 2013-2023 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -39,9 +39,15 @@
#define UTF8_BUFFER_SIZE 32768
-#if !defined(WINAPI_FAMILY_PARTITION)
-#define WINAPI_FAMILY_PARTITION(x) x
-#define WINAPI_PARTITION_DESKTOP 1
+/* detect whether it is Windows APP (UWP) or standard Win32 envionment */
+#ifdef WINAPI_FAMILY_PARTITION
+ #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
+ #define FLAC_WINDOWS_APP 1
+ #else
+ #define FLAC_WINDOWS_APP 0
+ #endif
+#else
+ #define FLAC_WINDOWS_APP 0
#endif
static int local_vsnprintf(char *str, size_t size, const char *fmt, va_list va)
@@ -106,15 +112,22 @@ static wchar_t *wchar_from_utf8(const char *str)
/* retrieve WCHAR commandline, expand wildcards and convert everything to UTF-8 */
int get_utf8_argv(int *argc, char ***argv)
{
+#if !FLAC_WINDOWS_APP
typedef int (__cdecl *wgetmainargs_t)(int*, wchar_t***, wchar_t***, int, int*);
wgetmainargs_t wgetmainargs;
HMODULE handle;
+#endif // !FLAC_WINDOWS_APP
int wargc;
wchar_t **wargv;
wchar_t **wenv;
char **utf8argv;
int ret, i;
+#if FLAC_WINDOWS_APP
+ wargc = __argc;
+ wargv = __wargv;
+ wenv = _wenviron;
+#else // !FLAC_WINDOWS_APP
if ((handle = LoadLibraryW(L"msvcrt.dll")) == NULL) return 1;
if ((wgetmainargs = (wgetmainargs_t)GetProcAddress(handle, "__wgetmainargs")) == NULL) {
FreeLibrary(handle);
@@ -126,8 +139,11 @@ int get_utf8_argv(int *argc, char ***argv)
FreeLibrary(handle);
return 1;
}
+#endif // !FLAC_WINDOWS_APP
if ((utf8argv = (char **)calloc(wargc, sizeof(char*))) == NULL) {
+ #if !FLAC_WINDOWS_APP
FreeLibrary(handle);
+ #endif // !FLAC_WINDOWS_APP
return 1;
}
@@ -139,7 +155,9 @@ int get_utf8_argv(int *argc, char ***argv)
}
}
+#if !FLAC_WINDOWS_APP
FreeLibrary(handle); /* do not free it when wargv or wenv are still in use */
+#endif // !FLAC_WINDOWS_APP
if (ret == 0) {
*argc = wargc;
@@ -160,9 +178,9 @@ HANDLE WINAPI CreateFile_utf8(const char *lpFileName, DWORD dwDesiredAccess, DWO
HANDLE handle = INVALID_HANDLE_VALUE;
if ((wname = wchar_from_utf8(lpFileName)) != NULL) {
-#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
+#if !FLAC_WINDOWS_APP
handle = CreateFileW(wname, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
-#else // !WINAPI_PARTITION_DESKTOP
+#else // FLAC_WINDOWS_APP
CREATEFILE2_EXTENDED_PARAMETERS params;
params.dwSize = sizeof(params);
params.dwFileAttributes = dwFlagsAndAttributes & 0xFFFF;
@@ -171,7 +189,7 @@ HANDLE WINAPI CreateFile_utf8(const char *lpFileName, DWORD dwDesiredAccess, DWO
params.lpSecurityAttributes = lpSecurityAttributes;
params.hTemplateFile = hTemplateFile;
handle = CreateFile2(wname, dwDesiredAccess, dwShareMode, dwCreationDisposition, &params);
-#endif // !WINAPI_PARTITION_DESKTOP
+#endif // FLAC_WINDOWS_APP
free(wname);
}
@@ -193,19 +211,19 @@ size_t strlen_utf8(const char *str)
int win_get_console_width(void)
{
int width = 80;
-#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
+#if !FLAC_WINDOWS_APP
CONSOLE_SCREEN_BUFFER_INFO csbi;
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
if(hOut != INVALID_HANDLE_VALUE && hOut != NULL)
if (GetConsoleScreenBufferInfo(hOut, &csbi) != 0)
width = csbi.dwSize.X;
-#endif // WINAPI_PARTITION_DESKTOP
+#endif // !FLAC_WINDOWS_APP
return width;
}
/* print functions */
-#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
+#if !FLAC_WINDOWS_APP
static int wprint_console(FILE *stream, const wchar_t *text, size_t len)
{
DWORD out;
@@ -235,7 +253,7 @@ static int wprint_console(FILE *stream, const wchar_t *text, size_t len)
return ret;
return len;
}
-#endif // WINAPI_PARTITION_DESKTOP
+#endif // !FLAC_WINDOWS_APP
int printf_utf8(const char *format, ...)
{
@@ -276,12 +294,12 @@ int vfprintf_utf8(FILE *stream, const char *format, va_list argptr)
ret = -1;
break;
}
-#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
+#if !FLAC_WINDOWS_APP
ret = wprint_console(stream, wout, wcslen(wout));
-#else // !WINAPI_PARTITION_DESKTOP
+#else // FLAC_WINDOWS_APP
OutputDebugStringW(wout);
ret = 0;
-#endif // !WINAPI_PARTITION_DESKTOP
+#endif // FLAC_WINDOWS_APP
} while(0);
free(utmp);
diff --git a/src/test_grabbag/Makefile.am b/src/test_grabbag/Makefile.am
index 74e21ce3..ea710091 100644
--- a/src/test_grabbag/Makefile.am
+++ b/src/test_grabbag/Makefile.am
@@ -1,6 +1,6 @@
# FLAC - Free Lossless Audio Codec
# Copyright (C) 2002-2009 Josh Coalson
-# Copyright (C) 2011-2022 Xiph.Org Foundation
+# Copyright (C) 2011-2023 Xiph.Org Foundation
#
# This file is part the FLAC project. FLAC is comprised of several
# components distributed under different licenses. The codec libraries
diff --git a/src/test_grabbag/cuesheet/Makefile.am b/src/test_grabbag/cuesheet/Makefile.am
index e9d2465a..1cee3707 100644
--- a/src/test_grabbag/cuesheet/Makefile.am
+++ b/src/test_grabbag/cuesheet/Makefile.am
@@ -1,6 +1,6 @@
# test_cuesheet - Simple tester for cuesheet routines in grabbag
# Copyright (C) 2002-2009 Josh Coalson
-# Copyright (C) 2011-2022 Xiph.Org Foundation
+# Copyright (C) 2011-2023 Xiph.Org Foundation
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/src/test_grabbag/cuesheet/main.c b/src/test_grabbag/cuesheet/main.c
index b40ead8b..b3d0e9ab 100644
--- a/src/test_grabbag/cuesheet/main.c
+++ b/src/test_grabbag/cuesheet/main.c
@@ -1,6 +1,6 @@
/* test_cuesheet - Simple tester for cuesheet routines in grabbag
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/test_grabbag/picture/Makefile.am b/src/test_grabbag/picture/Makefile.am
index 1e336595..45e14571 100644
--- a/src/test_grabbag/picture/Makefile.am
+++ b/src/test_grabbag/picture/Makefile.am
@@ -1,6 +1,6 @@
# test_picture - Simple tester for picture routines in grabbag
# Copyright (C) 2006-2009 Josh Coalson
-# Copyright (C) 2011-2022 Xiph.Org Foundation
+# Copyright (C) 2011-2023 Xiph.Org Foundation
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/src/test_grabbag/picture/main.c b/src/test_grabbag/picture/main.c
index 6b8b17a2..fe43be94 100644
--- a/src/test_grabbag/picture/main.c
+++ b/src/test_grabbag/picture/main.c
@@ -1,6 +1,6 @@
/* test_picture - Simple tester for picture routines in grabbag
* Copyright (C) 2006-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/test_libFLAC++/Makefile.am b/src/test_libFLAC++/Makefile.am
index a27f1fa7..8bf746f7 100644
--- a/src/test_libFLAC++/Makefile.am
+++ b/src/test_libFLAC++/Makefile.am
@@ -1,6 +1,6 @@
# test_libFLAC++ - Unit tester for libFLAC++
# Copyright (C) 2002-2009 Josh Coalson
-# Copyright (C) 2011-2022 Xiph.Org Foundation
+# Copyright (C) 2011-2023 Xiph.Org Foundation
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/src/test_libFLAC++/decoders.cpp b/src/test_libFLAC++/decoders.cpp
index 59b746a1..9f375f34 100644
--- a/src/test_libFLAC++/decoders.cpp
+++ b/src/test_libFLAC++/decoders.cpp
@@ -1,6 +1,6 @@
/* test_libFLAC++ - Unit tester for libFLAC++
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/test_libFLAC++/decoders.h b/src/test_libFLAC++/decoders.h
index dad7cfad..4bbce132 100644
--- a/src/test_libFLAC++/decoders.h
+++ b/src/test_libFLAC++/decoders.h
@@ -1,6 +1,6 @@
/* test_libFLAC++ - Unit tester for libFLAC++
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/test_libFLAC++/encoders.cpp b/src/test_libFLAC++/encoders.cpp
index dd3d1106..0e356afe 100644
--- a/src/test_libFLAC++/encoders.cpp
+++ b/src/test_libFLAC++/encoders.cpp
@@ -1,6 +1,6 @@
/* test_libFLAC++ - Unit tester for libFLAC++
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/test_libFLAC++/encoders.h b/src/test_libFLAC++/encoders.h
index c03cbc50..9da415c5 100644
--- a/src/test_libFLAC++/encoders.h
+++ b/src/test_libFLAC++/encoders.h
@@ -1,6 +1,6 @@
/* test_libFLAC++ - Unit tester for libFLAC++
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/test_libFLAC++/main.cpp b/src/test_libFLAC++/main.cpp
index 5496250f..7183def7 100644
--- a/src/test_libFLAC++/main.cpp
+++ b/src/test_libFLAC++/main.cpp
@@ -1,6 +1,6 @@
/* test_libFLAC++ - Unit tester for libFLAC++
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/test_libFLAC++/metadata.cpp b/src/test_libFLAC++/metadata.cpp
index c4d9bfb0..a31031b6 100644
--- a/src/test_libFLAC++/metadata.cpp
+++ b/src/test_libFLAC++/metadata.cpp
@@ -1,6 +1,6 @@
/* test_libFLAC++ - Unit tester for libFLAC++
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/test_libFLAC++/metadata.h b/src/test_libFLAC++/metadata.h
index 7c8ac92b..8c45bc0a 100644
--- a/src/test_libFLAC++/metadata.h
+++ b/src/test_libFLAC++/metadata.h
@@ -1,6 +1,6 @@
/* test_libFLAC++ - Unit tester for libFLAC++
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/test_libFLAC++/metadata_manip.cpp b/src/test_libFLAC++/metadata_manip.cpp
index 95fe153f..5d395dbd 100644
--- a/src/test_libFLAC++/metadata_manip.cpp
+++ b/src/test_libFLAC++/metadata_manip.cpp
@@ -1,6 +1,6 @@
/* test_libFLAC++ - Unit tester for libFLAC++
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/test_libFLAC++/metadata_object.cpp b/src/test_libFLAC++/metadata_object.cpp
index ba7fbe50..ab4cfbfe 100644
--- a/src/test_libFLAC++/metadata_object.cpp
+++ b/src/test_libFLAC++/metadata_object.cpp
@@ -1,6 +1,6 @@
/* test_libFLAC++ - Unit tester for libFLAC++
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/test_libFLAC/Makefile.am b/src/test_libFLAC/Makefile.am
index bbbf6c6c..c77f87e8 100644
--- a/src/test_libFLAC/Makefile.am
+++ b/src/test_libFLAC/Makefile.am
@@ -1,6 +1,6 @@
# test_libFLAC - Unit tester for libFLAC
# Copyright (C) 2000-2009 Josh Coalson
-# Copyright (C) 2011-2022 Xiph.Org Foundation
+# Copyright (C) 2011-2023 Xiph.Org Foundation
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/src/test_libFLAC/bitreader.c b/src/test_libFLAC/bitreader.c
index bae98675..d40bd1f2 100644
--- a/src/test_libFLAC/bitreader.c
+++ b/src/test_libFLAC/bitreader.c
@@ -1,6 +1,6 @@
/* test_libFLAC - Unit tester for libFLAC
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/test_libFLAC/bitreader.h b/src/test_libFLAC/bitreader.h
index 1d7c90bc..f497acf6 100644
--- a/src/test_libFLAC/bitreader.h
+++ b/src/test_libFLAC/bitreader.h
@@ -1,6 +1,6 @@
/* test_libFLAC - Unit tester for libFLAC
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/test_libFLAC/bitwriter.c b/src/test_libFLAC/bitwriter.c
index f3466139..0aafff2f 100644
--- a/src/test_libFLAC/bitwriter.c
+++ b/src/test_libFLAC/bitwriter.c
@@ -1,6 +1,6 @@
/* test_libFLAC - Unit tester for libFLAC
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/test_libFLAC/bitwriter.h b/src/test_libFLAC/bitwriter.h
index 1e081cf6..9b6a8248 100644
--- a/src/test_libFLAC/bitwriter.h
+++ b/src/test_libFLAC/bitwriter.h
@@ -1,6 +1,6 @@
/* test_libFLAC - Unit tester for libFLAC
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/test_libFLAC/crc.c b/src/test_libFLAC/crc.c
index 03d9adaf..8b876711 100644
--- a/src/test_libFLAC/crc.c
+++ b/src/test_libFLAC/crc.c
@@ -1,5 +1,5 @@
/* test_libFLAC - Unit tester for libFLAC
- * Copyright (C) 2014-2022 Xiph.Org Foundation
+ * Copyright (C) 2014-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/test_libFLAC/crc.h b/src/test_libFLAC/crc.h
index b4e35276..11523cd8 100644
--- a/src/test_libFLAC/crc.h
+++ b/src/test_libFLAC/crc.h
@@ -1,5 +1,5 @@
/* test_libFLAC - Unit tester for libFLAC
- * Copyright (C) 2014-2022 Xiph.Org Foundation
+ * Copyright (C) 2014-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/test_libFLAC/decoders.c b/src/test_libFLAC/decoders.c
index c353e6fc..ae114ced 100644
--- a/src/test_libFLAC/decoders.c
+++ b/src/test_libFLAC/decoders.c
@@ -1,6 +1,6 @@
/* test_libFLAC - Unit tester for libFLAC
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/test_libFLAC/decoders.h b/src/test_libFLAC/decoders.h
index d77ae80d..431eb176 100644
--- a/src/test_libFLAC/decoders.h
+++ b/src/test_libFLAC/decoders.h
@@ -1,6 +1,6 @@
/* test_libFLAC - Unit tester for libFLAC
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/test_libFLAC/encoders.c b/src/test_libFLAC/encoders.c
index 7f6e5ff7..d3fd39dd 100644
--- a/src/test_libFLAC/encoders.c
+++ b/src/test_libFLAC/encoders.c
@@ -1,6 +1,6 @@
/* test_libFLAC - Unit tester for libFLAC
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/test_libFLAC/encoders.h b/src/test_libFLAC/encoders.h
index 882b34ac..7bdcaf5c 100644
--- a/src/test_libFLAC/encoders.h
+++ b/src/test_libFLAC/encoders.h
@@ -1,6 +1,6 @@
/* test_libFLAC - Unit tester for libFLAC
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/test_libFLAC/endswap.c b/src/test_libFLAC/endswap.c
index d569197d..808f81f3 100644
--- a/src/test_libFLAC/endswap.c
+++ b/src/test_libFLAC/endswap.c
@@ -1,5 +1,5 @@
/* test_libFLAC - Unit tester for libFLAC
- * Copyright (C) 2014-2022 Xiph.Org Foundation
+ * Copyright (C) 2014-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/test_libFLAC/endswap.h b/src/test_libFLAC/endswap.h
index 1814f628..952b17f0 100644
--- a/src/test_libFLAC/endswap.h
+++ b/src/test_libFLAC/endswap.h
@@ -1,5 +1,5 @@
/* test_libFLAC - Unit tester for libFLAC
- * Copyright (C) 2014-2022 Xiph.Org Foundation
+ * Copyright (C) 2014-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/test_libFLAC/format.c b/src/test_libFLAC/format.c
index 4071b1c4..c5e8bf27 100644
--- a/src/test_libFLAC/format.c
+++ b/src/test_libFLAC/format.c
@@ -1,6 +1,6 @@
/* test_libFLAC - Unit tester for libFLAC
* Copyright (C) 2004-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -33,7 +33,7 @@ static struct {
FLAC__bool valid;
FLAC__bool subset;
} SAMPLE_RATES[] = {
- { 0 , false, false },
+ { 0 , true , true },
{ 1 , true , true },
{ 9 , true , true },
{ 10 , true , true },
diff --git a/src/test_libFLAC/format.h b/src/test_libFLAC/format.h
index a37b675c..f78d55df 100644
--- a/src/test_libFLAC/format.h
+++ b/src/test_libFLAC/format.h
@@ -1,6 +1,6 @@
/* test_libFLAC - Unit tester for libFLAC
* Copyright (C) 2004-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/test_libFLAC/main.c b/src/test_libFLAC/main.c
index f7f3fe52..a4be0fee 100644
--- a/src/test_libFLAC/main.c
+++ b/src/test_libFLAC/main.c
@@ -1,6 +1,6 @@
/* test_libFLAC - Unit tester for libFLAC
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/test_libFLAC/md5.c b/src/test_libFLAC/md5.c
index 39684e56..bac4a74a 100644
--- a/src/test_libFLAC/md5.c
+++ b/src/test_libFLAC/md5.c
@@ -1,5 +1,5 @@
/* test_libFLAC - Unit tester for libFLAC
- * Copyright (C) 2014-2022 Xiph.Org Foundation
+ * Copyright (C) 2014-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/test_libFLAC/md5.h b/src/test_libFLAC/md5.h
index f1aff45f..6863268d 100644
--- a/src/test_libFLAC/md5.h
+++ b/src/test_libFLAC/md5.h
@@ -1,5 +1,5 @@
/* test_libFLAC - Unit tester for libFLAC
- * Copyright (C) 2014-2022 Xiph.Org Foundation
+ * Copyright (C) 2014-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/test_libFLAC/metadata.c b/src/test_libFLAC/metadata.c
index 143ded46..0347f6d2 100644
--- a/src/test_libFLAC/metadata.c
+++ b/src/test_libFLAC/metadata.c
@@ -1,6 +1,6 @@
/* test_libFLAC - Unit tester for libFLAC
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/test_libFLAC/metadata.h b/src/test_libFLAC/metadata.h
index 809e9801..51bdf7aa 100644
--- a/src/test_libFLAC/metadata.h
+++ b/src/test_libFLAC/metadata.h
@@ -1,6 +1,6 @@
/* test_libFLAC - Unit tester for libFLAC
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/test_libFLAC/metadata_manip.c b/src/test_libFLAC/metadata_manip.c
index 52ce3a75..334dc3ae 100644
--- a/src/test_libFLAC/metadata_manip.c
+++ b/src/test_libFLAC/metadata_manip.c
@@ -1,6 +1,6 @@
/* test_libFLAC - Unit tester for libFLAC
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/test_libFLAC/metadata_object.c b/src/test_libFLAC/metadata_object.c
index a538480c..ea6b69fd 100644
--- a/src/test_libFLAC/metadata_object.c
+++ b/src/test_libFLAC/metadata_object.c
@@ -1,6 +1,6 @@
/* test_libFLAC - Unit tester for libFLAC
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/test_libs_common/Makefile.am b/src/test_libs_common/Makefile.am
index 667734de..30e1f157 100644
--- a/src/test_libs_common/Makefile.am
+++ b/src/test_libs_common/Makefile.am
@@ -1,6 +1,6 @@
# test_libs_common - Common code to library unit tests
# Copyright (C) 2000-2009 Josh Coalson
-# Copyright (C) 2011-2022 Xiph.Org Foundation
+# Copyright (C) 2011-2023 Xiph.Org Foundation
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/src/test_libs_common/file_utils_flac.c b/src/test_libs_common/file_utils_flac.c
index 4df6a5ff..3cc8c308 100644
--- a/src/test_libs_common/file_utils_flac.c
+++ b/src/test_libs_common/file_utils_flac.c
@@ -1,6 +1,6 @@
/* test_libFLAC - Unit tester for libFLAC
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/test_libs_common/metadata_utils.c b/src/test_libs_common/metadata_utils.c
index 38fe2aa8..929ca639 100644
--- a/src/test_libs_common/metadata_utils.c
+++ b/src/test_libs_common/metadata_utils.c
@@ -1,6 +1,6 @@
/* test_libFLAC - Unit tester for libFLAC
* Copyright (C) 2002-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -511,7 +511,8 @@ void mutils__init_metadata_blocks(
vorbiscomment->data.vorbis_comment.comments[0].entry = malloc_or_die_(5+1);
memcpy(vorbiscomment->data.vorbis_comment.comments[0].entry, "ab=cd", 5+1);
vorbiscomment->data.vorbis_comment.comments[1].length = 0;
- vorbiscomment->data.vorbis_comment.comments[1].entry = 0;
+ vorbiscomment->data.vorbis_comment.comments[1].entry = malloc_or_die_(1);
+ vorbiscomment->data.vorbis_comment.comments[1].entry[0] = '\0';
}
cuesheet->is_last = false;
diff --git a/src/test_seeking/Makefile.am b/src/test_seeking/Makefile.am
index d0ceca7b..9c9b8da8 100644
--- a/src/test_seeking/Makefile.am
+++ b/src/test_seeking/Makefile.am
@@ -1,6 +1,6 @@
# test_seeking - Seeking tester for libFLAC
# Copyright (C) 2004-2009 Josh Coalson
-# Copyright (C) 2011-2022 Xiph.Org Foundation
+# Copyright (C) 2011-2023 Xiph.Org Foundation
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/src/test_seeking/main.c b/src/test_seeking/main.c
index be50cedd..16ab9f40 100644
--- a/src/test_seeking/main.c
+++ b/src/test_seeking/main.c
@@ -1,6 +1,6 @@
/* test_seeking - Seeking tester for libFLAC
* Copyright (C) 2004-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/test_streams/Makefile.am b/src/test_streams/Makefile.am
index 5dc4a630..9aa4b025 100644
--- a/src/test_streams/Makefile.am
+++ b/src/test_streams/Makefile.am
@@ -1,6 +1,6 @@
# test_streams - Simple test pattern generator
# Copyright (C) 2000-2009 Josh Coalson
-# Copyright (C) 2011-2022 Xiph.Org Foundation
+# Copyright (C) 2011-2023 Xiph.Org Foundation
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/src/test_streams/main.c b/src/test_streams/main.c
index 886b0249..466bf8ef 100644
--- a/src/test_streams/main.c
+++ b/src/test_streams/main.c
@@ -1,6 +1,6 @@
/* test_streams - Simple test pattern generator
* Copyright (C) 2000-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/utils/Makefile.am b/src/utils/Makefile.am
index d609529a..5207b13c 100644
--- a/src/utils/Makefile.am
+++ b/src/utils/Makefile.am
@@ -1,6 +1,6 @@
# FLAC - Free Lossless Audio Codec
# Copyright (C) 2001-2009 Josh Coalson
-# Copyright (C) 2011-2022 Xiph.Org Foundation
+# Copyright (C) 2011-2023 Xiph.Org Foundation
#
# This file is part the FLAC project. FLAC is comprised of several
# components distributed under different licenses. The codec libraries
diff --git a/src/utils/flacdiff/Makefile.am b/src/utils/flacdiff/Makefile.am
index 2186bff5..b181d980 100644
--- a/src/utils/flacdiff/Makefile.am
+++ b/src/utils/flacdiff/Makefile.am
@@ -1,6 +1,6 @@
# flacdiff - Displays where two FLAC streams differ
# Copyright (C) 2007-2009 Josh Coalson
-# Copyright (C) 2011-2022 Xiph.Org Foundation
+# Copyright (C) 2011-2023 Xiph.Org Foundation
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/src/utils/flacdiff/main.cpp b/src/utils/flacdiff/main.cpp
index 90322a13..358fe047 100644
--- a/src/utils/flacdiff/main.cpp
+++ b/src/utils/flacdiff/main.cpp
@@ -1,6 +1,6 @@
/* flacdiff - Displays where two FLAC streams differ
* Copyright (C) 2007-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/src/utils/flactimer/Makefile.am b/src/utils/flactimer/Makefile.am
index cd0de169..07378630 100644
--- a/src/utils/flactimer/Makefile.am
+++ b/src/utils/flactimer/Makefile.am
@@ -1,6 +1,6 @@
# flactimer - Runs a command and prints timing information
# Copyright (C) 2007-2009 Josh Coalson
-# Copyright (C) 2011-2022 Xiph.Org Foundation
+# Copyright (C) 2011-2023 Xiph.Org Foundation
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/src/utils/flactimer/main.cpp b/src/utils/flactimer/main.cpp
index dbce469e..120a37ff 100644
--- a/src/utils/flactimer/main.cpp
+++ b/src/utils/flactimer/main.cpp
@@ -1,6 +1,6 @@
/* flactimer - Runs a command and prints timing information
* Copyright (C) 2007-2009 Josh Coalson
- * Copyright (C) 2011-2022 Xiph.Org Foundation
+ * Copyright (C) 2011-2023 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License