@@ -28,8 +28,7 @@ int compress_all_at_once = 0;
28
28
29
29
struct Results
30
30
{
31
- uint32_t inlen, outlen;
32
- uint32_t inpos;
31
+ uint32_t inpos, inlen, outpos, outlen;
33
32
uint8_t *inbuf, *outbuf;
34
33
};
35
34
@@ -43,7 +42,7 @@ int ReadWriteCallback (const char *what, void *buf, int size, void *r_)
43
42
44
43
if (strequ (what," init" )) {
45
44
46
- r.inpos = r.outlen = 0 ;
45
+ r.inpos = r.outpos = 0 ;
47
46
return FREEARC_OK;
48
47
49
48
} else if (strequ (what," read" )) {
@@ -56,8 +55,10 @@ int ReadWriteCallback (const char *what, void *buf, int size, void *r_)
56
55
57
56
} else if (strequ (what," write" ) || strequ (what," quasiwrite" )) {
58
57
if (strequ (what," write" )) {
59
- memcpy (r.outbuf +r.outlen , buf, size);
60
- r.outlen += size;
58
+ if (r.outpos + size > r.outlen )
59
+ return 0 ;
60
+ memcpy (r.outbuf +r.outpos , buf, size);
61
+ r.outpos += size;
61
62
return size;
62
63
}
63
64
@@ -71,46 +72,6 @@ int ReadWriteCallback (const char *what, void *buf, int size, void *r_)
71
72
}
72
73
73
74
74
- // #define CHUNK_SIZE 10240
75
- // GetTime(start_ticks);
76
- // ReadWriteCallback("init", NULL, 0, &r);
77
- // ArithCoder<EOB_CODE> ari(ReadWriteCallback, &r, CHUNK_SIZE, CHUNK_SIZE, 256);
78
- // for (int i=0; i<size; i++)
79
- // {
80
- // if (i%CHUNK_SIZE == 0)
81
- // ari.flush();
82
- // ari.encode(inbuf[i]);
83
- // }
84
- // outlen = r.outlen;
85
- // Print_Time("ArithCoder", &ticksPerSecond, &start_ticks, size, outlen);
86
- //
87
- //
88
- // GetTime(start_ticks);
89
- // ReadWriteCallback("init", NULL, 0, &r);
90
- // HuffmanEncoder<EOB_CODE> huff(ReadWriteCallback, &r, CHUNK_SIZE, CHUNK_SIZE, 256);
91
- // for (int i=0; i<size; i++)
92
- // {
93
- // if (i%CHUNK_SIZE == 0)
94
- // huff.flush();
95
- // huff.encode(inbuf[i]);
96
- // }
97
- // outlen = r.outlen;
98
- // Print_Time("HuffmanEncoder", &ticksPerSecond, &start_ticks, size, outlen);
99
- //
100
- //
101
- // GetTime(start_ticks);
102
- // ReadWriteCallback("init", NULL, 0, &r);
103
- // HuffmanEncoderOrder1<256, EOB_CODE> huff1(ReadWriteCallback, &r, CHUNK_SIZE, CHUNK_SIZE, 256);
104
- // for (int i=0; i<size; i++)
105
- // {
106
- // if (i%CHUNK_SIZE == 0)
107
- // huff1.flush();
108
- // huff1.encode(inbuf[i-1], inbuf[i]);
109
- // }
110
- // outlen = r.outlen;
111
- // Print_Time("HuffmanEncoderO1", &ticksPerSecond, &start_ticks, size, outlen);
112
-
113
-
114
75
115
76
PackMethod second_Tornado_method[] =
116
77
// tables row hashsize matchfinder buffer parser hash3 shift update auxhash fast_bytes
@@ -124,14 +85,15 @@ PackMethod second_Tornado_method[] =
124
85
, { 7 , BITCODER, false , 1 , 4 *mb, NON_CACHING_MF, 32 *mb, GREEDY, 0 , 0 , 999 , 0 , 0 , 128 }
125
86
};
126
87
127
-
128
- uint32_t tor_compress (uint8_t method, uint8_t * inbuf, uint8_t * outbuf, uint32_t size )
88
+
89
+ uint32_t tor_compress (uint8_t method, uint8_t * inbuf, uint32_t inlen, uint8_t * outbuf, uint32_t outlen )
129
90
{
130
91
PackMethod m;
131
92
static Results r;
132
93
r.inbuf = inbuf;
133
94
r.outbuf = outbuf;
134
- r.inlen = size;
95
+ r.inlen = inlen;
96
+ r.outlen = outlen;
135
97
136
98
ReadWriteCallback (" init" , NULL , 0 , &r);
137
99
if (method >= 20 )
@@ -142,18 +104,19 @@ uint32_t tor_compress(uint8_t method, uint8_t* inbuf, uint8_t* outbuf, uint32_t
142
104
if (r.inlen >= 0 )
143
105
m.buffer = mymin (m.buffer , r.inlen +LOOKAHEAD*2 );
144
106
int result = tor_compress (m, ReadWriteCallback, &r, NULL , -1 );
145
- return r.outlen ;
107
+ return r.outpos ;
146
108
}
147
109
148
- uint32_t tor_decompress (uint8_t * inbuf, uint8_t * outbuf, uint32_t size )
110
+ uint32_t tor_decompress (uint8_t * inbuf, uint32_t inlen, uint8_t * outbuf, uint32_t outlen )
149
111
{
150
112
static Results r;
151
113
r.inbuf = inbuf;
152
114
r.outbuf = outbuf;
153
- r.inlen = size;
115
+ r.inlen = inlen;
116
+ r.outlen = outlen;
154
117
155
118
ReadWriteCallback (" init" , NULL , 0 , &r);
156
119
int result = tor_decompress (ReadWriteCallback, &r, NULL , -1 );
157
120
ReadWriteCallback (" done" , NULL , 0 , &r);
158
- return r.outlen ;
121
+ return r.outpos ;
159
122
}
0 commit comments