Parolin 0.7.9 6796
Console (soon DLLs) to do a tar like job
Loading...
Searching...
No Matches
gzip2_decoder_mt_z.c
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
3 #2023 X March 21 19:50 PM Brasília Time
4
5* *
6* Licensa de Copia (C) <2023> <Aurora Boreal> *
7* *
8* Este programa e software livre: voce pode redistribuir isto e/ou *
9* modificar isto sobre os termos do GNU Licensa Geral Pública como 25
10* publicado pela Fundacao de Software Livre, tanto a versão 3 da *
11* Licensa, ou (dependendo da sua opcao) qualquer versao posterior. *
12* *
13* Este programa e distribuido na esperanca que isto vai ser util, *
14* mas SEM QUALQUER GARANTIA; sem ate mesmo a implicada garantia de *
15* COMERCIALIZAcaO ou CABIMENTO PARA UM FIM PARTICULAR. Veja a *
16* Licensa Geral Publica para mais detalhes. *
17* *
18* Você deve ter recebido uma cópia da LICENSA GERAL PUBLICA e a GNU *
19* Licensa Publica Menor junto com este programa *
20* Se não, veja <http://www.gnu.org/licenses/>. *
21* *
22* Suporte: sourceforge.net github.com *
23* *
24* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
25
26* Pereira: arsoftware25@gmail.com ricardo@arsoftware.net.br *
27* xcx: arsoftware10@gmail.com charli@arsoftware.net.br *
28 Yasmin: yasmin@arsoftware.net.br *
29 pereira1001@users.sourceforge.net
30 */
31
32
33#define CHUNK 131072 /* to never change again, or until someone change their mind... \
34at least it is better than 0x1000 (faster than) */
37 __attribute__((unused)) FILE *dest,
38 __attribute__((unused)) my_thread_struct_z *amanda)
39{
40 char signature_z[5] = "AR__";
41 int64_t remaining_z;
42 __int64 totalbytes = 0;
43 int64_t infile_remaining;
44 int done = 0;
45 int ret_z = 0;
46 int retvalue = 0;
47 ar_data ar;
48 char *buffer = malloc(CHUNK);
49 char *out = malloc(CHUNK);
50 z_stream strm;
51
52 pedro_dprintf(0, "gzip2 decoder multi-thread\n");
53 // exit(32);
54 assert(NULL == dest);
55
56 memset(&strm, 0, sizeof(strm));
57
58 pauseflag__5 = 0;
59 cancelflag__5 = 0;
60
61 //exit(27);
62
63 strm.zalloc = Z_NULL;
64 strm.zfree = Z_NULL;
65 strm.opaque = Z_NULL;
66 strm.avail_in = 0;
67 strm.next_in = Z_NULL;
68
69 signature_z[3] = '_' - 1; //gzip2 signature
70
71 if (-1 == signature_z[3]) //to make the compiler happy
72 {
73 pedro_dprintf(-1, "Test...\n");
74 }
75
76 ret_z = inflateInit(&strm);
77
78 assert(ret_z == Z_OK);
79
80 char *sha51_ptr = NULL;
81 char sha512_temp_k[SHA512_DIGEST_LENGTH];
82
83 sha51_ptr = sha512_init_k();
84
85 amanda->size_of_input_file_copy_z = amanda->size_of_input_file_copy_z + sizeof(int64_t) + sizeof(ar);
86 amanda->size_of_input_file_z = amanda->size_of_input_file_copy_z;
87 totalbytes = amanda->size_of_input_file_z;
88
89 //remaining_z = amanda->size_of_input_file_z;
90
91 pedro_dprintf(-1, "seek to %lld\n", amanda->offset_z);
92
93 assert(0 <= (int64_t)amanda->offset_z - (int64_t)sizeof(int64_t) - (int64_t)sizeof(ar));
94
95 if (
96 0 != _fseeki64(
97 amanda->input_file,
98 amanda->offset_z - sizeof(int64_t) - sizeof(ar),
99 SEEK_SET))
100 {
101 amanda->retvalue = 403; //File access error
102 goto saida_12_march_2021__09_32_18;
103 }
104
105 memset(&ar, 0, sizeof(ar));
106 ret_z = fread(&ar, 1, (int)(min((uint64_t)sizeof(ar), (uint64_t)(amanda->size_of_input_file_copy_z))), amanda->input_file);
107
108 if (ret_z != sizeof(ar))
109 {
110
111 retvalue = 9;
112 goto saida_12_march_2021__09_32_18;
113 }
114 amanda->size_of_input_file_copy_z -= ret_z;
115 if (0 != memcmp(ar.string, signature_z, 4))
116 {
117
118 retvalue = 90;
119 goto saida_12_march_2021__09_32_18;
120 }
121
122 ret_z = fread(&remaining_z, 1, (int)(min((uint64_t)sizeof(remaining_z), (uint64_t)(amanda->size_of_input_file_copy_z))), amanda->input_file);
123
124 if (sizeof(remaining_z) != ret_z)
125 {
126 retvalue = 9;
127 goto saida_12_march_2021__09_32_18;
128 }
129
130 amanda->size_of_input_file_copy_z -= ret_z;
131
132 if (0 > remaining_z)
133 {
134 retvalue = 500;
135 goto saida_12_march_2021__09_32_18;
136 }
137
138 if (amanda->size_of_input_file_copy_z != remaining_z)
139 {
140 retvalue = 500;
141 goto saida_12_march_2021__09_32_18;
142 }
143
144 /*
145
146 commented and kept for historical reasons, this is
147 one of the most used undetected buggy code
148 that we saw in 24 years...
149
150 for (;; )
151 {
152 while (*(amanda->intpause))
153 {
154
155 Sleep (50);
156
157 if (*(amanda->intcancel))
158 {
159 amanda->internal_error_arp = 119;
160 goto saida;
161 }
162
163 }
164
165 if (*(amanda->intcancel))
166 {
167 amanda-> internal_error_arp = 119;
168 goto saida;
169 }
170
171 ret_z = fread (buffer, 1, min(CHUNK, remaining_z), amanda->input_file);
172
173 if(0 > ret_z)
174 {
175 retvalue = 501;
176 goto saida;
177 }
178
179 if ((0 == ret_z) || done)
180 {
181
182 goto saida;
183
184 }
185
186 remaining_z -= ret_z;
187 *(amanda->bytes_read_z) += ret_z;
188 bytesread = bytesread + ret_z;
189
190 strm.avail_in = ret_z;
191
192 strm.next_in = (void *) buffer;
193
194devolta:
195
196 strm.avail_out = CHUNK;
197 strm.next_out = (void *) out;
198
199 ret2_z = inflate (&strm, Z_NO_FLUSH);
200
201 bytestosave = bytestosave + (CHUNK - strm.avail_out);
202
203 writebytes = CHUNK - strm.avail_out; //existe um erro aqui
204
205 if (writebytes > 0)
206 {
207 sha512_update_k(sha51_ptr, (void *) out, writebytes );
208 ret_z = fwrite_z (out, 1, writebytes, amanda->dest);
209 if (writebytes != ret_z )
210 {
211 amanda->internal_error_arp = 6;
212 retvalue = 14;
213 goto saida;
214 }
215 }
216
217 switch (ret2_z)
218 {
219
220 case Z_OK:
221
222 if (strm.avail_in)
223 {
224 goto devolta;
225 }
226
227 if(0==strm.avail_out)
228 {
229 goto devolta;
230 }
231
232 break;
233
234 case Z_STREAM_END:
235
236 done = 1;
237 break;
238
239 case Z_NEED_DICT:
240
241 assert (0);
242 break;
243
244 case Z_STREAM_ERROR:
245
246 assert (0);
247 break;
248
249 case Z_MEM_ERROR:
250
251 assert (0);
252 break;
253
254 case Z_DATA_ERROR:
255
256 retvalue = 21;
257 goto saida;
258
259 break;
260
261 case Z_BUF_ERROR:
262
263 assert (0);//here the decoding error appear...only for some files
264 break;
265
266 default:
267
268 assert (0);
269 break;
270
271 }
272
273 }
274
275saida:
276*/
277
278 totalbytes = remaining_z;
279 strm.next_in = (void *)buffer;
280 strm.avail_in = 0;
281 strm.next_out = (void *)out;
282 strm.avail_out = CHUNK;
283 infile_remaining = totalbytes;
284 for (;;)
285 {
286 while (*(amanda->intpause))
287 {
288
289 Sleep(50);
290
291 if (*(amanda->intcancel))
292 {
293 amanda->internal_error_arp = 119;
294 goto saida_12_march_2021__09_32_18;
295 }
296 }
297
298 if (*(amanda->intcancel))
299 {
300 amanda->internal_error_arp = 119;
301 goto saida_12_march_2021__09_32_18;
302 }
303
304 int status;
305
306 if (!strm.avail_in)
307 {
308 // Input buffer is empty, so read more bytes from input file.
309 int64_t n_z = (int64_t)(min((uint64_t)CHUNK, (uint64_t)infile_remaining));
310
311 if ((size_t)fread(buffer, 1, n_z, amanda->input_file) != (size_t)n_z)
312 {
313 retvalue = 9;
314 goto saida_12_march_2021__09_32_18;
315 }
316
317 strm.next_in = (void *)buffer;
318 strm.avail_in = n_z;
319 infile_remaining -= n_z;
320 *(amanda->bytes_read_z) += n_z;
321 }
322
323 status = inflate(&strm, Z_SYNC_FLUSH);
324
325 if ((status == Z_STREAM_END) || (!strm.avail_out))
326 {
327 // Output buffer is full, or decompression is done, so write buffer to output file.
328 int n_z = CHUNK - strm.avail_out;
329
330 if (fwrite(out, 1, n_z, amanda->dest) != (size_t)n_z)
331 {
332 amanda->internal_error_arp = 6;
333 retvalue = 14;
334 goto saida_12_march_2021__09_32_18;
335 }
336
337 sha512_update_k(sha51_ptr, (void *)out, n_z);
338
339 strm.next_out = (void *)out;
340 strm.avail_out = CHUNK;
341 }
342
343 if (status == Z_STREAM_END)
344 {
345 done = 1;
346 break;
347 }
348 else if (status != Z_OK)
349 {
350 //aqui
351
352 switch (status)
353 {
354 case Z_STREAM_END:
355 strcpy(zlib_error_z, "Z_STREAM_END");
356 zlib_int_error_z = 528;
357 break;
358 case Z_NEED_DICT:
359 strcpy(zlib_error_z, "Z_NEED_DICT");
360 zlib_int_error_z = 529;
361 break;
362 case Z_STREAM_ERROR:
363 strcpy(zlib_error_z, "Z_STREAM_ERROR");
364 zlib_int_error_z = 530;
365 break;
366 case Z_MEM_ERROR:
367 strcpy(zlib_error_z, "Z_MEM_ERROR");
368 zlib_int_error_z = 531;
369 break;
370 case Z_DATA_ERROR:
371 strcpy(zlib_error_z, "Z_DATA_ERROR");
372 zlib_int_error_z = 532;
373 break;
374 case Z_BUF_ERROR: //isso da erro
375 strcpy(zlib_error_z, "Z_BUF_ERROR");
376 zlib_int_error_z = 533;
377 break;
378 default:
379 strcpy(zlib_error_z, "unknown");
380 zlib_int_error_z = 534;
381 break;
382 }
383
384 pedro_dprintf(2, "inflate() failed with status %$ !\n", zlib_error_z);
385 retvalue = zlib_int_error_z;
386 goto saida_12_march_2021__09_32_18;
387 //break; also work here
388 }
389 }
390
391saida_12_march_2021__09_32_18:;
392
393 if ((0 == retvalue) && ((int64_t)totalbytes > (int64_t)sizeof(ar)))
394 {
395
396 sha512_final_k(sha51_ptr, (void *)sha512_temp_k);
397
398 if (0 != memcmp(sha512_temp_k, ar.sha512_k, SHA512_DIGEST_LENGTH))
399 {
400 pedro_dprintf(-1, "erro 20");
401 retvalue = 20;
402 }
403 }
404
405 if ((int64_t)totalbytes > (int64_t)sizeof(ar))
406 {
407
408 if ((0 == done) && (0 == retvalue))
409 {
410
411 retvalue = 18;
412 }
413 }
414
415 (void)inflateEnd(&strm);
416
417 if (cancelflag__5)
418 {
419 retvalue = 19;
420 }
421 *(amanda->bytes_read_z) = totalbytes_z__5;
422 free(buffer);
423 free(out);
424
425 pedro_dprintf(-1, "erro que deu interno %d\n", retvalue);
426
427 return retvalue;
428}
void pedro_dprintf(int amanda_level, char *format,...)
Definition pedro.c:43
#define SHA512_DIGEST_LENGTH
Definition bzip3.c:41
int64_t totalbytes_z__5
Definition zlib.c:301
#define CHUNK
Definition gzip2_decoder_mt_z.c:33
int zuncompress_sha512_k_mt_decoding_multi_thread_z__5(__attribute__((unused)) FILE *source, __attribute__((unused)) FILE *dest, __attribute__((unused)) my_thread_struct_z *amanda)
Definition gzip2_decoder_mt_z.c:35
int ZEXPORT inflate(z_streamp strm, int flush)
Definition inflate.c:666
int ZEXPORT inflateEnd(z_streamp strm)
Definition inflate.c:1416
#define assert(condition)
Definition lz4.c:273
const char * source
Definition lz4.h:808
char * dest
Definition lz4.h:806
#define __attribute__(unused_ric_since_2004)
Definition main_cr.c:84
#define min(a, b)
Definition compress42.c:304
Definition stdio_v3.h:12
unsigned char sha512_k[SHA512_DIGEST_LENGTH]
Definition zlib.c:105
char string[4]
Definition stdio_v3.h:13
Definition stdio_v3.h:23
Definition zlib.h:86
Bytef * next_out
Definition zlib.h:91
alloc_func zalloc
Definition zlib.h:98
free_func zfree
Definition zlib.h:99
uInt avail_in
Definition zlib.h:88
uInt avail_out
Definition zlib.h:92
z_const Bytef * next_in
Definition zlib.h:87
voidpf opaque
Definition zlib.h:100
int __stdcall status(int newvalue)
Definition bzip2dll.c:513
void sha512_update_k(void *ctx, unsigned char *buffer_k, unsigned int len_k)
Definition sha512_k.c:835
void * sha512_init_k()
Definition sha512_k.c:827
void sha512_final_k(void *ctx, unsigned char *array_digest_64_bytes)
Definition sha512_k.c:843
#define SEEK_SET
Definition zconf.h:498
uint cancelflag__5
Definition dll.c:196
uint pauseflag__5
Definition dll.c:195
char zlib_error_z[1024]
Definition zlib.c:125
int zlib_int_error_z
Definition zlib.c:126
const lzma_allocator const uint8_t size_t uint8_t * out
Definition block.h:528
#define NULL
Definition getopt1.c:37
#define Z_NEED_DICT
Definition zlib.h:179
#define Z_BUF_ERROR
Definition zlib.h:184
#define Z_STREAM_END
Definition zlib.h:178
#define Z_OK
Definition zlib.h:177
#define Z_DATA_ERROR
Definition zlib.h:182
#define Z_SYNC_FLUSH
Definition zlib.h:170
#define Z_STREAM_ERROR
Definition zlib.h:181
#define Z_NULL
Definition zlib.h:212
#define inflateInit(strm)
Definition zlib.h:1795
#define Z_MEM_ERROR
Definition zlib.h:183
totalbytes
Definition zlib_interface.c:43
signature_z[3]
Definition zlib_interface.c:37