The R Project SVN R

Rev

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

Rev 53508 Rev 55994
Line 224... Line 224...
224
extern LZMA_API(lzma_ret)
224
extern LZMA_API(lzma_ret)
225
lzma_block_buffer_encode(lzma_block *block, lzma_allocator *allocator,
225
lzma_block_buffer_encode(lzma_block *block, lzma_allocator *allocator,
226
		const uint8_t *in, size_t in_size,
226
		const uint8_t *in, size_t in_size,
227
		uint8_t *out, size_t *out_pos, size_t out_size)
227
		uint8_t *out, size_t *out_pos, size_t out_size)
228
{
228
{
229
	// Sanity checks
229
	// Validate the arguments.
230
	if (block == NULL || block->filters == NULL
-
 
231
			|| (in == NULL && in_size != 0) || out == NULL
230
	if (block == NULL || (in == NULL && in_size != 0) || out == NULL
232
			|| out_pos == NULL || *out_pos > out_size)
231
			|| out_pos == NULL || *out_pos > out_size)
233
		return LZMA_PROG_ERROR;
232
		return LZMA_PROG_ERROR;
234
 
233
 
-
 
234
	// The contents of the structure may depend on the version so
235
	// Check the version field.
235
	// check the version before validating the contents of *block.
236
	if (block->version != 0)
236
	if (block->version != 0)
237
		return LZMA_OPTIONS_ERROR;
237
		return LZMA_OPTIONS_ERROR;
238
 
238
 
-
 
239
	if ((unsigned int)(block->check) > LZMA_CHECK_ID_MAX
-
 
240
			|| block->filters == NULL)
-
 
241
		return LZMA_PROG_ERROR;
-
 
242
 
-
 
243
	if (!lzma_check_is_supported(block->check))
-
 
244
		return LZMA_UNSUPPORTED_CHECK;
-
 
245
 
239
	// Size of a Block has to be a multiple of four, so limit the size
246
	// Size of a Block has to be a multiple of four, so limit the size
240
	// here already. This way we don't need to check it again when adding
247
	// here already. This way we don't need to check it again when adding
241
	// Block Padding.
248
	// Block Padding.
242
	out_size -= (out_size - *out_pos) & 3;
249
	out_size -= (out_size - *out_pos) & 3;
243
 
250
 
244
	// Get the size of the Check field.
251
	// Get the size of the Check field.
245
	const size_t check_size = lzma_check_size(block->check);
252
	const size_t check_size = lzma_check_size(block->check);
246
	if (check_size == UINT32_MAX)
253
	assert(check_size != UINT32_MAX);
247
		return LZMA_PROG_ERROR;
-
 
248
 
254
 
249
	// Reserve space for the Check field.
255
	// Reserve space for the Check field.
250
	if (out_size - *out_pos <= check_size)
256
	if (out_size - *out_pos <= check_size)
251
		return LZMA_BUF_ERROR;
257
		return LZMA_BUF_ERROR;
252
 
258