getZip64Data.patch 4.9 KB

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