patch-extract_c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. $OpenBSD: patch-extract_c,v 1.2 2017/03/23 17:26:17 bluhm Exp $
  2. Fix CVE-2015-7696: prevent unsigned overflow on invalid input
  3. https://bugzilla.redhat.com/attachment.cgi?id=1075942
  4. https://bugzilla.redhat.com/show_bug.cgi?id=1260944
  5. Fix CVE-2014-8139: CRC32 verification heap-based overflow
  6. https://bugzilla.redhat.com/show_bug.cgi?id=1174844
  7. https://bugzilla.redhat.com/attachment.cgi?id=989833
  8. Fix CVE-2014-8140: out-of-bounds write issue in test_compr_eb()
  9. Fix CVE-2014-9636: out-of-bounds read/write in test_compr_eb()
  10. Fix CVE-2015-7697: infinite loop when extracting empty bzip2 data
  11. https://bugs.debian.org/802160
  12. https://bugzilla.redhat.com/show_bug.cgi?id=1260944
  13. https://bugzilla.redhat.com/attachment.cgi?id=1073339
  14. --- extract.c.orig Sat Mar 14 02:32:52 2009
  15. +++ extract.c Tue Mar 21 16:10:27 2017
  16. @@ -1,5 +1,5 @@
  17. /*
  18. - Copyright (c) 1990-2009 Info-ZIP. All rights reserved.
  19. + Copyright (c) 1990-2014 Info-ZIP. All rights reserved.
  20. See the accompanying file LICENSE, version 2009-Jan-02 or later
  21. (the contents of which are also included in unzip.h) for terms of use.
  22. @@ -298,6 +298,8 @@ char ZCONST Far TruncNTSD[] =
  23. #ifndef SFX
  24. static ZCONST char Far InconsistEFlength[] = "bad extra-field entry:\n \
  25. EF block length (%u bytes) exceeds remaining EF data (%u bytes)\n";
  26. + static ZCONST char Far TooSmallEBlength[] = "bad extra-field entry:\n \
  27. + EF block length (%u bytes) invalid (< %d)\n";
  28. static ZCONST char Far InvalidComprDataEAs[] =
  29. " invalid compressed data for EAs\n";
  30. # if (defined(WIN32) && defined(NTSD_EAS))
  31. @@ -1255,8 +1257,17 @@ static int extract_or_test_entrylist(__G__ numchunk,
  32. if (G.lrec.compression_method == STORED) {
  33. zusz_t csiz_decrypted = G.lrec.csize;
  34. - if (G.pInfo->encrypted)
  35. + if (G.pInfo->encrypted) {
  36. + if (csiz_decrypted < 12) {
  37. + /* handle the error now to prevent unsigned overflow */
  38. + Info(slide, 0x401, ((char *)slide,
  39. + LoadFarStringSmall(ErrUnzipNoFile),
  40. + LoadFarString(InvalidComprData),
  41. + LoadFarStringSmall2(Inflate)));
  42. + return PK_ERR;
  43. + }
  44. csiz_decrypted -= 12;
  45. + }
  46. if (G.lrec.ucsize != csiz_decrypted) {
  47. Info(slide, 0x401, ((char *)slide,
  48. LoadFarStringSmall2(WrnStorUCSizCSizDiff),
  49. @@ -2023,7 +2034,8 @@ static int TestExtraField(__G__ ef, ef_len)
  50. ebID = makeword(ef);
  51. ebLen = (unsigned)makeword(ef+EB_LEN);
  52. - if (ebLen > (ef_len - EB_HEADSIZE)) {
  53. + if (ebLen > (ef_len - EB_HEADSIZE))
  54. + {
  55. /* Discovered some extra field inconsistency! */
  56. if (uO.qflag)
  57. Info(slide, 1, ((char *)slide, "%-22s ",
  58. @@ -2158,11 +2170,19 @@ static int TestExtraField(__G__ ef, ef_len)
  59. }
  60. break;
  61. case EF_PKVMS:
  62. - if (makelong(ef+EB_HEADSIZE) !=
  63. + if (ebLen < 4)
  64. + {
  65. + Info(slide, 1,
  66. + ((char *)slide, LoadFarString(TooSmallEBlength),
  67. + ebLen, 4));
  68. + }
  69. + else if (makelong(ef+EB_HEADSIZE) !=
  70. crc32(CRCVAL_INITIAL, ef+(EB_HEADSIZE+4),
  71. (extent)(ebLen-4)))
  72. + {
  73. Info(slide, 1, ((char *)slide,
  74. LoadFarString(BadCRC_EAs)));
  75. + }
  76. break;
  77. case EF_PKW32:
  78. case EF_PKUNIX:
  79. @@ -2217,15 +2237,32 @@ static int test_compr_eb(__G__ eb, eb_size, compr_offs
  80. ulg eb_ucsize;
  81. uch *eb_ucptr;
  82. int r;
  83. + ush eb_compr_method;
  84. if (compr_offset < 4) /* field is not compressed: */
  85. return PK_OK; /* do nothing and signal OK */
  86. + /* Return no/bad-data error status if any problem is found:
  87. + * 1. eb_size is too small to hold the uncompressed size
  88. + * (eb_ucsize). (Else extract eb_ucsize.)
  89. + * 2. eb_ucsize is zero (invalid). 2014-12-04 SMS.
  90. + * 3. eb_ucsize is positive, but eb_size is too small to hold
  91. + * the compressed data header.
  92. + */
  93. if ((eb_size < (EB_UCSIZE_P + 4)) ||
  94. - ((eb_ucsize = makelong(eb+(EB_HEADSIZE+EB_UCSIZE_P))) > 0L &&
  95. - eb_size <= (compr_offset + EB_CMPRHEADLEN)))
  96. - return IZ_EF_TRUNC; /* no compressed data! */
  97. + ((eb_ucsize = makelong( eb+ (EB_HEADSIZE+ EB_UCSIZE_P))) == 0L) ||
  98. + ((eb_ucsize > 0L) && (eb_size <= (compr_offset + EB_CMPRHEADLEN))))
  99. + return IZ_EF_TRUNC; /* no/bad compressed data! */
  100. + /* 2015-02-10 Mancha(?), Michal Zalewski, Tomas Hoger, SMS.
  101. + * For STORE method, compressed and uncompressed sizes must agree.
  102. + * http://www.info-zip.org/phpBB3/viewtopic.php?f=7&t=450
  103. + */
  104. + eb_compr_method = makeword( eb + (EB_HEADSIZE + compr_offset));
  105. + if ((eb_compr_method == STORED) &&
  106. + (eb_size != compr_offset + EB_CMPRHEADLEN + eb_ucsize))
  107. + return PK_ERR;
  108. +
  109. if (
  110. #ifdef INT_16BIT
  111. (((ulg)(extent)eb_ucsize) != eb_ucsize) ||
  112. @@ -2700,6 +2737,12 @@ __GDEF
  113. int err=BZ_OK;
  114. int repeated_buf_err;
  115. bz_stream bstrm;
  116. +
  117. + if (G.incnt <= 0 && G.csize <= 0L) {
  118. + /* avoid an infinite loop */
  119. + Trace((stderr, "UZbunzip2() got empty input\n"));
  120. + return 2;
  121. + }
  122. #if (defined(DLL) && !defined(NO_SLIDE_REDIR))
  123. if (G.redirect_slide)