libmspack 0.0.5 → 0.10.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/rake.yml +37 -0
  3. data/.gitignore +2 -0
  4. data/.yardopts +1 -1
  5. data/README.md +1 -1
  6. data/Rakefile +11 -5
  7. data/ext/Rakefile +1 -1
  8. data/ext/libmspack/AUTHORS +1 -0
  9. data/ext/libmspack/ChangeLog +321 -4
  10. data/ext/libmspack/INSTALL +368 -0
  11. data/ext/libmspack/Makefile.am +86 -95
  12. data/ext/libmspack/Makefile.in +1729 -0
  13. data/ext/libmspack/README +30 -30
  14. data/ext/libmspack/acinclude.m4 +99 -0
  15. data/ext/libmspack/aclocal.m4 +1218 -0
  16. data/ext/libmspack/ar-lib +270 -0
  17. data/ext/libmspack/compile +347 -0
  18. data/ext/libmspack/config.guess +1480 -0
  19. data/ext/libmspack/config.h.in +129 -0
  20. data/ext/libmspack/config.sub +1801 -0
  21. data/ext/libmspack/configure +15487 -0
  22. data/ext/libmspack/configure.ac +11 -13
  23. data/ext/libmspack/depcomp +791 -0
  24. data/ext/libmspack/install-sh +508 -0
  25. data/ext/libmspack/libmscabd.la +41 -0
  26. data/ext/libmspack/libmschmd.la +41 -0
  27. data/ext/libmspack/libmspack.la +41 -0
  28. data/ext/libmspack/ltmain.sh +11156 -0
  29. data/ext/libmspack/m4/libtool.m4 +8387 -0
  30. data/ext/libmspack/m4/ltoptions.m4 +437 -0
  31. data/ext/libmspack/m4/ltsugar.m4 +124 -0
  32. data/ext/libmspack/m4/ltversion.m4 +23 -0
  33. data/ext/libmspack/m4/lt~obsolete.m4 +99 -0
  34. data/ext/libmspack/missing +215 -0
  35. data/ext/libmspack/mspack/cab.h +20 -7
  36. data/ext/libmspack/mspack/cabd.c +301 -236
  37. data/ext/libmspack/mspack/chmd.c +304 -319
  38. data/ext/libmspack/mspack/crc32.c +52 -52
  39. data/ext/libmspack/mspack/crc32.h +1 -1
  40. data/ext/libmspack/mspack/kwajd.c +178 -172
  41. data/ext/libmspack/mspack/lzss.h +4 -4
  42. data/ext/libmspack/mspack/lzssd.c +42 -42
  43. data/ext/libmspack/mspack/lzx.h +11 -11
  44. data/ext/libmspack/mspack/lzxd.c +370 -361
  45. data/ext/libmspack/mspack/mspack.h +109 -77
  46. data/ext/libmspack/mspack/mszip.h +6 -6
  47. data/ext/libmspack/mspack/mszipd.c +140 -139
  48. data/ext/libmspack/mspack/oab.h +1 -0
  49. data/ext/libmspack/mspack/oabd.c +71 -73
  50. data/ext/libmspack/mspack/qtm.h +4 -4
  51. data/ext/libmspack/mspack/qtmd.c +118 -117
  52. data/ext/libmspack/mspack/readbits.h +52 -52
  53. data/ext/libmspack/mspack/readhuff.h +61 -61
  54. data/ext/libmspack/mspack/system.c +15 -9
  55. data/ext/libmspack/mspack/system.h +38 -50
  56. data/ext/libmspack/mspack/szddd.c +35 -35
  57. data/ext/libmspack/test-driver +148 -0
  58. data/ext/x86_64-linux/libmspack.so +0 -0
  59. data/ext/x86_64-windows/mspack.dll +0 -0
  60. data/lib/libmspack/version.rb +2 -1
  61. data/lib/libmspack.rb +1 -1
  62. data/libmspack.gemspec +4 -4
  63. data/spec/libmspack_spec.rb +5 -4
  64. metadata +38 -105
  65. data/.travis.yml +0 -5
  66. data/ext/i386-windows/libmspack.dll +0 -0
  67. data/ext/libmspack/cleanup.sh +0 -9
  68. data/ext/libmspack/debian/changelog +0 -6
  69. data/ext/libmspack/debian/control +0 -14
  70. data/ext/libmspack/debian/rules +0 -101
  71. data/ext/libmspack/doc/Doxyfile.in +0 -22
  72. data/ext/libmspack/doc/Makefile.in +0 -14
  73. data/ext/libmspack/doc/szdd_kwaj_format.html +0 -331
  74. data/ext/libmspack/mspack/mspack.def +0 -28
  75. data/ext/libmspack/mspack/qtmc.c +0 -18
  76. data/ext/libmspack/rebuild.sh +0 -8
  77. data/ext/libmspack/test/cabd_c10 +0 -19
  78. data/ext/libmspack/test/cabd_compare +0 -34
  79. data/ext/libmspack/test/cabd_md5.c +0 -161
  80. data/ext/libmspack/test/cabd_memory.c +0 -179
  81. data/ext/libmspack/test/cabd_test.c +0 -386
  82. data/ext/libmspack/test/cabrip.c +0 -81
  83. data/ext/libmspack/test/chmd_compare +0 -38
  84. data/ext/libmspack/test/chmd_find.c +0 -95
  85. data/ext/libmspack/test/chmd_md5.c +0 -67
  86. data/ext/libmspack/test/chmd_order.c +0 -144
  87. data/ext/libmspack/test/chminfo.c +0 -284
  88. data/ext/libmspack/test/chmx.c +0 -216
  89. data/ext/libmspack/test/error.h +0 -22
  90. data/ext/libmspack/test/expand.c +0 -79
  91. data/ext/libmspack/test/md5.c +0 -457
  92. data/ext/libmspack/test/md5.h +0 -165
  93. data/ext/libmspack/test/md5_fh.h +0 -123
  94. data/ext/libmspack/test/msdecompile_md5 +0 -24
  95. data/ext/libmspack/test/msexpand_md5 +0 -39
  96. data/ext/libmspack/test/multifh.c +0 -435
  97. data/ext/libmspack/test/oabx.c +0 -41
  98. data/ext/libmspack/test/test_files/cabd/1.pl +0 -84
  99. data/ext/libmspack/test/test_files/cabd/2.pl +0 -75
  100. data/ext/libmspack/test/test_files/cabd/bad_folderindex.cab +0 -0
  101. data/ext/libmspack/test/test_files/cabd/bad_nofiles.cab +0 -0
  102. data/ext/libmspack/test/test_files/cabd/bad_nofolders.cab +0 -0
  103. data/ext/libmspack/test/test_files/cabd/bad_signature.cab +0 -0
  104. data/ext/libmspack/test/test_files/cabd/multi_basic_pt1.cab +0 -0
  105. data/ext/libmspack/test/test_files/cabd/multi_basic_pt2.cab +0 -0
  106. data/ext/libmspack/test/test_files/cabd/multi_basic_pt3.cab +0 -0
  107. data/ext/libmspack/test/test_files/cabd/multi_basic_pt4.cab +0 -0
  108. data/ext/libmspack/test/test_files/cabd/multi_basic_pt5.cab +0 -0
  109. data/ext/libmspack/test/test_files/cabd/normal_255c_filename.cab +0 -0
  110. data/ext/libmspack/test/test_files/cabd/normal_2files_1folder.cab +0 -0
  111. data/ext/libmspack/test/test_files/cabd/partial_nodata.cab +0 -0
  112. data/ext/libmspack/test/test_files/cabd/partial_nofiles.cab +0 -0
  113. data/ext/libmspack/test/test_files/cabd/partial_nofolder.cab +0 -0
  114. data/ext/libmspack/test/test_files/cabd/partial_shortextheader.cab +0 -0
  115. data/ext/libmspack/test/test_files/cabd/partial_shortfile1.cab +0 -0
  116. data/ext/libmspack/test/test_files/cabd/partial_shortfile2.cab +0 -0
  117. data/ext/libmspack/test/test_files/cabd/partial_shortfolder.cab +0 -0
  118. data/ext/libmspack/test/test_files/cabd/partial_shortheader.cab +0 -0
  119. data/ext/libmspack/test/test_files/cabd/partial_str_nofname.cab +0 -0
  120. data/ext/libmspack/test/test_files/cabd/partial_str_noninfo.cab +0 -0
  121. data/ext/libmspack/test/test_files/cabd/partial_str_nonname.cab +0 -0
  122. data/ext/libmspack/test/test_files/cabd/partial_str_nopinfo.cab +0 -0
  123. data/ext/libmspack/test/test_files/cabd/partial_str_nopname.cab +0 -0
  124. data/ext/libmspack/test/test_files/cabd/partial_str_shortfname.cab +0 -0
  125. data/ext/libmspack/test/test_files/cabd/partial_str_shortninfo.cab +0 -0
  126. data/ext/libmspack/test/test_files/cabd/partial_str_shortnname.cab +0 -0
  127. data/ext/libmspack/test/test_files/cabd/partial_str_shortpinfo.cab +0 -0
  128. data/ext/libmspack/test/test_files/cabd/partial_str_shortpname.cab +0 -0
  129. data/ext/libmspack/test/test_files/cabd/reserve_---.cab +0 -0
  130. data/ext/libmspack/test/test_files/cabd/reserve_--D.cab +0 -0
  131. data/ext/libmspack/test/test_files/cabd/reserve_-F-.cab +0 -0
  132. data/ext/libmspack/test/test_files/cabd/reserve_-FD.cab +0 -0
  133. data/ext/libmspack/test/test_files/cabd/reserve_H--.cab +0 -0
  134. data/ext/libmspack/test/test_files/cabd/reserve_H-D.cab +0 -0
  135. data/ext/libmspack/test/test_files/cabd/reserve_HF-.cab +0 -0
  136. data/ext/libmspack/test/test_files/cabd/reserve_HFD.cab +0 -0
  137. data/ext/libmspack/test/test_files/cabd/search_basic.cab +0 -0
  138. data/ext/libmspack/test/test_files/cabd/search_tricky1.cab +0 -0
  139. data/ext/libmspack/winbuild.sh +0 -26
  140. data/ext/libmspack.h +0 -259
  141. data/ext/x86_64-windows/libmspack.dll +0 -0
