The R Project SVN R

Rev

Rev 55994 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 55994 Rev 63230
Line 24... Line 24...
24
		SEQ_UNCOMPRESSED_SIZE,
24
		SEQ_UNCOMPRESSED_SIZE,
25
		SEQ_CODER_INIT,
25
		SEQ_CODER_INIT,
26
		SEQ_CODE,
26
		SEQ_CODE,
27
	} sequence;
27
	} sequence;
28
 
28
 
-
 
29
	/// If true, reject files that are unlikely to be .lzma files.
-
 
30
	/// If false, more non-.lzma files get accepted and will give
-
 
31
	/// LZMA_DATA_ERROR either immediately or after a few output bytes.
-
 
32
	bool picky;
-
 
33
 
29
	/// Position in the header fields
34
	/// Position in the header fields
30
	size_t pos;
35
	size_t pos;
31
 
36
 
32
	/// Uncompressed size decoded from the header
37
	/// Uncompressed size decoded from the header
33
	lzma_vli uncompressed_size;
38
	lzma_vli uncompressed_size;
Line 66... Line 71...
66
	case SEQ_DICTIONARY_SIZE:
71
	case SEQ_DICTIONARY_SIZE:
67
		coder->options.dict_size
72
		coder->options.dict_size
68
				|= (size_t)(in[*in_pos]) << (coder->pos * 8);
73
				|= (size_t)(in[*in_pos]) << (coder->pos * 8);
69
 
74
 
70
		if (++coder->pos == 4) {
75
		if (++coder->pos == 4) {
71
			if (coder->options.dict_size != UINT32_MAX) {
76
			if (coder->picky && coder->options.dict_size
-
 
77
					!= UINT32_MAX) {
72
				// A hack to ditch tons of false positives:
78
				// A hack to ditch tons of false positives:
73
				// We allow only dictionary sizes that are
79
				// We allow only dictionary sizes that are
74
				// 2^n or 2^n + 2^(n-1). LZMA_Alone created
80
				// 2^n or 2^n + 2^(n-1). LZMA_Alone created
75
				// only files with 2^n, but accepts any
81
				// only files with 2^n, but accepts any
76
				// dictionary size. If someone complains, this
-
 
77
				// will be reconsidered.
82
				// dictionary size.
78
				uint32_t d = coder->options.dict_size - 1;
83
				uint32_t d = coder->options.dict_size - 1;
79
				d |= d >> 2;
84
				d |= d >> 2;
80
				d |= d >> 3;
85
				d |= d >> 3;
81
				d |= d >> 4;
86
				d |= d >> 4;
82
				d |= d >> 8;
87
				d |= d >> 8;
Line 101... Line 106...
101
		if (++coder->pos < 8)
106
		if (++coder->pos < 8)
102
			break;
107
			break;
103
 
108
 
104
		// Another hack to ditch false positives: Assume that
109
		// Another hack to ditch false positives: Assume that
105
		// if the uncompressed size is known, it must be less
110
		// if the uncompressed size is known, it must be less
106
		// than 256 GiB. Again, if someone complains, this
111
		// than 256 GiB.
107
		// will be reconsidered.
112
		if (coder->picky
108
		if (coder->uncompressed_size != LZMA_VLI_UNKNOWN
113
				&& coder->uncompressed_size != LZMA_VLI_UNKNOWN
109
				&& coder->uncompressed_size
114
				&& coder->uncompressed_size
110
					>= (LZMA_VLI_C(1) << 38))
115
					>= (LZMA_VLI_C(1) << 38))
111
			return LZMA_FORMAT_ERROR;
116
			return LZMA_FORMAT_ERROR;
112
 
117
 
113
		// Calculate the memory usage so that it is ready
118
		// Calculate the memory usage so that it is ready
Line 187... Line 192...
187
}
192
}
188
 
193
 
189
 
194
 
190
extern lzma_ret
195
extern lzma_ret
191
lzma_alone_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
196
lzma_alone_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
192
		uint64_t memlimit)
197
		uint64_t memlimit, bool picky)
193
{
198
{
194
	lzma_next_coder_init(&lzma_alone_decoder_init, next, allocator);
199
	lzma_next_coder_init(&lzma_alone_decoder_init, next, allocator);
195
 
200
 
196
	if (memlimit == 0)
201
	if (memlimit == 0)
197
		return LZMA_PROG_ERROR;
202
		return LZMA_PROG_ERROR;
Line 206... Line 211...
206
		next->memconfig = &alone_decoder_memconfig;
211
		next->memconfig = &alone_decoder_memconfig;
207
		next->coder->next = LZMA_NEXT_CODER_INIT;
212
		next->coder->next = LZMA_NEXT_CODER_INIT;
208
	}
213
	}
209
 
214
 
210
	next->coder->sequence = SEQ_PROPERTIES;
215
	next->coder->sequence = SEQ_PROPERTIES;
-
 
216
	next->coder->picky = picky;
211
	next->coder->pos = 0;
217
	next->coder->pos = 0;
212
	next->coder->options.dict_size = 0;
218
	next->coder->options.dict_size = 0;
213
	next->coder->options.preset_dict = NULL;
219
	next->coder->options.preset_dict = NULL;
214
	next->coder->options.preset_dict_size = 0;
220
	next->coder->options.preset_dict_size = 0;
215
	next->coder->uncompressed_size = 0;
221
	next->coder->uncompressed_size = 0;
Line 221... Line 227...
221
 
227
 
222
 
228
 
223
extern LZMA_API(lzma_ret)
229
extern LZMA_API(lzma_ret)
224
lzma_alone_decoder(lzma_stream *strm, uint64_t memlimit)
230
lzma_alone_decoder(lzma_stream *strm, uint64_t memlimit)
225
{
231
{
226
	lzma_next_strm_init(lzma_alone_decoder_init, strm, memlimit);
232
	lzma_next_strm_init(lzma_alone_decoder_init, strm, memlimit, false);
227
 
233
 
228
	strm->internal->supported_actions[LZMA_RUN] = true;
234
	strm->internal->supported_actions[LZMA_RUN] = true;
229
	strm->internal->supported_actions[LZMA_FINISH] = true;
235
	strm->internal->supported_actions[LZMA_FINISH] = true;
230
 
236
 
231
	return LZMA_OK;
237
	return LZMA_OK;