0001-tjLoadImage-Fix-int-overflow-segfault-w-big-BMP.patch 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. From 3d9c64e9f8aa1ee954d1d0bb3390fc894bb84da3 Mon Sep 17 00:00:00 2001
  2. From: DRC <information@libjpeg-turbo.org>
  3. Date: Tue, 1 Jan 2019 18:57:36 -0600
  4. Subject: [PATCH] tjLoadImage(): Fix int overflow/segfault w/big BMP
  5. Fixes #304
  6. [baruch: drop the ChangeLog.md hunk]
  7. Signed-off-by: Baruch Siach <baruch@tkos.co.il>
  8. ---
  9. Upstream status: commit 3d9c64e9f8aa
  10. ChangeLog.md | 4 ++++
  11. turbojpeg.c | 9 ++++++---
  12. 2 files changed, 10 insertions(+), 3 deletions(-)
  13. diff --git a/turbojpeg.c b/turbojpeg.c
  14. index 90a9ce6a0be8..3f7cd640677f 100644
  15. --- a/turbojpeg.c
  16. +++ b/turbojpeg.c
  17. @@ -1,5 +1,5 @@
  18. /*
  19. - * Copyright (C)2009-2018 D. R. Commander. All Rights Reserved.
  20. + * Copyright (C)2009-2019 D. R. Commander. All Rights Reserved.
  21. *
  22. * Redistribution and use in source and binary forms, with or without
  23. * modification, are permitted provided that the following conditions are met:
  24. @@ -1960,7 +1960,8 @@ DLLEXPORT unsigned char *tjLoadImage(const char *filename, int *width,
  25. int align, int *height, int *pixelFormat,
  26. int flags)
  27. {
  28. - int retval = 0, tempc, pitch;
  29. + int retval = 0, tempc;
  30. + size_t pitch;
  31. tjhandle handle = NULL;
  32. tjinstance *this;
  33. j_compress_ptr cinfo = NULL;
  34. @@ -2013,7 +2014,9 @@ DLLEXPORT unsigned char *tjLoadImage(const char *filename, int *width,
  35. *pixelFormat = cs2pf[cinfo->in_color_space];
  36. pitch = PAD((*width) * tjPixelSize[*pixelFormat], align);
  37. - if ((dstBuf = (unsigned char *)malloc(pitch * (*height))) == NULL)
  38. + if ((unsigned long long)pitch * (unsigned long long)(*height) >
  39. + (unsigned long long)((size_t)-1) ||
  40. + (dstBuf = (unsigned char *)malloc(pitch * (*height))) == NULL)
  41. _throwg("tjLoadImage(): Memory allocation failure");
  42. if (setjmp(this->jerr.setjmp_buffer)) {
  43. --
  44. 2.20.1