@@ -20,9 +20,9 @@
20
20
  #define BITS_VAR zip
21
21
  #define BITS_ORDER_LSB
22
22
  #define BITS_LSB_TABLE
23
- #define READ_BYTES do { \
24
- READ_IF_NEEDED; \
25
- INJECT_BITS(*i_ptr++, 8); \
23
+ #define READ_BYTES do { \
24
+ READ_IF_NEEDED; \
25
+ INJECT_BITS(*i_ptr++, 8); \
26
26
  } while (0)
27
27
  #include <readbits.h>
28
28
 
@@ -34,13 +34,13 @@
34
34
  #define HUFF_ERROR return INF_ERR_HUFFSYM
35
35
  #include <readhuff.h>
36
36
 
37
- #define FLUSH_IF_NEEDED do { \
38
- if (zip->window_posn == MSZIP_FRAME_SIZE) { \
39
- if (zip->flush_window(zip, MSZIP_FRAME_SIZE)) { \
40
- return INF_ERR_FLUSH; \
41
- } \
42
- zip->window_posn = 0; \
43
- } \
37
+ #define FLUSH_IF_NEEDED do { \
38
+ if (zip->window_posn == MSZIP_FRAME_SIZE) { \
39
+ if (zip->flush_window(zip, MSZIP_FRAME_SIZE)) { \
40
+ return INF_ERR_FLUSH; \
41
+ } \
42
+ zip->window_posn = 0; \
43
+ } \
44
44
  } while (0)
