unzip-6.0-cve-2014-8141.patch 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. diff --git a/fileio.c b/fileio.c
  2. index 03fc4be..2a61a30 100644
  3. --- a/fileio.c
  4. +++ b/fileio.c
  5. @@ -176,6 +176,8 @@ static ZCONST char Far FilenameTooLongTrunc[] =
  6. #endif
  7. static ZCONST char Far ExtraFieldTooLong[] =
  8. "warning: extra field too long (%d). Ignoring...\n";
  9. +static ZCONST char Far ExtraFieldCorrupt[] =
  10. + "warning: extra field (type: 0x%04x) corrupt. Continuing...\n";
  11. #ifdef WINDLL
  12. static ZCONST char Far DiskFullQuery[] =
  13. @@ -2300,7 +2302,13 @@ int do_string(__G__ length, option) /* return PK-type error code */
  14. length = length2;
  15. }
  16. /* Looks like here is where extra fields are read */
  17. - getZip64Data(__G__ G.extra_field, length);
  18. + if (getZip64Data(__G__ G.extra_field, length) != PK_COOL)
  19. + {
  20. + Info(slide, 0x401, ((char *)slide,
  21. + LoadFarString( ExtraFieldCorrupt), EF_PKSZ64));
  22. + error = PK_WARN;
  23. + }
  24. +
  25. #ifdef UNICODE_SUPPORT
  26. G.unipath_filename = NULL;
  27. if (G.UzO.U_flag < 2) {
  28. diff --git a/process.c b/process.c
  29. index be6e006..0d57ab4 100644
  30. --- a/process.c
  31. +++ b/process.c
  32. @@ -1,5 +1,5 @@
  33. /*
  34. - Copyright (c) 1990-2009 Info-ZIP. All rights reserved.
  35. + Copyright (c) 1990-2014 Info-ZIP. All rights reserved.
  36. See the accompanying file LICENSE, version 2009-Jan-02 or later
  37. (the contents of which are also included in unzip.h) for terms of use.
  38. @@ -1894,48 +1894,83 @@ int getZip64Data(__G__ ef_buf, ef_len)
  39. and a 4-byte version of disk start number.
  40. Sets both local header and central header fields. Not terribly clever,
  41. but it means that this procedure is only called in one place.
  42. +
  43. + 2014-12-05 SMS.
  44. + Added checks to ensure that enough data are available before calling
  45. + makeint64() or makelong(). Replaced various sizeof() values with
  46. + simple ("4" or "8") constants. (The Zip64 structures do not depend
  47. + on our variable sizes.) Error handling is crude, but we should now
  48. + stay within the buffer.
  49. ---------------------------------------------------------------------------*/
  50. +#define Z64FLGS 0xffff
  51. +#define Z64FLGL 0xffffffff
  52. +
  53. if (ef_len == 0 || ef_buf == NULL)
  54. return PK_COOL;
  55. Trace((stderr,"\ngetZip64Data: scanning extra field of length %u\n",
  56. ef_len));
  57. - while (ef_len >= EB_HEADSIZE) {
  58. + while (ef_len >= EB_HEADSIZE)
  59. + {
  60. eb_id = makeword(EB_ID + ef_buf);
  61. eb_len = makeword(EB_LEN + ef_buf);
  62. - if (eb_len > (ef_len - EB_HEADSIZE)) {
  63. - /* discovered some extra field inconsistency! */
  64. + if (eb_len > (ef_len - EB_HEADSIZE))
  65. + {
  66. + /* Extra block length exceeds remaining extra field length. */
  67. Trace((stderr,
  68. "getZip64Data: block length %u > rest ef_size %u\n", eb_len,
  69. ef_len - EB_HEADSIZE));
  70. break;
  71. }
  72. - if (eb_id == EF_PKSZ64) {
  73. + if (eb_id == EF_PKSZ64)
  74. + {
  75. int offset = EB_HEADSIZE;
  76. - if (G.crec.ucsize == 0xffffffff || G.lrec.ucsize == 0xffffffff){
  77. - G.lrec.ucsize = G.crec.ucsize = makeint64(offset + ef_buf);
  78. - offset += sizeof(G.crec.ucsize);
  79. + if ((G.crec.ucsize == Z64FLGL) || (G.lrec.ucsize == Z64FLGL))
  80. + {
  81. + if (offset+ 8 > ef_len)
  82. + return PK_ERR;
  83. +
  84. + G.crec.ucsize = G.lrec.ucsize = makeint64(offset + ef_buf);
  85. + offset += 8;
  86. }
  87. - if (G.crec.csize == 0xffffffff || G.lrec.csize == 0xffffffff){
  88. - G.csize = G.lrec.csize = G.crec.csize = makeint64(offset + ef_buf);
  89. - offset += sizeof(G.crec.csize);
  90. +
  91. + if ((G.crec.csize == Z64FLGL) || (G.lrec.csize == Z64FLGL))
  92. + {
  93. + if (offset+ 8 > ef_len)
  94. + return PK_ERR;
  95. +
  96. + G.csize = G.crec.csize = G.lrec.csize = makeint64(offset + ef_buf);
  97. + offset += 8;
  98. }
  99. - if (G.crec.relative_offset_local_header == 0xffffffff){
  100. +
  101. + if (G.crec.relative_offset_local_header == Z64FLGL)
  102. + {
  103. + if (offset+ 8 > ef_len)
  104. + return PK_ERR;
  105. +
  106. G.crec.relative_offset_local_header = makeint64(offset + ef_buf);
  107. - offset += sizeof(G.crec.relative_offset_local_header);
  108. + offset += 8;
  109. }
  110. - if (G.crec.disk_number_start == 0xffff){
  111. +
  112. + if (G.crec.disk_number_start == Z64FLGS)
  113. + {
  114. + if (offset+ 4 > ef_len)
  115. + return PK_ERR;
  116. +
  117. G.crec.disk_number_start = (zuvl_t)makelong(offset + ef_buf);
  118. - offset += sizeof(G.crec.disk_number_start);
  119. + offset += 4;
  120. }
  121. +#if 0
  122. + break; /* Expect only one EF_PKSZ64 block. */
  123. +#endif /* 0 */
  124. }
  125. - /* Skip this extra field block */
  126. + /* Skip this extra field block. */
  127. ef_buf += (eb_len + EB_HEADSIZE);
  128. ef_len -= (eb_len + EB_HEADSIZE);
  129. }