gd-CVE-2018-1000222.patch 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. diff --git a/src/gd_bmp.c b/src/gd_bmp.c
  2. index bde0b9d3..78f40d9a 100644
  3. --- a/src/gd_bmp.c
  4. +++ b/src/gd_bmp.c
  5. @@ -47,6 +47,8 @@ static int bmp_read_4bit(gdImagePtr im, gdIOCtxPtr infile, bmp_info_t *info, bmp
  6. static int bmp_read_8bit(gdImagePtr im, gdIOCtxPtr infile, bmp_info_t *info, bmp_hdr_t *header);
  7. static int bmp_read_rle(gdImagePtr im, gdIOCtxPtr infile, bmp_info_t *info);
  8. +static int _gdImageBmpCtx(gdImagePtr im, gdIOCtxPtr out, int compression);
  9. +
  10. #define BMP_DEBUG(s)
  11. static int gdBMPPutWord(gdIOCtx *out, int w)
  12. @@ -87,8 +89,10 @@ BGD_DECLARE(void *) gdImageBmpPtr(gdImagePtr im, int *size, int compression)
  13. void *rv;
  14. gdIOCtx *out = gdNewDynamicCtx(2048, NULL);
  15. if (out == NULL) return NULL;
  16. - gdImageBmpCtx(im, out, compression);
  17. - rv = gdDPExtractData(out, size);
  18. + if (!_gdImageBmpCtx(im, out, compression))
  19. + rv = gdDPExtractData(out, size);
  20. + else
  21. + rv = NULL;
  22. out->gd_free(out);
  23. return rv;
  24. }
  25. @@ -141,6 +145,11 @@ BGD_DECLARE(void) gdImageBmp(gdImagePtr im, FILE *outFile, int compression)
  26. compression - whether to apply RLE or not.
  27. */
  28. BGD_DECLARE(void) gdImageBmpCtx(gdImagePtr im, gdIOCtxPtr out, int compression)
  29. +{
  30. + _gdImageBmpCtx(im, out, compression);
  31. +}
  32. +
  33. +static int _gdImageBmpCtx(gdImagePtr im, gdIOCtxPtr out, int compression)
  34. {
  35. int bitmap_size = 0, info_size, total_size, padding;
  36. int i, row, xpos, pixel;
  37. @@ -148,6 +157,7 @@ BGD_DECLARE(void) gdImageBmpCtx(gdImagePtr im, gdIOCtxPtr out, int compression)
  38. unsigned char *uncompressed_row = NULL, *uncompressed_row_start = NULL;
  39. FILE *tmpfile_for_compression = NULL;
  40. gdIOCtxPtr out_original = NULL;
  41. + int ret = 1;
  42. /* No compression if its true colour or we don't support seek */
  43. if (im->trueColor) {
  44. @@ -325,6 +335,7 @@ BGD_DECLARE(void) gdImageBmpCtx(gdImagePtr im, gdIOCtxPtr out, int compression)
  45. out_original = NULL;
  46. }
  47. + ret = 0;
  48. cleanup:
  49. if (tmpfile_for_compression) {
  50. #ifdef _WIN32
  51. @@ -338,7 +349,7 @@ BGD_DECLARE(void) gdImageBmpCtx(gdImagePtr im, gdIOCtxPtr out, int compression)
  52. if (out_original) {
  53. out_original->gd_free(out_original);
  54. }
  55. - return;
  56. + return ret;
  57. }
  58. static int compress_row(unsigned char *row, int length)