diff --git a/src/common.c b/src/common.c index 3bf71471..7fd4454c 100644 --- a/src/common.c +++ b/src/common.c @@ -73,6 +73,10 @@ psf_bump_header_allocation (SF_PRIVATE * psf, sf_count_t needed) return 1 ; } ; + /* Always zero-out new header memory to avoid un-initializer memory accesses. */ + if (newlen > psf->header.len) + memset ((char *) ptr + psf->header.len, 0, newlen - psf->header.len) ; + psf->header.ptr = ptr ; psf->header.len = newlen ; return 0 ; diff --git a/src/float32.c b/src/float32.c index 100c1499..fd74b6d6 100644 --- a/src/float32.c +++ b/src/float32.c @@ -1,5 +1,5 @@ /* -** Copyright (C) 1999-2015 Erik de Castro Lopo +** Copyright (C) 1999-2017 Erik de Castro Lopo ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU Lesser General Public License as published by @@ -527,7 +527,7 @@ host_read_f2s (SF_PRIVATE *psf, short *ptr, sf_count_t len) /* Fix me : Need lef2s_array */ if (psf->data_endswap == SF_TRUE) - endswap_int_array (ubuf.ibuf, bufferlen) ; + endswap_int_array (ubuf.ibuf, readcount) ; convert (ubuf.fbuf, readcount, ptr + total, scale) ; total += readcount ; diff --git a/src/sndfile.hh b/src/sndfile.hh index 0e1c1c20..b0dbc443 100644 --- a/src/sndfile.hh +++ b/src/sndfile.hh @@ -1,5 +1,5 @@ /* -** Copyright (C) 2005-2012 Erik de Castro Lopo +** Copyright (C) 2005-2017 Erik de Castro Lopo ** ** All rights reserved. ** diff --git a/tests/checksum_test.c b/tests/checksum_test.c index 747f2339..4b37b3d3 100644 --- a/tests/checksum_test.c +++ b/tests/checksum_test.c @@ -1,5 +1,5 @@ /* -** Copyright (C) 2008-2015 Erik de Castro Lopo +** Copyright (C) 2008-2017 Erik de Castro Lopo ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by @@ -87,6 +87,7 @@ checksum_test (const CHECKSUM * cksum) print_test_name (__func__, cksum->enc_name) ; + memset (&info, 0, sizeof (info)) ; info.format = cksum->enc_fmt ; info.channels = 1 ; info.samplerate = SAMPLE_RATE ; diff --git a/tests/command_test.c b/tests/command_test.c index 10ddd5c9..6109780d 100644 --- a/tests/command_test.c +++ b/tests/command_test.c @@ -1,5 +1,5 @@ /* -** Copyright (C) 2001-2016 Erik de Castro Lopo +** Copyright (C) 2001-2017 Erik de Castro Lopo ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by @@ -1053,6 +1053,7 @@ broadcast_test (const char *filename, int filetype) print_test_name ("broadcast_test", filename) ; + memset (&sfinfo, 0, sizeof (sfinfo)) ; sfinfo.samplerate = 11025 ; sfinfo.format = filetype ; sfinfo.channels = 1 ; @@ -1415,6 +1416,7 @@ cart_test (const char *filename, int filetype) print_test_name ("cart_test", filename) ; + memset (&sfinfo, 0, sizeof (sfinfo)) ; sfinfo.samplerate = 11025 ; sfinfo.format = filetype ; sfinfo.channels = 1 ; diff --git a/tests/floating_point_test.tpl b/tests/floating_point_test.tpl index f026f4cd..74b5a7e5 100644 --- a/tests/floating_point_test.tpl +++ b/tests/floating_point_test.tpl @@ -1,6 +1,6 @@ [+ AutoGen5 template c +] /* -** Copyright (C) 1999-2016 Erik de Castro Lopo +** Copyright (C) 1999-2017 Erik de Castro Lopo ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by @@ -207,6 +207,7 @@ float_scaled_test (const char *filename, int allow_exit, int replace_float, int gen_windowed_sine_float (float_data, DFT_DATA_LENGTH, 0.9999) ; + memset (&sfinfo, 0, sizeof (sfinfo)) ; sfinfo.samplerate = SAMPLE_RATE ; sfinfo.frames = DFT_DATA_LENGTH ; sfinfo.channels = 1 ; @@ -259,6 +260,7 @@ double_scaled_test (const char *filename, int allow_exit, int replace_float, int gen_windowed_sine_double (double_data, DFT_DATA_LENGTH, 0.9999) ; + memset (&sfinfo, 0, sizeof (sfinfo)) ; sfinfo.samplerate = SAMPLE_RATE ; sfinfo.frames = DFT_DATA_LENGTH ; sfinfo.channels = 1 ; @@ -316,6 +318,7 @@ static void gen_windowed_sine_[+ (get "float_name") +] ([+ (get "float_name") +]_data, ARRAY_LEN ([+ (get "float_name") +]_data), 0.9999) ; + memset (&sfinfo, 0, sizeof (sfinfo)) ; sfinfo.samplerate = SAMPLE_RATE ; sfinfo.frames = ARRAY_LEN ([+ (get "int_name") +]_data) ; sfinfo.channels = 1 ; diff --git a/tests/format_check_test.c b/tests/format_check_test.c index b9cc02e2..98bdbb64 100644 --- a/tests/format_check_test.c +++ b/tests/format_check_test.c @@ -1,5 +1,5 @@ /* -** Copyright (C) 2011 Erik de Castro Lopo +** Copyright (C) 2011-2017 Erik de Castro Lopo ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by @@ -102,6 +102,7 @@ format_combo_test (void) char filename [128] ; int subtype_is_valid, check_is_valid ; + memset (&info, 0, sizeof (info)) ; memset (&subtype_fmt_info, 0, sizeof (subtype_fmt_info)) ; subtype_fmt_info.format = codec ; subtype_is_valid = sf_command (NULL, SFC_GET_FORMAT_SUBTYPE, &subtype_fmt_info, sizeof (subtype_fmt_info)) == 0 ; diff --git a/tests/header_test.tpl b/tests/header_test.tpl index 6545bb49..e8a2b995 100644 --- a/tests/header_test.tpl +++ b/tests/header_test.tpl @@ -1,6 +1,6 @@ [+ AutoGen5 template c +] /* -** Copyright (C) 2001-2012 Erik de Castro Lopo +** Copyright (C) 2001-2017 Erik de Castro Lopo ** ** This program is free software ; you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by @@ -247,10 +247,10 @@ update_header_sub (const char *filename, int typemajor, int write_mode) SF_INFO sfinfo ; int k ; + memset (&sfinfo, 0, sizeof (sfinfo)) ; sfinfo.samplerate = 44100 ; sfinfo.format = (typemajor | SF_FORMAT_PCM_16) ; sfinfo.channels = 1 ; - sfinfo.frames = 0 ; outfile = test_open_file_or_die (filename, write_mode, &sfinfo, SF_TRUE, __LINE__) ; @@ -340,6 +340,7 @@ update_seek_[+ (get "name") +]_test (const char *filename, int filetype) memset (buffer, 0, sizeof (buffer)) ; /* Create sound outfile with no data. */ + memset (&sfinfo, 0, sizeof (sfinfo)) ; sfinfo.format = filetype | [+ (get "format") +] ; sfinfo.samplerate = 48000 ; sfinfo.channels = 2 ; @@ -450,6 +451,7 @@ extra_header_test (const char *filename, int filetype) print_test_name ("extra_header_test", filename) ; + memset (&sfinfo, 0, sizeof (sfinfo)) ; sfinfo.samplerate = 44100 ; sfinfo.format = (filetype | SF_FORMAT_PCM_16) ; sfinfo.channels = 1 ; diff --git a/tests/pipe_test.tpl b/tests/pipe_test.tpl index 1bc1f436..5e915a26 100644 --- a/tests/pipe_test.tpl +++ b/tests/pipe_test.tpl @@ -1,6 +1,6 @@ [+ AutoGen5 template c +] /* -** Copyright (C) 2001-2012 Erik de Castro Lopo +** Copyright (C) 2001-2017 Erik de Castro Lopo ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by @@ -129,6 +129,7 @@ pipe_read_test (int filetype, const char *ext) snprintf (filename, sizeof (filename), "pipe_in.%s", ext) ; print_test_name ("pipe_read_test", filename) ; + memset (&sfinfo, 0, sizeof (sfinfo)) ; sfinfo.format = filetype | SF_FORMAT_PCM_16 ; sfinfo.channels = 1 ; sfinfo.samplerate = 44100 ; @@ -331,6 +332,7 @@ pipe_test_others (FILETYPE* list1, FILETYPE* list2) SF_INFO sfinfo ; int retval ; + memset (&sfinfo, 0, sizeof (sfinfo)) ; sfinfo.format = info.format | SF_FORMAT_PCM_16 ; sfinfo.channels = 1 ; sfinfo.samplerate = 44100 ; diff --git a/tests/utils.tpl b/tests/utils.tpl index 310a69a4..5f13ff4d 100644 --- a/tests/utils.tpl +++ b/tests/utils.tpl @@ -1,6 +1,6 @@ [+ AutoGen5 template h c +] /* -** Copyright (C) 2002-2016 Erik de Castro Lopo +** Copyright (C) 2002-2017 Erik de Castro Lopo ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by @@ -239,6 +239,7 @@ create_short_sndfile (const char *filename, int format, int channels) SNDFILE *file ; SF_INFO sfinfo ; + memset (&sfinfo, 0, sizeof (sfinfo)) ; sfinfo.samplerate = 44100 ; sfinfo.channels = channels ; sfinfo.format = format ;