Brad Bishop | 220d553 | 2018-08-14 00:59:39 +0100 | [diff] [blame] | 1 | From 2d54514a4f6437b67829717c05472d2e3300a258 Mon Sep 17 00:00:00 2001 |
| 2 | From: Fabian Greffrath <fabian@greffrath.com> |
| 3 | Date: Wed, 27 Sep 2017 14:46:17 +0200 |
| 4 | Subject: [PATCH] sfe_copy_data_fp: check value of "max" variable for being |
| 5 | normal |
| 6 | |
| 7 | and check elements of the data[] array for being finite. |
| 8 | |
| 9 | Both checks use functions provided by the <math.h> header as declared |
| 10 | by the C99 standard. |
| 11 | |
| 12 | Fixes #317 |
| 13 | CVE: CVE-2017-14245 |
| 14 | CVE: CVE-2017-14246 |
| 15 | |
| 16 | Upstream-Status: Backport [https://github.com/fabiangreffrath/libsndfile/commit/2d54514a4f6437b67829717c05472d2e3300a258] |
| 17 | |
| 18 | Signed-off-by: Fabian Greffrath <fabian@greffrath.com> |
| 19 | Signed-off-by: Jagadeesh Krishnanjanappa <jkrishnanjanappa@mvista.com> |
| 20 | --- |
| 21 | programs/common.c | 20 ++++++++++++++++---- |
| 22 | programs/common.h | 2 +- |
| 23 | programs/sndfile-convert.c | 6 +++++- |
| 24 | 3 files changed, 22 insertions(+), 6 deletions(-) |
| 25 | |
| 26 | diff --git a/programs/common.c b/programs/common.c |
| 27 | index a21e62c..a249a58 100644 |
| 28 | --- a/programs/common.c |
| 29 | +++ b/programs/common.c |
| 30 | @@ -36,6 +36,7 @@ |
| 31 | #include <string.h> |
| 32 | #include <ctype.h> |
| 33 | #include <stdint.h> |
| 34 | +#include <math.h> |
| 35 | |
| 36 | #include <sndfile.h> |
| 37 | |
| 38 | @@ -45,7 +46,7 @@ |
| 39 | |
| 40 | #define MIN(x, y) ((x) < (y) ? (x) : (y)) |
| 41 | |
| 42 | -void |
| 43 | +int |
| 44 | sfe_copy_data_fp (SNDFILE *outfile, SNDFILE *infile, int channels, int normalize) |
| 45 | { static double data [BUFFER_LEN], max ; |
| 46 | int frames, readcount, k ; |
| 47 | @@ -54,6 +55,8 @@ sfe_copy_data_fp (SNDFILE *outfile, SNDFILE *infile, int channels, int normalize |
| 48 | readcount = frames ; |
| 49 | |
| 50 | sf_command (infile, SFC_CALC_SIGNAL_MAX, &max, sizeof (max)) ; |
| 51 | + if (!isnormal (max)) /* neither zero, subnormal, infinite, nor NaN */ |
| 52 | + return 1 ; |
| 53 | |
| 54 | if (!normalize && max < 1.0) |
| 55 | { while (readcount > 0) |
| 56 | @@ -67,12 +70,16 @@ sfe_copy_data_fp (SNDFILE *outfile, SNDFILE *infile, int channels, int normalize |
| 57 | while (readcount > 0) |
| 58 | { readcount = sf_readf_double (infile, data, frames) ; |
| 59 | for (k = 0 ; k < readcount * channels ; k++) |
| 60 | - data [k] /= max ; |
| 61 | + { data [k] /= max ; |
| 62 | + |
| 63 | + if (!isfinite (data [k])) /* infinite or NaN */ |
| 64 | + return 1; |
| 65 | + } |
| 66 | sf_writef_double (outfile, data, readcount) ; |
| 67 | } ; |
| 68 | } ; |
| 69 | |
| 70 | - return ; |
| 71 | + return 0 ; |
| 72 | } /* sfe_copy_data_fp */ |
| 73 | |
| 74 | void |
| 75 | @@ -252,7 +259,12 @@ sfe_apply_metadata_changes (const char * filenames [2], const METADATA_INFO * in |
| 76 | |
| 77 | /* If the input file is not the same as the output file, copy the data. */ |
| 78 | if ((infileminor == SF_FORMAT_DOUBLE) || (infileminor == SF_FORMAT_FLOAT)) |
| 79 | - sfe_copy_data_fp (outfile, infile, sfinfo.channels, SF_FALSE) ; |
| 80 | + { if (sfe_copy_data_fp (outfile, infile, sfinfo.channels, SF_FALSE) != 0) |
| 81 | + { printf ("Error : Not able to decode input file '%s'\n", filenames [0]) ; |
| 82 | + error_code = 1 ; |
| 83 | + goto cleanup_exit ; |
| 84 | + } ; |
| 85 | + } |
| 86 | else |
| 87 | sfe_copy_data_int (outfile, infile, sfinfo.channels) ; |
| 88 | } ; |
| 89 | diff --git a/programs/common.h b/programs/common.h |
| 90 | index eda2d7d..986277e 100644 |
| 91 | --- a/programs/common.h |
| 92 | +++ b/programs/common.h |
| 93 | @@ -62,7 +62,7 @@ typedef SF_BROADCAST_INFO_VAR (2048) SF_BROADCAST_INFO_2K ; |
| 94 | |
| 95 | void sfe_apply_metadata_changes (const char * filenames [2], const METADATA_INFO * info) ; |
| 96 | |
| 97 | -void sfe_copy_data_fp (SNDFILE *outfile, SNDFILE *infile, int channels, int normalize) ; |
| 98 | +int sfe_copy_data_fp (SNDFILE *outfile, SNDFILE *infile, int channels, int normalize) ; |
| 99 | |
| 100 | void sfe_copy_data_int (SNDFILE *outfile, SNDFILE *infile, int channels) ; |
| 101 | |
| 102 | diff --git a/programs/sndfile-convert.c b/programs/sndfile-convert.c |
| 103 | index dff7f79..e6de593 100644 |
| 104 | --- a/programs/sndfile-convert.c |
| 105 | +++ b/programs/sndfile-convert.c |
| 106 | @@ -335,7 +335,11 @@ main (int argc, char * argv []) |
| 107 | || (outfileminor == SF_FORMAT_DOUBLE) || (outfileminor == SF_FORMAT_FLOAT) |
| 108 | || (infileminor == SF_FORMAT_DOUBLE) || (infileminor == SF_FORMAT_FLOAT) |
| 109 | || (infileminor == SF_FORMAT_VORBIS) || (outfileminor == SF_FORMAT_VORBIS)) |
| 110 | - sfe_copy_data_fp (outfile, infile, sfinfo.channels, normalize) ; |
| 111 | + { if (sfe_copy_data_fp (outfile, infile, sfinfo.channels, normalize) != 0) |
| 112 | + { printf ("Error : Not able to decode input file %s.\n", infilename) ; |
| 113 | + return 1 ; |
| 114 | + } ; |
| 115 | + } |
| 116 | else |
| 117 | sfe_copy_data_int (outfile, infile, sfinfo.channels) ; |
| 118 | |
| 119 | -- |
| 120 | 2.7.4 |
| 121 | |