CVE-2017-14245-14246.patch 4.0 KB

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