1 // SPDX-License-Identifier: 0BSD
2 
3 ///////////////////////////////////////////////////////////////////////////////
4 //
5 /// \file       filter_flags_decoder.c
6 /// \brief      Decodes a Filter Flags field
7 //
8 //  Author:     Lasse Collin
9 //
10 ///////////////////////////////////////////////////////////////////////////////
11 
12 #include "filter_decoder.h"
13 
14 
15 extern LZMA_API(lzma_ret)
lzma_filter_flags_decode(lzma_filter * filter,const lzma_allocator * allocator,const uint8_t * in,size_t * in_pos,size_t in_size)16 lzma_filter_flags_decode(
17 		lzma_filter *filter, const lzma_allocator *allocator,
18 		const uint8_t *in, size_t *in_pos, size_t in_size)
19 {
20 	// Set the pointer to NULL so the caller can always safely free it.
21 	filter->options = NULL;
22 
23 	// Filter ID
24 	return_if_error(lzma_vli_decode(&filter->id, NULL,
25 			in, in_pos, in_size));
26 
27 	if (filter->id >= LZMA_FILTER_RESERVED_START)
28 		return LZMA_DATA_ERROR;
29 
30 	// Size of Properties
31 	lzma_vli props_size;
32 	return_if_error(lzma_vli_decode(&props_size, NULL,
33 			in, in_pos, in_size));
34 
35 	// Filter Properties
36 	if (in_size - *in_pos < props_size)
37 		return LZMA_DATA_ERROR;
38 
39 	const lzma_ret ret = lzma_properties_decode(
40 			filter, allocator, in + *in_pos, props_size);
41 
42 	*in_pos += props_size;
43 
44 	return ret;
45 }
46