gegl-0.2.0-cve-2012-4433-1e92e523.patch 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. From 1e92e5235ded0415d555aa86066b8e4041ee5a53 Mon Sep 17 00:00:00 2001
  2. From: Nils Philippsen <nils@redhat.com>
  3. Date: Tue, 16 Oct 2012 14:58:27 +0000
  4. Subject: ppm-load: CVE-2012-4433: don't overflow memory allocation
  5. Carefully selected width/height values could cause the size of a later
  6. allocation to overflow, resulting in a buffer much too small to store
  7. the data which would then written beyond its end.
  8. ---
  9. diff --git a/operations/external/ppm-load.c b/operations/external/ppm-load.c
  10. index efe6d56..3d6bce7 100644
  11. --- a/operations/external/ppm-load.c
  12. +++ b/operations/external/ppm-load.c
  13. @@ -84,7 +84,6 @@ ppm_load_read_header(FILE *fp,
  14. /* Get Width and Height */
  15. img->width = strtol (header,&ptr,0);
  16. img->height = atoi (ptr);
  17. - img->numsamples = img->width * img->height * CHANNEL_COUNT;
  18. fgets (header,MAX_CHARS_IN_ROW,fp);
  19. maxval = strtol (header,&ptr,0);
  20. @@ -109,6 +108,16 @@ ppm_load_read_header(FILE *fp,
  21. g_warning ("%s: Programmer stupidity error", G_STRLOC);
  22. }
  23. + /* Later on, img->numsamples is multiplied with img->bpc to allocate
  24. + * memory. Ensure it doesn't overflow. */
  25. + if (!img->width || !img->height ||
  26. + G_MAXSIZE / img->width / img->height / CHANNEL_COUNT < img->bpc)
  27. + {
  28. + g_warning ("Illegal width/height: %ld/%ld", img->width, img->height);
  29. + return FALSE;
  30. + }
  31. + img->numsamples = img->width * img->height * CHANNEL_COUNT;
  32. +
  33. return TRUE;
  34. }
  35. @@ -229,12 +238,24 @@ process (GeglOperation *operation,
  36. if (!ppm_load_read_header (fp, &img))
  37. goto out;
  38. - rect.height = img.height;
  39. - rect.width = img.width;
  40. -
  41. /* Allocating Array Size */
  42. +
  43. + /* Should use g_try_malloc(), but this causes crashes elsewhere because the
  44. + * error signalled by returning FALSE isn't properly acted upon. Therefore
  45. + * g_malloc() is used here which aborts if the requested memory size can't be
  46. + * allocated causing a controlled crash. */
  47. img.data = (guchar*) g_malloc (img.numsamples * img.bpc);
  48. + /* No-op without g_try_malloc(), see above. */
  49. + if (! img.data)
  50. + {
  51. + g_warning ("Couldn't allocate %" G_GSIZE_FORMAT " bytes, giving up.", ((gsize)img.numsamples * img.bpc));
  52. + goto out;
  53. + }
  54. +
  55. + rect.height = img.height;
  56. + rect.width = img.width;
  57. +
  58. switch (img.bpc)
  59. {
  60. case 1:
  61. --
  62. cgit v0.9.0.2