You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.4 KiB

  1. From 9171da596c88e6a2dadcab4a3a89dddd6e1b4655 Mon Sep 17 00:00:00 2001
  2. From: Nathan Baker <elitebadger@gmail.com>
  3. Date: Thu, 25 Jan 2018 21:28:15 +0000
  4. Subject: [PATCH] Add workaround to pal2rgb buffer overflow.
  5. ---
  6. tools/pal2rgb.c | 17 +++++++++++++++--
  7. 1 file changed, 15 insertions(+), 2 deletions(-)
  8. diff --git a/tools/pal2rgb.c b/tools/pal2rgb.c
  9. index 0423598..01fcf94 100644
  10. --- a/tools/pal2rgb.c
  11. +++ b/tools/pal2rgb.c
  12. @@ -184,8 +184,21 @@ main(int argc, char* argv[])
  13. { unsigned char *ibuf, *obuf;
  14. register unsigned char* pp;
  15. register uint32 x;
  16. - ibuf = (unsigned char*)_TIFFmalloc(TIFFScanlineSize(in));
  17. - obuf = (unsigned char*)_TIFFmalloc(TIFFScanlineSize(out));
  18. + tmsize_t tss_in = TIFFScanlineSize(in);
  19. + tmsize_t tss_out = TIFFScanlineSize(out);
  20. + if (tss_out / tss_in < 3) {
  21. + /*
  22. + * BUG 2750: The following code does not know about chroma
  23. + * subsampling of JPEG data. It assumes that the output buffer is 3x
  24. + * the length of the input buffer due to exploding the palette into
  25. + * RGB tuples. If this assumption is incorrect, it could lead to a
  26. + * buffer overflow. Go ahead and fail now to prevent that.
  27. + */
  28. + fprintf(stderr, "Could not determine correct image size for output. Exiting.\n");
  29. + return -1;
  30. + }
  31. + ibuf = (unsigned char*)_TIFFmalloc(tss_in);
  32. + obuf = (unsigned char*)_TIFFmalloc(tss_out);
  33. switch (config) {
  34. case PLANARCONFIG_CONTIG:
  35. for (row = 0; row < imagelength; row++) {
  36. --
  37. libgit2 0.27.0