diff --git a/0004-modify-error-value-for-Win32-file-handle.patch b/0004-modify-error-value-for-Win32-file-handle.patch new file mode 100644 index 0000000000000000000000000000000000000000..5ef0b43d4308fc51dd73e7b27d248093d94eaf56 --- /dev/null +++ b/0004-modify-error-value-for-Win32-file-handle.patch @@ -0,0 +1,148 @@ +From 3f8343ccdc1c02ee4969eac9a056fd1999544522 Mon Sep 17 00:00:00 2001 +From: ctl-ly +Date: Thu, 29 Dec 2022 14:48:22 +0800 +Subject: [PATCH] Use proper error value for Win32 file handle +The error value for Win32 file handle shoule be INVALID_HANDLE_VALUE, instead of NULL. Use proper error value for Win32 file handle + +--- + src/file_io.c | 37 ++++++++++++++----------------------- + 1 file changed, 14 insertions(+), 23 deletions(-) + +diff --git a/src/file_io.c b/src/file_io.c +index 9cd9379..9901e86 100644 +--- a/src/file_io.c ++++ b/src/file_io.c +@@ -620,7 +620,7 @@ psf_fopen (SF_PRIVATE *psf) + psf->error = 0 ; + psf->file.handle = psf_open_handle (&psf->file) ; + +- if (psf->file.handle == NULL) ++ if (psf->file.handle == INVALID_HANDLE_VALUE) + psf_log_syserr (psf, GetLastError ()) ; + + return psf->error ; +@@ -634,14 +634,14 @@ psf_fclose (SF_PRIVATE *psf) + return 0 ; + + if (psf->file.do_not_close_descriptor) +- { psf->file.handle = NULL ; ++ { psf->file.handle = INVALID_HANDLE_VALUE ; + return 0 ; + } ; + + if ((retval = psf_close_handle (psf->file.handle)) == -1) + psf_log_syserr (psf, GetLastError ()) ; + +- psf->file.handle = NULL ; ++ psf->file.handle = INVALID_HANDLE_VALUE ; + + return retval ; + } /* psf_fclose */ +@@ -649,13 +649,13 @@ psf_fclose (SF_PRIVATE *psf) + /* USE_WINDOWS_API */ int + psf_open_rsrc (SF_PRIVATE *psf) + { +- if (psf->rsrc.handle != NULL) ++ if (psf->rsrc.handle != INVALID_HANDLE_VALUE) + return 0 ; + + /* Test for MacOSX style resource fork on HPFS or HPFS+ filesystems. */ + snprintf (psf->rsrc.path.c, sizeof (psf->rsrc.path.c), "%s/rsrc", psf->file.path.c) ; + psf->error = SFE_NO_ERROR ; +- if ((psf->rsrc.handle = psf_open_handle (&psf->rsrc)) != NULL) ++ if ((psf->rsrc.handle = psf_open_handle (&psf->rsrc)) != INVALID_HANDLE_VALUE) + { psf->rsrclength = psf_get_filelen_handle (psf->rsrc.handle) ; + return SFE_NO_ERROR ; + } ; +@@ -666,7 +666,7 @@ psf_open_rsrc (SF_PRIVATE *psf) + */ + snprintf (psf->rsrc.path.c, sizeof (psf->rsrc.path.c), "%s._%s", psf->file.dir.c, psf->file.name.c) ; + psf->error = SFE_NO_ERROR ; +- if ((psf->rsrc.handle = psf_open_handle (&psf->rsrc)) != NULL) ++ if ((psf->rsrc.handle = psf_open_handle (&psf->rsrc)) != INVALID_HANDLE_VALUE) + { psf->rsrclength = psf_get_filelen_handle (psf->rsrc.handle) ; + return SFE_NO_ERROR ; + } ; +@@ -677,17 +677,15 @@ psf_open_rsrc (SF_PRIVATE *psf) + */ + snprintf (psf->rsrc.path.c, sizeof (psf->rsrc.path.c), "%s.AppleDouble/%s", psf->file.dir.c, psf->file.name.c) ; + psf->error = SFE_NO_ERROR ; +- if ((psf->rsrc.handle = psf_open_handle (&psf->rsrc)) != NULL) ++ if ((psf->rsrc.handle = psf_open_handle (&psf->rsrc)) != INVALID_HANDLE_VALUE) + { psf->rsrclength = psf_get_filelen_handle (psf->rsrc.handle) ; + return SFE_NO_ERROR ; + } ; + + /* No resource file found. */ +- if (psf->rsrc.handle == NULL) ++ if (psf->rsrc.handle == INVALID_HANDLE_VALUE) + psf_log_syserr (psf, GetLastError ()) ; + +- psf->rsrc.handle = NULL ; +- + return psf->error ; + } /* psf_open_rsrc */ + +@@ -738,9 +736,9 @@ psf_get_filelen (SF_PRIVATE *psf) + + /* USE_WINDOWS_API */ void + psf_init_files (SF_PRIVATE *psf) +-{ psf->file.handle = NULL ; +- psf->rsrc.handle = NULL ; +- psf->file.hsaved = NULL ; ++{ psf->file.handle = INVALID_HANDLE_VALUE ; ++ psf->rsrc.handle = INVALID_HANDLE_VALUE ; ++ psf->file.hsaved = INVALID_HANDLE_VALUE ; + } /* psf_init_files */ + + /* USE_WINDOWS_API */ void +@@ -798,9 +796,6 @@ psf_open_handle (PSF_FILE * pfile) + + handle = CreateFile2 (pfile->path.wc, dwDesiredAccess, dwShareMode, dwCreationDistribution, &cfParams) ; + +- if (handle == INVALID_HANDLE_VALUE) +- return NULL ; +- + return handle ; + #else + if (pfile->use_wchar) +@@ -824,9 +819,6 @@ psf_open_handle (PSF_FILE * pfile) + NULL /* handle to file with attributes to copy */ + ) ; + +- if (handle == INVALID_HANDLE_VALUE) +- return NULL ; +- + return handle ; + #endif + } /* psf_open_handle */ +@@ -860,14 +852,14 @@ psf_log_syserr (SF_PRIVATE *psf, int error) + /* USE_WINDOWS_API */ int + psf_close_rsrc (SF_PRIVATE *psf) + { psf_close_handle (psf->rsrc.handle) ; +- psf->rsrc.handle = NULL ; ++ psf->rsrc.handle = INVALID_HANDLE_VALUE ; + return 0 ; + } /* psf_close_rsrc */ + + + /* USE_WINDOWS_API */ int + psf_set_stdio (SF_PRIVATE *psf) +-{ HANDLE handle = NULL ; ++{ HANDLE handle = INVALID_HANDLE_VALUE ; + int error = 0 ; + + switch (psf->file.mode) +@@ -909,8 +901,7 @@ psf_set_file (SF_PRIVATE *psf, int fd) + + /* USE_WINDOWS_API */ int + psf_file_valid (SF_PRIVATE *psf) +-{ if (psf->file.handle == NULL) +- return SF_FALSE ; ++{ + if (psf->file.handle == INVALID_HANDLE_VALUE) + return SF_FALSE ; + return SF_TRUE ; +-- +2.27.0 + diff --git a/0005-Fix-NULL-file-handle-values.patch b/0005-Fix-NULL-file-handle-values.patch new file mode 100644 index 0000000000000000000000000000000000000000..a0b91c816eebbb7c095de88576cac8ce7af53805 --- /dev/null +++ b/0005-Fix-NULL-file-handle-values.patch @@ -0,0 +1,40 @@ +From 3101b92d50579d1ac7a3b06ad8e09a397938cdd3 Mon Sep 17 00:00:00 2001 +From: ctl-ly +Date: Thu, 29 Dec 2022 15:58:44 +0800 +Subject: [PATCH] Fix more NULL file handle values + +--- + src/file_io.c | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/src/file_io.c b/src/file_io.c +index 9901e86..046e027 100644 +--- a/src/file_io.c ++++ b/src/file_io.c +@@ -783,12 +783,12 @@ psf_open_handle (PSF_FILE * pfile) + break ; + + default : +- return NULL ; ++ return INVALID_HANDLE_VALUE ; + } ; + + #if defined (WINAPI_FAMILY_PARTITION) && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_SYSTEM) + if (!pfile->use_wchar) +- return NULL ; ++ return INVALID_HANDLE_VALUE ; + + CREATEFILE2_EXTENDED_PARAMETERS cfParams = { 0 } ; + cfParams.dwSize = sizeof (CREATEFILE2_EXTENDED_PARAMETERS) ; +@@ -1064,7 +1064,7 @@ psf_ftell (SF_PRIVATE *psf) + + /* USE_WINDOWS_API */ static int + psf_close_handle (HANDLE handle) +-{ if (handle == NULL) ++{ if (handle == INVALID_HANDLE_VALUE) + return 0 ; + + if (CloseHandle (handle) == 0) +-- +2.27.0 + diff --git a/0006-Fix-int-normalisation.patch b/0006-Fix-int-normalisation.patch new file mode 100644 index 0000000000000000000000000000000000000000..a839756e26bd90c4b747a5156afe9993edb42b1a --- /dev/null +++ b/0006-Fix-int-normalisation.patch @@ -0,0 +1,77 @@ +From 409bf1459f44ed23eef0020805aad66627168dcc Mon Sep 17 00:00:00 2001 +From: ctl-ly +Date: Fri, 30 Dec 2022 14:25:00 +0800 +Subject: [PATCH] Fix int normalisation when reading in floats with the + replacement reader + +--- + src/float32.c | 2 +- + tests/floating_point_test.tpl | 14 ++++++++------ + 2 files changed, 9 insertions(+), 7 deletions(-) + +diff --git a/src/float32.c b/src/float32.c +index a63413d..e8b0ade 100644 +--- a/src/float32.c ++++ b/src/float32.c +@@ -787,7 +787,7 @@ replace_read_f2i (SF_PRIVATE *psf, int *ptr, sf_count_t len) + float scale ; + + bufferlen = ARRAY_LEN (ubuf.fbuf) ; +- scale = (psf->float_int_mult == 0) ? 1.0 : 0x7FFF / psf->float_max ; ++ scale = (psf->float_int_mult == 0) ? 1.0 : 2147483648.0f / psf->float_max ; + + while (len > 0) + { if (len < bufferlen) +diff --git a/tests/floating_point_test.tpl b/tests/floating_point_test.tpl +index 7258fa2..bfa7a75 100644 +--- a/tests/floating_point_test.tpl ++++ b/tests/floating_point_test.tpl +@@ -42,7 +42,7 @@ static void float_scaled_test (const char *filename, int allow_exit, int replace + static void double_scaled_test (const char *filename, int allow_exit, int replace_float, int filetype, double target_snr) ; + + [+ FOR float_type +][+ FOR int_type +][+ FOR endian_type +-+]static void [+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +]_test (const char * filename) ; +++]static void [+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +]_test (const char * filename, int replace_float) ; + [+ ENDFOR endian_type +][+ ENDFOR int_type +][+ ENDFOR float_type + +] + +@@ -187,10 +187,10 @@ main (int argc, char *argv []) + + putchar ('\n') ; + /* Float int tests. */ +-[+ FOR float_type +][+ FOR int_type +][+ FOR endian_type +-+] [+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +]_test ("[+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +].au") ; +-[+ ENDFOR endian_type +][+ ENDFOR int_type +][+ ENDFOR float_type +-+] ++[+ FOR float_type +][+ FOR int_type +][+ FOR endian_type +] ++[+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +]_test ("[+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +].au", SF_FALSE) ; ++[+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +]_test ("[+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +]_replace.au", SF_TRUE) ; ++[+ ENDFOR endian_type +][+ ENDFOR int_type +][+ ENDFOR float_type +] + + return 0 ; + } /* main */ +@@ -311,7 +311,7 @@ double_scaled_test (const char *filename, int allow_exit, int replace_float, int + [+ FOR float_type +][+ FOR int_type +][+ FOR endian_type + +] + static void +-[+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +]_test (const char * filename) ++[+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +]_test (const char * filename, int replace_float) + { SNDFILE *file ; + SF_INFO sfinfo ; + int max ; +@@ -328,10 +328,12 @@ static void + sfinfo.format = [+ (get "end_type") +] | SF_FORMAT_AU | [+ (get "minor_type") +] ; + + file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; ++ sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ; + test_write_[+ (get "float_name") +]_or_die (file, 0, [+ (get "float_name") +]_data, ARRAY_LEN ([+ (get "float_name") +]_data), __LINE__) ; + sf_close (file) ; + + file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; ++ sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ; + + if (sfinfo.frames != ARRAY_LEN ([+ (get "float_name") +]_data)) + { printf ("\n\nLine %d: Incorrect number of frames in file (too short). (%" PRId64 " should be %d)\n", __LINE__, sfinfo.frames, DFT_DATA_LENGTH) ; +-- +2.27.0 + diff --git a/libsndfile.spec b/libsndfile.spec index fb29a5dbe6339b058f4bb7bbf89e15d40e6f9c43..33a78dca1997b307fa86a4e18e846ed6ec015af3 100644 --- a/libsndfile.spec +++ b/libsndfile.spec @@ -1,6 +1,6 @@ Name: libsndfile Version: 1.0.31 -Release: 3 +Release: 4 Summary: Library for reading and writing sound files License: LGPLv2+ and GPLv2+ and BSD URL: http://libsndfile.github.io/libsndfile @@ -8,11 +8,14 @@ Source0: https://github.com/libsndfile/libsndfile/releases/download/%{version}/% BuildRequires: alsa-lib-devel gcc gcc-c++ flac-devel BuildRequires: libogg-devel libtool libvorbis-devel pkgconfig -BuildRequires: sqlite-devel +BuildRequires: sqlite-devel autogen Patch1: 0001-CVE-2021-3246.patch Patch2: 0002-CVE-2021-4156.patch Patch3: 0003-Fix-memory-leak-in-caf_read_header.patch +Patch4: 0004-modify-error-value-for-Win32-file-handle.patch +Patch5: 0005-Fix-NULL-file-handle-values.patch +Patch6: 0006-Fix-int-normalisation.patch %description Libsndfile is a C library for reading and writing files containing @@ -117,6 +120,12 @@ LD_LIBRARY_PATH=$PWD/src/.libs make check %{_mandir}/man1/sndfile-salvage.1* %changelog +* Fri Dec 30 2022 liying - 1.0.31-4 +- Use proper error value for Win32 file handle +- Fix more NULL file handle values +- Fix int normalisation when reading in floats with the replacement reader +- Add BuildRequires autogen in spec + * Thu Dec 29 2022 liying - 1.0.31-3 - Marked unimplemented dither enums in the header file as such. - Fix typo