SDL-1.2.15-CVE-2019-7574-Fix-a-buffer-overread-in-IMA_ADPCM_dec.patch 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. From 9b2eee24768889378032077423cb6a3221a8ad18 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
  3. Date: Thu, 14 Feb 2019 15:41:47 +0100
  4. Subject: [PATCH] CVE-2019-7574: Fix a buffer overread in IMA_ADPCM_decode
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. If data chunk was shorter than expected based on a WAV format
  9. definition, IMA_ADPCM_decode() tried to read past the data chunk
  10. buffer. This patch fixes it.
  11. CVE-2019-7574
  12. https://bugzilla.libsdl.org/show_bug.cgi?id=4496
  13. Signed-off-by: Petr Písař <ppisar@redhat.com>
  14. ---
  15. src/audio/SDL_wave.c | 9 ++++++++-
  16. 1 file changed, 8 insertions(+), 1 deletion(-)
  17. diff --git a/src/audio/SDL_wave.c b/src/audio/SDL_wave.c
  18. index b6c49de..2968b3d 100644
  19. --- a/src/audio/SDL_wave.c
  20. +++ b/src/audio/SDL_wave.c
  21. @@ -334,7 +334,7 @@ static void Fill_IMA_ADPCM_block(Uint8 *decoded, Uint8 *encoded,
  22. static int IMA_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
  23. {
  24. struct IMA_ADPCM_decodestate *state;
  25. - Uint8 *freeable, *encoded, *decoded;
  26. + Uint8 *freeable, *encoded, *encoded_end, *decoded;
  27. Sint32 encoded_len, samplesleft;
  28. unsigned int c, channels;
  29. @@ -350,6 +350,7 @@ static int IMA_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
  30. /* Allocate the proper sized output buffer */
  31. encoded_len = *audio_len;
  32. encoded = *audio_buf;
  33. + encoded_end = encoded + encoded_len;
  34. freeable = *audio_buf;
  35. *audio_len = (encoded_len/IMA_ADPCM_state.wavefmt.blockalign) *
  36. IMA_ADPCM_state.wSamplesPerBlock*
  37. @@ -365,6 +366,7 @@ static int IMA_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
  38. while ( encoded_len >= IMA_ADPCM_state.wavefmt.blockalign ) {
  39. /* Grab the initial information for this block */
  40. for ( c=0; c<channels; ++c ) {
  41. + if (encoded + 4 > encoded_end) goto invalid_size;
  42. /* Fill the state information for this block */
  43. state[c].sample = ((encoded[1]<<8)|encoded[0]);
  44. encoded += 2;
  45. @@ -387,6 +389,7 @@ static int IMA_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
  46. samplesleft = (IMA_ADPCM_state.wSamplesPerBlock-1)*channels;
  47. while ( samplesleft > 0 ) {
  48. for ( c=0; c<channels; ++c ) {
  49. + if (encoded + 4 > encoded_end) goto invalid_size;
  50. Fill_IMA_ADPCM_block(decoded, encoded,
  51. c, channels, &state[c]);
  52. encoded += 4;
  53. @@ -398,6 +401,10 @@ static int IMA_ADPCM_decode(Uint8 **audio_buf, Uint32 *audio_len)
  54. }
  55. SDL_free(freeable);
  56. return(0);
  57. +invalid_size:
  58. + SDL_SetError("Unexpected chunk length for an IMA ADPCM decoder");
  59. + SDL_free(freeable);
  60. + return(-1);
  61. }
  62. SDL_AudioSpec * SDL_LoadWAV_RW (SDL_RWops *src, int freesrc,
  63. --
  64. 2.20.1