SDL-1.2.15-CVE-2019-7638-CVE-2019-7636-Refuse-loading-BMP-image.patch 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. From 28b1433b4bd7982524f2418420e8cc01786df5c4 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
  3. Date: Fri, 15 Feb 2019 16:52:27 +0100
  4. Subject: [PATCH] CVE-2019-7638, CVE-2019-7636: Refuse loading BMP images with
  5. too high number of colors
  6. MIME-Version: 1.0
  7. Content-Type: text/plain; charset=UTF-8
  8. Content-Transfer-Encoding: 8bit
  9. If a BMP file that defines more colors than can fit into
  10. a palette of color depth defined in the same BMP file is loaded by
  11. SDL_LoadBMP_RW() function, invalid number of colors is set into
  12. resulting SDL surface.
  13. Then if the SDL surface is passed to SDL_DisplayFormat() function to
  14. convert the surface format into a native video format, a buffer
  15. overread will happen in Map1to1() or Map1toN() function
  16. (CVE-2019-7638). (The choice of the mapping function depends on
  17. a actual video hardware.)
  18. In addition SDL_GetRGB() called indirectly from SDL_DisplayFormat()
  19. performs the same buffer overread (CVE-2019-7636).
  20. There is also probably a buffer overwrite when the SDL_LoadBMP_RW()
  21. loads colors from a file.
  22. This patch fixes it by refusing loading such badly damaged BMP files.
  23. CVE-2019-7638
  24. https://bugzilla.libsdl.org/show_bug.cgi?id=4500
  25. CVE-2019-7636
  26. https://bugzilla.libsdl.org/show_bug.cgi?id=4499
  27. Signed-off-by: Petr Písař <ppisar@redhat.com>
  28. ---
  29. src/video/SDL_bmp.c | 4 ++++
  30. 1 file changed, 4 insertions(+)
  31. diff --git a/src/video/SDL_bmp.c b/src/video/SDL_bmp.c
  32. index d56cfd8..3accded 100644
  33. --- a/src/video/SDL_bmp.c
  34. +++ b/src/video/SDL_bmp.c
  35. @@ -233,6 +233,10 @@ SDL_Surface * SDL_LoadBMP_RW (SDL_RWops *src, int freesrc)
  36. if ( palette ) {
  37. if ( biClrUsed == 0 ) {
  38. biClrUsed = 1 << biBitCount;
  39. + } else if ( biClrUsed > (1 << biBitCount) ) {
  40. + SDL_SetError("BMP file has an invalid number of colors");
  41. + was_error = SDL_TRUE;
  42. + goto done;
  43. }
  44. if ( biSize == 12 ) {
  45. for ( i = 0; i < (int)biClrUsed; ++i ) {
  46. --
  47. 2.20.1