Rizin
unix-like reverse engineering framework and cli tools
block_header_encoder.c File Reference

Encodes Block Header for .xz files. More...

#include "common.h"
#include "check.h"

Go to the source code of this file.

Functions

 LZMA_API (lzma_ret)
 

Detailed Description

Encodes Block Header for .xz files.

Definition in file block_header_encoder.c.

Function Documentation

◆ LZMA_API()

LZMA_API ( lzma_ret  )

Definition at line 17 of file block_header_encoder.c.

19 {
20  if (block->version > 1)
21  return LZMA_OPTIONS_ERROR;
22 
23  // Block Header Size + Block Flags + CRC32.
24  uint32_t size = 1 + 1 + 4;
25 
26  // Compressed Size
27  if (block->compressed_size != LZMA_VLI_UNKNOWN) {
28  const uint32_t add = lzma_vli_size(block->compressed_size);
29  if (add == 0 || block->compressed_size == 0)
30  return LZMA_PROG_ERROR;
31 
32  size += add;
33  }
34 
35  // Uncompressed Size
36  if (block->uncompressed_size != LZMA_VLI_UNKNOWN) {
37  const uint32_t add = lzma_vli_size(block->uncompressed_size);
38  if (add == 0)
39  return LZMA_PROG_ERROR;
40 
41  size += add;
42  }
43 
44  // List of Filter Flags
45  if (block->filters == NULL || block->filters[0].id == LZMA_VLI_UNKNOWN)
46  return LZMA_PROG_ERROR;
47 
48  for (size_t i = 0; block->filters[i].id != LZMA_VLI_UNKNOWN; ++i) {
49  // Don't allow too many filters.
50  if (i == LZMA_FILTERS_MAX)
51  return LZMA_PROG_ERROR;
52 
53  uint32_t add;
54  return_if_error(lzma_filter_flags_size(&add,
55  block->filters + i));
56 
57  size += add;
58  }
59 
60  // Pad to a multiple of four bytes.
61  block->header_size = (size + 3) & ~UINT32_C(3);
62 
63  // NOTE: We don't verify that the encoded size of the Block stays
64  // within limits. This is because it is possible that we are called
65  // with exaggerated Compressed Size (e.g. LZMA_VLI_MAX) to reserve
66  // space for Block Header, and later called again with lower,
67  // real values.
68 
69  return LZMA_OK;
70 }
lzma_index ** i
Definition: index.h:629
#define NULL
Definition: cris-opc.c:27
#define LZMA_FILTERS_MAX
Maximum number of filters in a chain.
Definition: filter.h:26
voidpf void uLong size
Definition: ioapi.h:138
unsigned int uint32_t
Definition: sftypes.h:29
#define UINT32_C(val)
#define return_if_error(expr)
Return if expression doesn't evaluate to LZMA_OK.
Definition: common.h:278
#define LZMA_VLI_UNKNOWN
VLI value to denote that the value is unknown.
Definition: vli.h:39
@ LZMA_PROG_ERROR
Programming error.
Definition: base.h:218
@ LZMA_OPTIONS_ERROR
Invalid or unsupported options.
Definition: base.h:160
@ LZMA_OK
Operation completed successfully.
Definition: base.h:58
static int add(char *argv[])
Definition: ziptool.c:84

References add(), lzma_block::compressed_size, lzma_block::filters, lzma_block::header_size, i, lzma_filter::id, LZMA_FILTERS_MAX, LZMA_OK, LZMA_OPTIONS_ERROR, LZMA_PROG_ERROR, LZMA_VLI_UNKNOWN, NULL, return_if_error, UINT32_C, lzma_block::uncompressed_size, and lzma_block::version.