003-CVE-2014-8141-getzip64data.patch 4.8 KB

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