summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMartijn van Beurden <mvanb1@gmail.com>2022-04-19 17:45:22 +0200
committerGitHub <noreply@github.com>2022-04-19 17:45:22 +0200
commit7385dac38317488e645c568e98c758039d4076ca (patch)
tree251bf497bf54148d3bf5865c04ff89cf715f1e91 /test
parent7406eabe1782c5c9c21f80d35c0da4e82f1d6b21 (diff)
downloadflac-7385dac38317488e645c568e98c758039d4076ca.tar.gz
Fix overflow of streaminfo total samples (github issue 237)
When writing a FLAC file with over 2^36 samples, the total samples entry in streaminfo will overflow and wrap around. Setting it to 0 (which means unknown number of samples) makes sure the decoder doesn't rely on this number Co-authored-by: Ralph Giles <giles@thaumas.net>
Diffstat (limited to 'test')
-rwxr-xr-xtest/test_flac.sh23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/test_flac.sh b/test/test_flac.sh
index cd17b164..369d23b4 100755
--- a/test/test_flac.sh
+++ b/test/test_flac.sh
@@ -1249,6 +1249,29 @@ flac2flac input-SCVA.flac case04e "--no-padding -S 5x"
# case 04f: on file with SEEKTABLE block and size-changing option specified, drop existing SEEKTABLE, new SEEKTABLE with default points
#(already covered by case03c)
+test_total_samples_overflow ()
+{
+ total_samples=$1
+ expected_stored_total_samples=$2
+ echo $ECHO_N "total_samples overflow test (samples=$total_samples) encode... " $ECHO_C
+ head -c $total_samples /dev/zero | run_flac --force --verify --sign=signed --sample-rate=96000 -b 16384 --channels=1 --endian=little --bps=8 -o big-$total_samples.flac - || die "ERROR"
+ echo $ECHO_N "decode... " $ECHO_C
+ run_flac -t big-$total_samples.flac || die "ERROR"
+ echo $ECHO_N "check... " $ECHO_C
+ run_metaflac --show-total-samples big-$total_samples.flac > big-$total_samples.cmp1
+ echo $expected_stored_total_samples > big-$total_samples.cmp2
+ diff -q -w big-$total_samples.cmp1 big-$total_samples.cmp2 || die "ERROR"
+ echo "OK"
+ rm -f big-$total_samples.flac big-$total_samples.cmp1 big-$total_samples.cmp2
+}
+
+if [ "$FLAC__TEST_LEVEL" -gt 1 ] ; then
+ test_total_samples_overflow 68719476735 68719476735
+ test_total_samples_overflow 68719476736 0
+ test_total_samples_overflow 68719476737 0
+fi
+
+
rm -f out.flac out.meta out1.meta
#@@@ when metaflac handles ogg flac, duplicate flac2flac tests here