CVE-2019-7574.patch 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # HG changeset patch
  2. # User Petr Písař <ppisar@redhat.com>
  3. # Date 1560181859 25200
  4. # Mon Jun 10 08:50:59 2019 -0700
  5. # Branch SDL-1.2
  6. # Node ID a6e3d2f5183e1cc300ad993e10e9ce077e13bd9c
  7. # Parent 388987dff7bf8f1e214e69c2e4f1aa31e06396b5
  8. CVE-2019-7574: Fix a buffer overread in IMA_ADPCM_decode
  9. If data chunk was shorter than expected based on a WAV format
  10. definition, IMA_ADPCM_decode() tried to read past the data chunk
  11. buffer. This patch fixes it.
  12. CVE-2019-7574
  13. https://bugzilla.libsdl.org/show_bug.cgi?id=4496
  14. Signed-off-by: Petr Písař <ppisar@redhat.com>
  15. CVE: CVE-2019-7574
  16. Upstream-Status: Backport
  17. Signed-off-by: Anuj Mittal <anuj.mittal@intel.com>
  18. diff -r 388987dff7bf -r a6e3d2f5183e src/audio/SDL_wave.c
  19. --- a/src/audio/SDL_wave.c Sat Jun 08 18:02:09 2019 -0700
  20. +++ b/src/audio/SDL_wave.c Mon Jun 10 08:50:59 2019 -0700
  21. @@ -331,7 +331,7 @@
  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. @@ -347,6 +347,7 @@
  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. @@ -362,6 +363,7 @@
  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. @@ -384,6 +386,7 @@
  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. @@ -395,6 +398,10 @@
  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,