45
45
 
46
46
  /* match lengths for literal codes 257.. 285 */
@@ -181,14 +181,14 @@ static int inflate(struct mszipd_stream *zip) {
181
181
 
182
182
  /* read 4 bytes of data, emptying the bit-buffer if necessary */
183
183
  for (i = 0; (bits_left >= 8); i++) {
184
- if (i == 4) return INF_ERR_BITBUF;
185
- lens_buf[i] = PEEK_BITS(8);
186
- REMOVE_BITS(8);
184
+ if (i == 4) return INF_ERR_BITBUF;
185
+ lens_buf[i] = PEEK_BITS(8);
186
+ REMOVE_BITS(8);
187
187
  }
188
188
  if (bits_left != 0) return INF_ERR_BITBUF;
189
189
  while (i < 4) {
190
- READ_IF_NEEDED;
191
- lens_buf[i++] = *i_ptr++;
190
+ READ_IF_NEEDED;
191
+ lens_buf[i++] = *i_ptr++;
192
192
  }
193
193
 
194
194
  /* get the length and its complement */
@@ -198,18 +198,18 @@ static int inflate(struct mszipd_stream *zip) {
198
198
 
199
199
  /* read and copy the uncompressed data into the window */
200
200
  while (length > 0) {
201
- READ_IF_NEEDED;
202
-
203
- this_run = length;
204
- if (this_run > (unsigned int)(i_end - i_ptr)) this_run = i_end - i_ptr;
205
- if (this_run > (MSZIP_FRAME_SIZE - zip->window_posn))
206
- this_run = MSZIP_FRAME_SIZE - zip->window_posn;
207
-
208
- zip->sys->copy(i_ptr, &zip->window[zip->window_posn], this_run);
209
- zip->window_posn += this_run;
210
- i_ptr += this_run;
211
- length -= this_run;
212
- FLUSH_IF_NEEDED;
201
+ READ_IF_NEEDED;
202
+
203
+ this_run = length;
204
+ if (this_run > (unsigned int)(i_end - i_ptr)) this_run = i_end - i_ptr;
205
+ if (this_run > (MSZIP_FRAME_SIZE - zip->window_posn))
206
+ this_run = MSZIP_FRAME_SIZE - zip->window_posn;
207
+
208
+ zip->sys->copy(i_ptr, &zip->window[zip->window_posn], this_run);
209
+ zip->window_posn += this_run;
210
+ i_ptr += this_run;
211
+ length -= this_run;
212
+ FLUSH_IF_NEEDED;
213
213
  }
214
214
  }
215
215
  else if ((block_type == 1) || (block_type == 2)) {
@@ -217,92 +217,92 @@ static int inflate(struct mszipd_stream *zip) {
217
217
  unsigned int match_posn, code;
218
218
 
219
219
  if (block_type == 1) {
220
- /* block with fixed Huffman codes */
221
- i = 0;
222
- while (i < 144) zip->LITERAL_len[i++] = 8;
223
- while (i < 256) zip->LITERAL_len[i++] = 9;
224
- while (i < 280) zip->LITERAL_len[i++] = 7;
225
- while (i < 288) zip->LITERAL_len[i++] = 8;
226
- for (i = 0; i < 32; i++) zip->DISTANCE_len[i] = 5;
220
+ /* block with fixed Huffman codes */
221
+ i = 0;
222
+ while (i < 144) zip->LITERAL_len[i++] = 8;
223
+ while (i < 256) zip->LITERAL_len[i++] = 9;
224
+ while (i < 280) zip->LITERAL_len[i++] = 7;
225
+ while (i < 288) zip->LITERAL_len[i++] = 8;
226
+ for (i = 0; i < 32; i++) zip->DISTANCE_len[i] = 5;
227
227
  }
228
228
  else {
229
- /* block with dynamic Huffman codes */
230
- STORE_BITS;
231
- if ((i = zip_read_lens(zip))) return i;
232
- RESTORE_BITS;
229
+ /* block with dynamic Huffman codes */
230
+ STORE_BITS;
231
+ if ((i = zip_read_lens(zip))) return i;
232
+ RESTORE_BITS;
233
233
  }
234
234
 
235
235
  /* now huffman lengths are read for either kind of block,
236
236
  * create huffman decoding tables */
237
237
  if (make_decode_table(MSZIP_LITERAL_MAXSYMBOLS, MSZIP_LITERAL_TABLEBITS,
238
- &zip->LITERAL_len[0], &zip->LITERAL_table[0]))
238
+ &zip->LITERAL_len[0], &zip->LITERAL_table[0]))
239
239
  {
240
- return INF_ERR_LITERALTBL;
240
+ return INF_ERR_LITERALTBL;
241
241
  }
242
242
 
243
243
  if (make_decode_table(MSZIP_DISTANCE_MAXSYMBOLS,MSZIP_DISTANCE_TABLEBITS,
244
- &zip->DISTANCE_len[0], &zip->DISTANCE_table[0]))
244
+ &zip->DISTANCE_len[0], &zip->DISTANCE_table[0]))
245
245
  {
246
- return INF_ERR_DISTANCETBL;
246
+ return INF_ERR_DISTANCETBL;
247
247
  }
