patch-oggenc_audio_c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. $OpenBSD: patch-oggenc_audio_c,v 1.3 2015/09/10 21:03:12 naddy Exp $
  2. CVE-2015-6749 (aiff_open buffer overflow)
  3. https://trac.xiph.org/attachment/ticket/2212/0001-oggenc-Fix-large-alloca-on-bad-AIFF-input.patch
  4. CVE-2014-9638 (division by zero)
  5. CVE-2014-9639 (channel integer overflow)
  6. http://pkgs.fedoraproject.org/cgit/vorbis-tools.git/tree/vorbis-tools-1.4.0-CVE-2014-9638-CVE-2014-9639.patch
  7. --- oggenc/audio.c.orig Wed Mar 24 09:27:14 2010
  8. +++ oggenc/audio.c Thu Sep 10 22:48:38 2015
  9. @@ -13,6 +13,7 @@
  10. #include <config.h>
  11. #endif
  12. +#include <limits.h>
  13. #include <stdlib.h>
  14. #include <stdio.h>
  15. #include <string.h>
  16. @@ -245,12 +246,13 @@ static int aiff_permute_matrix[6][6] =
  17. int aiff_open(FILE *in, oe_enc_opt *opt, unsigned char *buf, int buflen)
  18. {
  19. int aifc; /* AIFC or AIFF? */
  20. - unsigned int len;
  21. - unsigned char *buffer;
  22. + unsigned int len, readlen;
  23. + unsigned char buffer[22];
  24. unsigned char buf2[8];
  25. aiff_fmt format;
  26. aifffile *aiff = malloc(sizeof(aifffile));
  27. int i;
  28. + long channels;
  29. if(buf[11]=='C')
  30. aifc=1;
  31. @@ -269,19 +271,25 @@ int aiff_open(FILE *in, oe_enc_opt *opt, unsigned char
  32. return 0; /* Weird common chunk */
  33. }
  34. - buffer = alloca(len);
  35. -
  36. - if(fread(buffer,1,len,in) < len)
  37. + readlen = len < sizeof(buffer) ? len : sizeof(buffer);
  38. + if(fread(buffer,1,readlen,in) < readlen ||
  39. + (len > readlen && !seek_forward(in, len-readlen)))
  40. {
  41. fprintf(stderr, _("Warning: Unexpected EOF in reading AIFF header\n"));
  42. return 0;
  43. }
  44. - format.channels = READ_U16_BE(buffer);
  45. + format.channels = channels = READ_U16_BE(buffer);
  46. format.totalframes = READ_U32_BE(buffer+2);
  47. format.samplesize = READ_U16_BE(buffer+6);
  48. format.rate = (int)read_IEEE80(buffer+8);
  49. + if(channels <= 0L || SHRT_MAX < channels)
  50. + {
  51. + fprintf(stderr, _("Warning: Unsupported count of channels in AIFF header\n"));
  52. + return 0;
  53. + }
  54. +
  55. aiff->bigendian = 1;
  56. if(aifc)
  57. @@ -412,6 +420,7 @@ int wav_open(FILE *in, oe_enc_opt *opt, unsigned char
  58. wav_fmt format;
  59. wavfile *wav = malloc(sizeof(wavfile));
  60. int i;
  61. + long channels;
  62. /* Ok. At this point, we know we have a WAV file. Now we have to detect
  63. * whether we support the subtype, and we have to find the actual data
  64. @@ -449,11 +458,17 @@ int wav_open(FILE *in, oe_enc_opt *opt, unsigned char
  65. }
  66. format.format = READ_U16_LE(buf);
  67. - format.channels = READ_U16_LE(buf+2);
  68. + format.channels = channels = READ_U16_LE(buf+2);
  69. format.samplerate = READ_U32_LE(buf+4);
  70. format.bytespersec = READ_U32_LE(buf+8);
  71. format.align = READ_U16_LE(buf+12);
  72. format.samplesize = READ_U16_LE(buf+14);
  73. +
  74. + if(channels <= 0L || SHRT_MAX < channels)
  75. + {
  76. + fprintf(stderr, _("Warning: Unsupported count of channels in WAV header\n"));
  77. + return 0;
  78. + }
  79. if(format.format == -2) /* WAVE_FORMAT_EXTENSIBLE */
  80. {