18-stack-corruption.patch 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. Author: Fabian Greffrath <fabian+debian@greffrath.com>
  2. Description: Fix a stack corruption while trying to verify integrity
  3. of a fuzzed file. Thanks again, Jakub Wilk.
  4. Bug-Debian: https://bugs.debian.org/775134
  5. --- a/source/base/all/uninorm/uninorm.c
  6. +++ b/source/base/all/uninorm/uninorm.c
  7. @@ -36,6 +36,9 @@ INT BASE_UNINORM_CP850ToUTF8NFC(UCHAR *c
  8. UINT Unicode[BASE_LFN_MAXLEN+1], Normalized[BASE_LFN_MAXLEN+1], *destptr = Unicode;
  9. UCHAR *srcptr = cp850String, *resultstr = cp850String;
  10. + if ((UINT) len >= BASE_LFN_MAXLEN)
  11. + len = BASE_LFN_MAXLEN - 1;
  12. +
  13. srcptr[len] = 0;
  14. /* First, convert that DOS CP850 encoded String to Unicode */
  15. while (*srcptr)
  16. @@ -48,6 +51,7 @@ INT BASE_UNINORM_CP850ToUTF8NFC(UCHAR *c
  17. /* Then normalize and return UTF-8 encoded in place of the input string */
  18. normalize_nfc(Normalized, Unicode);
  19. encode_utf8(resultstr, Normalized);
  20. + resultstr[len] = 0;
  21. return strlen(resultstr);
  22. --- a/source/base/all/uninorm/unincore.c
  23. +++ b/source/base/all/uninorm/unincore.c
  24. @@ -17,6 +17,7 @@
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28. +#include "base/all/includes.h" /* BASE_LFN_MAXLEN */
  29. #include "unidata.h"
  30. /* Hangul constants */
  31. @@ -33,7 +34,7 @@
  32. /* convenience null */
  33. #define null 0
  34. -#define MAX_FILENAME_SIZE 2048
  35. +#define MAX_FILENAME_SIZE BASE_LFN_MAXLEN
  36. /**
  37. @@ -367,7 +368,7 @@ void canonical_decomposition(uint *buf,
  38. uint temp[MAX_FILENAME_SIZE];
  39. temp[0] = null;
  40. - for (i = 0; i < length; ++i)
  41. + for (i = 0; i < length && pos < MAX_FILENAME_SIZE; ++i)
  42. {
  43. decompose_recursive(temp, str[i]);
  44. len = istrlen(temp);
  45. @@ -458,7 +459,7 @@ void encode_utf8(char *buf, uint *str)
  46. int i, j = 0;
  47. int len = istrlen(str);
  48. - for (i = 0; i < len; ++i)
  49. + for (i = 0; i < len && j < MAX_FILENAME_SIZE; ++i)
  50. {
  51. uint c = str[i];