248
248
 
249
249
  /* decode forever until end of block code */
250
250
  for (;;) {
251
- READ_HUFFSYM(LITERAL, code);
252
- if (code < 256) {
253
- zip->window[zip->window_posn++] = (unsigned char) code;
254
- FLUSH_IF_NEEDED;
255
- }
256
- else if (code == 256) {
257
- /* END OF BLOCK CODE: loop break point */
258
- break;
259
- }
260
- else {
261
- code -= 257; /* codes 257-285 are matches */
262
- if (code >= 29) return INF_ERR_LITCODE; /* codes 286-287 are illegal */
263
- READ_BITS_T(length, lit_extrabits[code]);
264
- length += lit_lengths[code];
265
-
266
- READ_HUFFSYM(DISTANCE, code);
267
- if (code > 30) return INF_ERR_DISTCODE;
268
- READ_BITS_T(distance, dist_extrabits[code]);
269
- distance += dist_offsets[code];
270
-
271
- /* match position is window position minus distance. If distance
272
- * is more than window position numerically, it must 'wrap
273
- * around' the frame size. */
274
- match_posn = ((distance > zip->window_posn) ? MSZIP_FRAME_SIZE : 0)
275
- + zip->window_posn - distance;
276
-
277
- /* copy match */
278
- if (length < 12) {
279
- /* short match, use slower loop but no loop setup code */
280
- while (length--) {
281
- zip->window[zip->window_posn++] = zip->window[match_posn++];
282
- match_posn &= MSZIP_FRAME_SIZE - 1;
283
- FLUSH_IF_NEEDED;
284
- }
285
- }
286
- else {
287
- /* longer match, use faster loop but with setup expense */
288
- unsigned char *runsrc, *rundest;
289
- do {
290
- this_run = length;
291
- if ((match_posn + this_run) > MSZIP_FRAME_SIZE)
292
- this_run = MSZIP_FRAME_SIZE - match_posn;
293
- if ((zip->window_posn + this_run) > MSZIP_FRAME_SIZE)
294
- this_run = MSZIP_FRAME_SIZE - zip->window_posn;
295
-
296
- rundest = &zip->window[zip->window_posn]; zip->window_posn += this_run;
297
- runsrc = &zip->window[match_posn]; match_posn += this_run;
298
- length -= this_run;
299
- while (this_run--) *rundest++ = *runsrc++;
300
- if (match_posn == MSZIP_FRAME_SIZE) match_posn = 0;
301
- FLUSH_IF_NEEDED;
302
- } while (length > 0);
303
- }
304
-
305
- } /* else (code >= 257) */
251
+ READ_HUFFSYM(LITERAL, code);
252
+ if (code < 256) {
253
+ zip->window[zip->window_posn++] = (unsigned char) code;
254
+ FLUSH_IF_NEEDED;
255
+ }
256
+ else if (code == 256) {
257
+ /* END OF BLOCK CODE: loop break point */
258
+ break;
259
+ }
260
+ else {
261
+ code -= 257; /* codes 257-285 are matches */
262
+ if (code >= 29) return INF_ERR_LITCODE; /* codes 286-287 are illegal */
263
+ READ_BITS_T(length, lit_extrabits[code]);
264
+ length += lit_lengths[code];
265
+
266
+ READ_HUFFSYM(DISTANCE, code);
267
+ if (code >= 30) return INF_ERR_DISTCODE;
268
+ READ_BITS_T(distance, dist_extrabits[code]);
269
+ distance += dist_offsets[code];
270
+
271
+ /* match position is window position minus distance. If distance
272
+ * is more than window position numerically, it must 'wrap
273
+ * around' the frame size. */
274
+ match_posn = ((distance > zip->window_posn) ? MSZIP_FRAME_SIZE : 0)
275
+ + zip->window_posn - distance;
276
+
277
+ /* copy match */
278
+ if (length < 12) {
279
+ /* short match, use slower loop but no loop setup code */
280
+ while (length--) {
281
+ zip->window[zip->window_posn++] = zip->window[match_posn++];
282
+ match_posn &= MSZIP_FRAME_SIZE - 1;
283
+ FLUSH_IF_NEEDED;
284
+ }
285
+ }
286
+ else {
287
+ /* longer match, use faster loop but with setup expense */
288
+ unsigned char *runsrc, *rundest;
289
+ do {
290
+ this_run = length;
291
+ if ((match_posn + this_run) > MSZIP_FRAME_SIZE)
292
+ this_run = MSZIP_FRAME_SIZE - match_posn;
293
+ if ((zip->window_posn + this_run) > MSZIP_FRAME_SIZE)
294
+ this_run = MSZIP_FRAME_SIZE - zip->window_posn;
295
+
296
+ rundest = &zip->window[zip->window_posn]; zip->window_posn += this_run;
297
+ runsrc = &zip->window[match_posn]; match_posn += this_run;
298
+ length -= this_run;
299
+ while (this_run--) *rundest++ = *runsrc++;
300
+ if (match_posn == MSZIP_FRAME_SIZE) match_posn = 0;
301
+ FLUSH_IF_NEEDED;
302
+ } while (length > 0);
303
+ }
304
+
305
+ } /* else (code >= 257) */
306
306
 
307
307
  } /* for(;;) -- break point at 'code == 256' */
308
308
  }
@@ -328,7 +328,7 @@ static int inflate(struct mszipd_stream *zip) {
328
328
  * is flushed, an error is raised.
329
329
  */
330
330
  static int mszipd_flush_window(struct mszipd_stream *zip,
331
- unsigned int data_flushed)
331
+ unsigned int data_flushed)
332
332
  {
333
333
  zip->bytes_output += data_flushed;
334
334
  if (zip->bytes_output > MSZIP_FRAME_SIZE) {
@@ -340,17 +340,18 @@ static int mszipd_flush_window(struct mszipd_stream *zip,
340
340
  }
341
341
 
342
342
  struct mszipd_stream *mszipd_init(struct mspack_system *system,
343
- struct mspack_file *input,
344
- struct mspack_file *output,
345
- int input_buffer_size,
346
- int repair_mode)
343
+ struct mspack_file *input,
344
+ struct mspack_file *output,
345
+ int input_buffer_size,
346
+ int repair_mode)
347
347
  {
348
348
  struct mszipd_stream *zip;
349
349
 
350
350
  if (!system) return NULL;
351
351
 
352
+ /* round up input buffer size to multiple of two */
352
353
  input_buffer_size = (input_buffer_size + 1) & -2;
353
- if (!input_buffer_size) return NULL;
354
+ if (input_buffer_size < 2) return NULL;
354
355
 
355
356
  /* allocate decompression state */
356
357
  if (!(zip = (struct mszipd_stream *) system->alloc(system, sizeof(struct mszipd_stream)))) {
@@ -426,19 +427,19 @@ int mszipd_decompress(struct mszipd_stream *zip, off_t out_bytes) {
426
427
  if ((error = inflate(zip))) {
427
428
  D(("inflate error %d", error))
428
429
  if (zip->repair_mode) {
429
- /* recover partially-inflated buffers */
430
- if (zip->bytes_output == 0 && zip->window_posn > 0) {
431
- zip->flush_window(zip, zip->window_posn);
432
- }
433
- zip->sys->message(NULL, "MSZIP error, %u bytes of data lost.",
434
- MSZIP_FRAME_SIZE - zip->bytes_output);
435
- for (i = zip->bytes_output; i < MSZIP_FRAME_SIZE; i++) {
436
- zip->window[i] = '\0';
437
- }
438
- zip->bytes_output = MSZIP_FRAME_SIZE;
430
+ /* recover partially-inflated buffers */
431
+ if (zip->bytes_output == 0 && zip->window_posn > 0) {
432
+ zip->flush_window(zip, zip->window_posn);
433
+ }
434
+ zip->sys->message(NULL, "MSZIP error, %u bytes of data lost.",
435
+ MSZIP_FRAME_SIZE - zip->bytes_output);
436
+ for (i = zip->bytes_output; i < MSZIP_FRAME_SIZE; i++) {
437
+ zip->window[i] = '\0';
438
+ }
439
+ zip->bytes_output = MSZIP_FRAME_SIZE;
439
440
  }
440
441
  else {
441
- return zip->error = (error > 0) ? error : MSPACK_ERR_DECRUNCH;
442
+ return zip->error = (error > 0) ? error : MSPACK_ERR_DECRUNCH;
442
443
  }
443
444
  }
444
445
  zip->o_ptr = &zip->window[0];
@@ -475,31 +476,31 @@ int mszipd_decompress_kwaj(struct mszipd_stream *zip) {
475
476
 
476
477
  /* unpack blocks until block_len == 0 */
477
478
  for (;;) {
478
- RESTORE_BITS;
479
-
480
- /* align to bytestream, read block_len */
481
- i = bits_left & 7; REMOVE_BITS(i);
482
- READ_BITS(block_len, 8);
483
- READ_BITS(i, 8); block_len |= i << 8;
484
-
485
- if (block_len == 0) break;
486
-
487
- /* read "CK" header */
488
- READ_BITS(i, 8); if (i != 'C') return MSPACK_ERR_DATAFORMAT;
489
- READ_BITS(i, 8); if (i != 'K') return MSPACK_ERR_DATAFORMAT;
490
-
491
- /* inflate block */
492
- zip->window_posn = 0;
493
- zip->bytes_output = 0;
494
- STORE_BITS;
495
- if ((error = inflate(zip))) {
496
- D(("inflate error %d", error))
497
- return zip->error = (error > 0) ? error : MSPACK_ERR_DECRUNCH;
498
- }
499
-
500
- /* write inflated block */
501
- if (zip->sys->write(zip->output, &zip->window[0], zip->bytes_output)
502
- != zip->bytes_output) return zip->error = MSPACK_ERR_WRITE;
479
+ RESTORE_BITS;
480
+
481
+ /* align to bytestream, read block_len */
482
+ i = bits_left & 7; REMOVE_BITS(i);
483
+ READ_BITS(block_len, 8);
484
+ READ_BITS(i, 8); block_len |= i << 8;
485
+
486
+ if (block_len == 0) break;
487
+
488
+ /* read "CK" header */
489
+ READ_BITS(i, 8); if (i != 'C') return MSPACK_ERR_DATAFORMAT;
490
+ READ_BITS(i, 8); if (i != 'K') return MSPACK_ERR_DATAFORMAT;
491
+
492
+ /* inflate block */
493
+ zip->window_posn = 0;
494
+ zip->bytes_output = 0;
495
+ STORE_BITS;
496
+ if ((error = inflate(zip))) {
497
+ D(("inflate error %d", error))
498
+ return zip->error = (error > 0) ? error : MSPACK_ERR_DECRUNCH;
499
+ }
500
+
501
+ /* write inflated block */
502
+ if (zip->sys->write(zip->output, &zip->window[0], zip->bytes_output)
503
+ != zip->bytes_output) return zip->error = MSPACK_ERR_WRITE;
503
504
  }
504
505
  return MSPACK_ERR_OK;
505
506
  }
@@ -27,6 +27,7 @@ struct msoab_compressor_p {
27
27
  struct msoab_decompressor_p {
28
28
  struct msoab_decompressor base;
29
29
  struct mspack_system *system;
30
+ int buf_size;
30
31
  /* todo */
31
32
  };
32
33
 
@@ -29,10 +29,15 @@
29
29
 
30
30
  /* prototypes */
31
31
  static int oabd_decompress(struct msoab_decompressor *self, const char *input,
32
- const char *output);
32
+ const char *output);
33
33
  static int oabd_decompress_incremental(struct msoab_decompressor *self,
34
- const char *input, const char *base,
35
- const char *output);
34
+ const char *input, const char *base,
35
+ const char *output);
36
+ static int oabd_param(struct msoab_decompressor *base, int param, int value);
37
+ static int copy_fh(struct mspack_system *sys, struct mspack_file *infh,
38
+ struct mspack_file *outfh, size_t bytes_to_copy,
39
+ unsigned char *buf, int buf_size);
40
+
36
41
 
37
42
  struct msoab_decompressor *
38
43
  mspack_create_oab_decompressor(struct mspack_system *sys)
@@ -45,7 +50,9 @@ struct msoab_decompressor *
45
50
  if ((self = (struct msoab_decompressor_p *) sys->alloc(sys, sizeof(struct msoab_decompressor_p)))) {
46
51
  self->base.decompress = &oabd_decompress;
47
52
  self->base.decompress_incremental = &oabd_decompress_incremental;
53
+ self->base.set_param = &oabd_param;
48
54
  self->system = sys;
55
+ self->buf_size = 4096;
49
56
  }
50
57
  return (struct msoab_decompressor *) self;
51
58
  }
@@ -94,7 +101,7 @@ static int oabd_sys_write (struct mspack_file *base_file, void *buf, int size)
94
101
  }
95
102
 
96
103
  static int oabd_decompress(struct msoab_decompressor *_self, const char *input,
97
- const char *output)
104
+ const char *output)
98
105
  {
99
106
  struct msoab_decompressor_p *self = (struct msoab_decompressor_p *) _self;
100
107
  struct mspack_system *sys;
@@ -132,17 +139,13 @@ static int oabd_decompress(struct msoab_decompressor *_self, const char *input,
132
139
  block_max = EndGetI32(&hdrbuf[oabhead_BlockMax]);
133
140
  target_size = EndGetI32(&hdrbuf[oabhead_TargetSize]);
134
141
 
135
- /* We use it for reading block headers too */
136
- if (block_max < oabblk_SIZEOF)
137
- block_max = oabblk_SIZEOF;
138
-
139
142
  outfh = sys->open(sys, output, MSPACK_SYS_OPEN_WRITE);
140
143
  if (!outfh) {
141
144
  ret = MSPACK_ERR_OPEN;
142
145
  goto out;
143
146
  }
144
147
 
145
- buf = sys->alloc(sys, block_max);
148
+ buf = sys->alloc(sys, self->buf_size);
146
149
  if (!buf) {
147
150
  ret = MSPACK_ERR_NOMEMORY;
148
151
  goto out;
@@ -178,79 +181,59 @@ static int oabd_decompress(struct msoab_decompressor *_self, const char *input,
178
181
  if (!blk_flags) {
179
182
  /* Uncompressed block */
180
183
  if (blk_dsize != blk_csize) {
181
- ret = MSPACK_ERR_DATAFORMAT;
182
- goto out;
183
- }
184
- if (sys->read(infh, buf, blk_dsize) != (int)blk_dsize) {
185
- ret = MSPACK_ERR_READ;
186
- goto out;
187
- }
188
- if (sys->write(outfh, buf, blk_dsize) != (int)blk_dsize) {
189
- ret = MSPACK_ERR_WRITE;
190
- goto out;
184
+ ret = MSPACK_ERR_DATAFORMAT;
185
+ goto out;
191
186
  }
187
+ ret = copy_fh(sys, infh, outfh, blk_dsize, buf, self->buf_size);
188
+ if (ret) goto out;
192
189
  } else {
193
190
  /* LZX compressed block */
194
191
  window_bits = 17;
195
192
 
196
193
  while (window_bits < 25 && (1U << window_bits) < blk_dsize)
197
- window_bits++;
194
+ window_bits++;
198
195
 
199
196
  in_ofh.available = blk_csize;
200
197
  out_ofh.crc = 0xffffffff;
201
198
 
202
199
  lzx = lzxd_init(&oabd_sys, (void *)&in_ofh, (void *)&out_ofh, window_bits,
203
- 0, 4096, blk_dsize, 1);
200
+ 0, self->buf_size, blk_dsize, 1);
204
201
  if (!lzx) {
205
- ret = MSPACK_ERR_NOMEMORY;
206
- goto out;
202
+ ret = MSPACK_ERR_NOMEMORY;
203
+ goto out;
207
204
  }
208
205
 
209
206
  ret = lzxd_decompress(lzx, blk_dsize);
210
207
  if (ret != MSPACK_ERR_OK)
211
- goto out;
208
+ goto out;
212
209
 
213
210
  lzxd_free(lzx);
214
211
  lzx = NULL;
215
212
 
216
213
  /* Consume any trailing padding bytes before the next block */
217
- while (in_ofh.available) {
218
- int count = block_max;
219
- if ((size_t)count > in_ofh.available)
220
- count = in_ofh.available;
221
-
222
- count = sys->read(infh, buf, count);
223
- if (count < 0) {
224
- ret = MSPACK_ERR_READ;
225
- goto out;
226
- }
227
- in_ofh.available -= count;
228
- }
214
+ ret = copy_fh(sys, infh, NULL, in_ofh.available, buf, self->buf_size);
215
+ if (ret) goto out;
229
216
 
230
217
  if (out_ofh.crc != blk_crc) {
231
- ret = MSPACK_ERR_CHECKSUM;
232
- goto out;
218
+ ret = MSPACK_ERR_CHECKSUM;
219
+ goto out;
233
220
  }
234
221
  }
235
222
  target_size -= blk_dsize;
236
223
  }
237
224
 
238
225
  out:
239
- if (lzx)
240
- lzxd_free(lzx);
241
- if (buf)
242
- sys->free(buf);
243
- if (outfh)
244
- sys->close(outfh);
245
- if (infh)
246
- sys->close(infh);
226
+ if (lzx) lzxd_free(lzx);
227
+ if (outfh) sys->close(outfh);
228
+ if (infh) sys->close(infh);
229
+ sys->free(buf);
247
230
 
248
231
  return ret;
249
232
  }
250
233
 
251
234
  static int oabd_decompress_incremental(struct msoab_decompressor *_self,
252
- const char *input, const char *base,
253
- const char *output)
235
+ const char *input, const char *base,
236
+ const char *output)
254
237
  {
255
238
  struct msoab_decompressor_p *self = (struct msoab_decompressor_p *) _self;
256
239
  struct mspack_system *sys;
@@ -305,7 +288,7 @@ static int oabd_decompress_incremental(struct msoab_decompressor *_self,
305
288
  goto out;
306
289
  }
307
290
 
308
- buf = sys->alloc(sys, block_max);
291
+ buf = sys->alloc(sys, self->buf_size);
309
292
  if (!buf) {
310
293
  ret = MSPACK_ERR_NOMEMORY;
311
294
  goto out;
@@ -334,7 +317,7 @@ static int oabd_decompress_incremental(struct msoab_decompressor *_self,
334
317
  blk_crc = EndGetI32(&buf[patchblk_CRC]);
335
318
 
336
319
  if (blk_dsize > block_max || blk_dsize > target_size ||
337
- blk_ssize > block_max) {
320
+ blk_ssize > block_max) {
338
321
  ret = MSPACK_ERR_DATAFORMAT;
339
322
  goto out;
340
323
  }
@@ -351,7 +334,7 @@ static int oabd_decompress_incremental(struct msoab_decompressor *_self,
351
334
  out_ofh.crc = 0xffffffff;
352
335
 
353
336
  lzx = lzxd_init(&oabd_sys, (void *)&in_ofh, (void *)&out_ofh, window_bits,
354
- 0, 4096, blk_dsize, 1);
337
+ 0, 4096, blk_dsize, 1);
355
338
  if (!lzx) {
356
339
  ret = MSPACK_ERR_NOMEMORY;
357
340
  goto out;
@@ -368,18 +351,8 @@ static int oabd_decompress_incremental(struct msoab_decompressor *_self,
368
351
  lzx = NULL;
369
352
 
370
353
  /* Consume any trailing padding bytes before the next block */
371
- while (in_ofh.available) {
372
- int count = block_max;
373
- if ((size_t)count > in_ofh.available)
374
- count = in_ofh.available;
375
-
376
- count = sys->read(infh, buf, count);
377
- if (count < 0) {
378
- ret = MSPACK_ERR_READ;
379
- goto out;
380
- }
381
- in_ofh.available -= count;
382
- }
354
+ ret = copy_fh(sys, infh, NULL, in_ofh.available, buf, self->buf_size);
355
+ if (ret) goto out;
383
356
 
384
357
  if (out_ofh.crc != blk_crc) {
385
358
  ret = MSPACK_ERR_CHECKSUM;
@@ -390,16 +363,41 @@ static int oabd_decompress_incremental(struct msoab_decompressor *_self,
390
363
  }
391
364
 
392
365
  out:
393
- if (lzx)
394
- lzxd_free(lzx);
395
- if (buf)
396
- sys->free(buf);
397
- if (outfh)
398
- sys->close(outfh);
399
- if (basefh)
400
- sys->close(basefh);
401
- if (infh)
402
- sys->close(infh);
366
+ if (lzx) lzxd_free(lzx);
367
+ if (outfh) sys->close(outfh);
368
+ if (basefh) sys->close(basefh);
369
+ if (infh) sys->close(infh);
370
+ sys->free(buf);
403
371
 
404
372
  return ret;
405
373
  }
374
+
375
+ static int copy_fh(struct mspack_system *sys, struct mspack_file *infh,
376
+ struct mspack_file *outfh, size_t bytes_to_copy,
377
+ unsigned char *buf, int buf_size)
378
+ {
379
+ while (bytes_to_copy) {
380
+ int run = buf_size;
381
+ if ((size_t) run > bytes_to_copy) {
382
+ run = (int) bytes_to_copy;
383
+ }
384
+ if (sys->read(infh, buf, run) != run) {
385
+ return MSPACK_ERR_READ;
386
+ }
387
+ if (outfh && sys->write(outfh, buf, run) != run) {
388
+ return MSPACK_ERR_WRITE;
389
+ }
390
+ bytes_to_copy -= run;
391
+ }
392
+ return MSPACK_ERR_OK;
393
+ }
394
+
395
+ static int oabd_param(struct msoab_decompressor *base, int param, int value) {
396
+ struct msoab_decompressor_p *self = (struct msoab_decompressor_p *) base;
397
+ if (self && param == MSOABD_PARAM_DECOMPBUF && value >= 16) {
398
+ /* must be at least 16 bytes (patchblk_SIZEOF, oabblk_SIZEOF) */
399
+ self->buf_size = value;
400
+ return MSPACK_ERR_OK;
401
+ }
402
+ return MSPACK_ERR_ARGS;
403
+ }
@@ -90,10 +90,10 @@ struct qtmd_stream {
90
90
  * - input_buffer_size is the number of bytes to use to store bitstream data.
91
91
  */
92
92
  extern struct qtmd_stream *qtmd_init(struct mspack_system *system,
93
- struct mspack_file *input,
94
- struct mspack_file *output,
95
- int window_bits,
96
- int input_buffer_size);
93
+ struct mspack_file *input,
94
+ struct mspack_file *output,
95
+ int window_bits,
96
+ int input_buffer_size);
97
97
 
98
98
  /* decompresses, or decompresses more of, a Quantum stream.
99
99
  *