Debian Codegraph @

c/dec/decode.c

raw symbols SCIP
1 /* Copyright 2013 Google Inc. All Rights Reserved.
2
3 Distributed under MIT license.
4 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 */
6
7 #include <brotli/decode.h>cxx . . $ `<file>/c/include/brotli/decode.h`/
8
9 #include "../common/constants.h"cxx . . $ `<file>/c/common/constants.h`/
10 #include "../common/context.h"cxx . . $ `<file>/c/common/context.h`/
11 #include "../common/dictionary.h"cxx . . $ `<file>/c/common/dictionary.h`/
12 #include "../common/platform.h"cxx . . $ `<file>/c/common/platform.h`/
13 #include "../common/shared_dictionary_internal.h"cxx . . $ `<file>/c/common/shared_dictionary_internal.h`/
14 #include "../common/transform.h"cxx . . $ `<file>/c/common/transform.h`/
15 #include "../common/version.h"cxx . . $ `<file>/c/common/version.h`/
16 #include "bit_reader.h"cxx . . $ `<file>/c/dec/bit_reader.h`/
17 #include "huffman.h"cxx . . $ `<file>/c/dec/huffman.h`/
18 #include "prefix.h"cxx . . $ `<file>/c/dec/prefix.h`/
19 #include "state.h"cxx . . $ `<file>/c/dec/state.h`/
20 #include "static_init.h"cxx . . $ `<file>/c/dec/static_init.h`/
21
22 #if defined(BROTLI_TARGET_NEON)
23 #include <arm_neon.h>
24 #endif
25
26 #if defined(__cplusplus) || defined(c_plusplus)
27 extern "C" {
28 #endif
29
30 #define BROTLI_FAILUREcxx . . $ `c/dec/decode.c:30:9`!(CODE) (BROTLI_DUMPcxx . . $ `c/common/platform.h:487:9`!(), CODE)
31
32 #define BROTLI_LOG_UINTcxx . . $ `c/dec/decode.c:32:9`!(name) \
33 BROTLI_LOGcxx . . $ `c/common/platform.h:465:9`!(("[%s] %s = %lu\n", __func__, #name, (unsigned long)(name)))
34 #define BROTLI_LOG_ARRAY_INDEXcxx . . $ `c/dec/decode.c:34:9`!(array_name, idx) \
35 BROTLI_LOGcxx . . $ `c/common/platform.h:465:9`!(("[%s] %s[%lu] = %lu\n", __func__, #array_name, \
36 (unsigned long)(idx), (unsigned long)array_name[idx]))
37
38 #define HUFFMAN_TABLE_BITScxx . . $ `c/dec/decode.c:38:9`! 8U
39 #define HUFFMAN_TABLE_MASKcxx . . $ `c/dec/decode.c:39:9`! 0xFF
40
41 /* We need the slack region for the following reasons:
42 - doing up to two 16-byte copies for fast backward copying
43 - inserting transformed dictionary word:
44 255 prefix + 32 base + 255 suffix */
45 static const brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! kRingBufferWriteAheadSlackcxx . . $ kRingBufferWriteAheadSlack. = 542;
46
47 static const BROTLI_MODELcxx . . $ `c/common/platform.h:674:9`!("small")
48 uint8_tcxx . . $ uint8_t# kCodeLengthCodeOrdercxx . . $ kCodeLengthCodeOrder.[BROTLI_CODE_LENGTH_CODEScxx . . $ `c/common/constants.h:34:9`!] = {
49 1, 2, 3, 4, 0, 5, 17, 6, 16, 7, 8, 9, 10, 11, 12, 13, 14, 15,
50 };
51
52 /* Static prefix code for the complex code length code lengths. */
53 static const BROTLI_MODELcxx . . $ `c/common/platform.h:674:9`!("small")
54 uint8_tcxx . . $ uint8_t# kCodeLengthPrefixLengthcxx . . $ kCodeLengthPrefixLength.[16] = {
55 2, 2, 2, 3, 2, 2, 2, 4, 2, 2, 2, 3, 2, 2, 2, 4,
56 };
57
58 static const BROTLI_MODELcxx . . $ `c/common/platform.h:674:9`!("small")
59 uint8_tcxx . . $ uint8_t# kCodeLengthPrefixValuecxx . . $ kCodeLengthPrefixValue.[16] = {
60 0, 4, 3, 2, 0, 4, 3, 1, 0, 4, 3, 2, 0, 4, 3, 5,
61 };
62
63 BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! BrotliDecoderSetParametercxx . . $ BrotliDecoderSetParameter(605003305ae8af39).(
64 BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* state, BrotliDecoderParametercxx . . $ BrotliDecoderParameter# p, uint32_tcxx . . $ uint32_t# value) {
65 if (state->statecxx . . $ BrotliDecoderStateStruct#state. != BROTLI_STATE_UNINITEDcxx . . $ BROTLI_STATE_UNINITED.) return BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!;
66 switch (p) {
67 case BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATIONcxx . . $ BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION.:
68 state->canny_ringbuffer_allocationcxx . . $ BrotliDecoderStateStruct#canny_ringbuffer_allocation. = !!value ? 0 : 1;
69 return BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!;
70
71 case BROTLI_DECODER_PARAM_LARGE_WINDOWcxx . . $ BROTLI_DECODER_PARAM_LARGE_WINDOW.:
72 state->large_windowcxx . . $ BrotliDecoderStateStruct#large_window. = TO_BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:55:9`!(!!value);
73 return BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!;
74
75 default: return BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!;
76 }
77 }
78
79 BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* BrotliDecoderCreateInstancecxx . . $ BrotliDecoderCreateInstance(125708fa71c753db).(
80 brotli_alloc_funccxx . . $ brotli_alloc_func# alloc_func, brotli_free_funccxx . . $ brotli_free_func# free_func, void* opaque) {
81 BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* state = 0;
82 if (!BrotliDecoderEnsureStaticInitcxx . . $ BrotliDecoderEnsureStaticInit(b126dc7c1de90089).()) {
83 BROTLI_DUMPcxx . . $ `c/common/platform.h:487:9`!();
84 return 0;
85 }
86 if (!alloc_func && !free_func) {
87 state = (BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!*)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!));
88 } else if (alloc_func && free_func) {
89 state = (BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!*)alloc_func(opaque, sizeof(BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!));
90 }
91 if (state == 0) {
92 BROTLI_DUMPcxx . . $ `c/common/platform.h:487:9`!();
93 return 0;
94 }
95 if (!BrotliDecoderStateInitcxx . . $ BrotliDecoderStateInit(6711db6abf207b4c).(state, alloc_func, free_func, opaque)) {
96 BROTLI_DUMPcxx . . $ `c/common/platform.h:487:9`!();
97 if (!alloc_func && !free_func) {
98 freecxx . . $ free(5d22bdacc48458e8).(state);
99 } else if (alloc_func && free_func) {
100 free_func(opaque, state);
101 }
102 return 0;
103 }
104 return state;
105 }
106
107 /* Deinitializes and frees BrotliDecoderState instance. */
108 void BrotliDecoderDestroyInstancecxx . . $ BrotliDecoderDestroyInstance(bb1fb99afd41e748).(BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* state) {
109 if (!state) {
110 return;
111 } else {
112 brotli_free_funccxx . . $ brotli_free_func# free_func = state->free_funccxx . . $ BrotliDecoderStateStruct#free_func.;
113 void* opaque = state->memory_manager_opaquecxx . . $ BrotliDecoderStateStruct#memory_manager_opaque.;
114 BrotliDecoderStateCleanupcxx . . $ BrotliDecoderStateCleanup(bb1fb99afd41e748).(state);
115 free_func(opaque, state);
116 }
117 }
118
119 /* Saves error code and converts it to BrotliDecoderResult. */
120 static BROTLI_NOINLINEcxx . . $ `c/common/platform.h:137:9`! BrotliDecoderResultcxx . . $ BrotliDecoderResult# SaveErrorCodecxx . . $ SaveErrorCode(77e1025b57b0953d).(
121 BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s, BrotliDecoderErrorCodecxx . . $ BrotliDecoderErrorCode# e, size_t consumed_input) {
122 s->error_codecxx . . $ BrotliDecoderStateStruct#error_code. = (int)e;
123 s->used_inputcxx . . $ BrotliDecoderStateStruct#used_input. += consumed_input;
124 if ((s->buffer_lengthcxx . . $ BrotliDecoderStateStruct#buffer_length. != 0) && (s->brcxx . . $ BrotliDecoderStateStruct#br..next_incxx . . $ $anonymous_type_83261257069d1fbd_0#next_in. == s->brcxx . . $ BrotliDecoderStateStruct#br..last_incxx . . $ $anonymous_type_83261257069d1fbd_0#last_in.)) {
125 /* If internal buffer is depleted at last, reset it. */
126 s->buffer_lengthcxx . . $ BrotliDecoderStateStruct#buffer_length. = 0;
127 }
128 switch (e) {
129 case BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.:
130 return BROTLI_DECODER_RESULT_SUCCESScxx . . $ BROTLI_DECODER_RESULT_SUCCESS.;
131
132 case BROTLI_DECODER_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_INPUT.:
133 return BROTLI_DECODER_RESULT_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT.;
134
135 case BROTLI_DECODER_NEEDS_MORE_OUTPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_OUTPUT.:
136 return BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUTcxx . . $ BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT.;
137
138 default:
139 return BROTLI_DECODER_RESULT_ERRORcxx . . $ BROTLI_DECODER_RESULT_ERROR.;
140 }
141 }
142
143 /* Decodes WBITS by reading 1 - 7 bits, or 0x11 for "Large Window Brotli".
144 Precondition: bit-reader accumulator has at least 8 bits. */
145 static BrotliDecoderErrorCodecxx . . $ BrotliDecoderErrorCode# DecodeWindowBitscxx . . $ DecodeWindowBits(2f206bf3bd0000ad).(BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s,
146 BrotliBitReadercxx . . $ BrotliBitReader#* br) {
147 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! n;
148 BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! large_window = s->large_windowcxx . . $ BrotliDecoderStateStruct#large_window.;
149 s->large_windowcxx . . $ BrotliDecoderStateStruct#large_window. = BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!;
150 BrotliTakeBitscxx . . $ BrotliTakeBits(d1d27a8f6588cca7).(br, 1, &n);
151 if (n == 0) {
152 s->window_bitscxx . . $ BrotliDecoderStateStruct#window_bits. = 16;
153 return BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.;
154 }
155 BrotliTakeBitscxx . . $ BrotliTakeBits(d1d27a8f6588cca7).(br, 3, &n);
156 if (n != 0) {
157 s->window_bitscxx . . $ BrotliDecoderStateStruct#window_bits. = (17u + n) & 63u;
158 return BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.;
159 }
160 BrotliTakeBitscxx . . $ BrotliTakeBits(d1d27a8f6588cca7).(br, 3, &n);
161 if (n == 1) {
162 if (large_window) {
163 BrotliTakeBitscxx . . $ BrotliTakeBits(d1d27a8f6588cca7).(br, 1, &n);
164 if (n == 1) {
165 return BROTLI_FAILUREcxx . . $ `c/dec/decode.c:30:9`!(BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS);
166 }
167 s->large_windowcxx . . $ BrotliDecoderStateStruct#large_window. = BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!;
168 return BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.;
169 } else {
170 return BROTLI_FAILUREcxx . . $ `c/dec/decode.c:30:9`!(BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS);
171 }
172 }
173 if (n != 0) {
174 s->window_bitscxx . . $ BrotliDecoderStateStruct#window_bits. = (8u + n) & 63u;
175 return BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.;
176 }
177 s->window_bitscxx . . $ BrotliDecoderStateStruct#window_bits. = 17;
178 return BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.;
179 }
180
181 static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! void memmove16cxx . . $ memmove16(b400838b9938479d).(uint8_tcxx . . $ uint8_t#* dst, uint8_tcxx . . $ uint8_t#* src) {
182 #if defined(BROTLI_TARGET_NEON)
183 vst1q_u8(dst, vld1q_u8(src));
184 #else
185 uint32_tcxx . . $ uint32_t# buffer[4];
186 memcpycxx . . $ memcpy(cc817cb175f282d).(buffer, src, 16);
187 memcpycxx . . $ memcpy(cc817cb175f282d).(dst, buffer, 16);
188 #endif
189 }
190
191 /* Decodes a number in the range [0..255], by reading 1 - 11 bits. */
192 static BROTLI_NOINLINEcxx . . $ `c/common/platform.h:137:9`! BrotliDecoderErrorCodecxx . . $ BrotliDecoderErrorCode# DecodeVarLenUint8cxx . . $ DecodeVarLenUint8(8f6e4a21f550f5f6).(
193 BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s, BrotliBitReadercxx . . $ BrotliBitReader#* br, brotli_reg_tcxx . . $ `c/common/platform.h:237:9`!* value) {
194 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! bits;
195 switch (s->substate_decode_uint8cxx . . $ BrotliDecoderStateStruct#substate_decode_uint8.) {
196 case BROTLI_STATE_DECODE_UINT8_NONEcxx . . $ BROTLI_STATE_DECODE_UINT8_NONE.:
197 if (BROTLI_PREDICT_FALSEcxx . . $ `c/common/platform.h:74:9`!(!BrotliSafeReadBits(br, 1, &bits))) {
198 return BROTLI_DECODER_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_INPUT.;
199 }
200 if (bits == 0) {
201 *value = 0;
202 return BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.;
203 }
204 /* Fall through. */
205
206 case BROTLI_STATE_DECODE_UINT8_SHORTcxx . . $ BROTLI_STATE_DECODE_UINT8_SHORT.:
207 if (BROTLI_PREDICT_FALSEcxx . . $ `c/common/platform.h:74:9`!(!BrotliSafeReadBits(br, 3, &bits))) {
208 s->substate_decode_uint8cxx . . $ BrotliDecoderStateStruct#substate_decode_uint8. = BROTLI_STATE_DECODE_UINT8_SHORTcxx . . $ BROTLI_STATE_DECODE_UINT8_SHORT.;
209 return BROTLI_DECODER_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_INPUT.;
210 }
211 if (bits == 0) {
212 *value = 1;
213 s->substate_decode_uint8cxx . . $ BrotliDecoderStateStruct#substate_decode_uint8. = BROTLI_STATE_DECODE_UINT8_NONEcxx . . $ BROTLI_STATE_DECODE_UINT8_NONE.;
214 return BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.;
215 }
216 /* Use output value as a temporary storage. It MUST be persisted. */
217 *value = bits;
218 /* Fall through. */
219
220 case BROTLI_STATE_DECODE_UINT8_LONGcxx . . $ BROTLI_STATE_DECODE_UINT8_LONG.:
221 if (BROTLI_PREDICT_FALSEcxx . . $ `c/common/platform.h:74:9`!(!BrotliSafeReadBits(br, *value, &bits))) {
222 s->substate_decode_uint8cxx . . $ BrotliDecoderStateStruct#substate_decode_uint8. = BROTLI_STATE_DECODE_UINT8_LONGcxx . . $ BROTLI_STATE_DECODE_UINT8_LONG.;
223 return BROTLI_DECODER_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_INPUT.;
224 }
225 *value = ((brotli_reg_tcxx . . $ `c/common/platform.h:237:9`!)1U << *value) + bits;
226 s->substate_decode_uint8cxx . . $ BrotliDecoderStateStruct#substate_decode_uint8. = BROTLI_STATE_DECODE_UINT8_NONEcxx . . $ BROTLI_STATE_DECODE_UINT8_NONE.;
227 return BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.;
228
229 default:
230 return
231 BROTLI_FAILUREcxx . . $ `c/dec/decode.c:30:9`!(BROTLI_DECODER_ERROR_UNREACHABLE); /* COV_NF_LINE */
232 }
233 }
234
235 /* Decodes a metablock length and flags by reading 2 - 31 bits. */
236 static BrotliDecoderErrorCodecxx . . $ BrotliDecoderErrorCode# BROTLI_NOINLINEcxx . . $ `c/common/platform.h:137:9`! DecodeMetaBlockLengthcxx . . $ DecodeMetaBlockLength(2f206bf3bd0000ad).(
237 BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s, BrotliBitReadercxx . . $ BrotliBitReader#* br) {
238 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! bits;
239 int i;
240 for (;;) {
241 switch (s->substate_metablock_headercxx . . $ BrotliDecoderStateStruct#substate_metablock_header.) {
242 case BROTLI_STATE_METABLOCK_HEADER_NONEcxx . . $ BROTLI_STATE_METABLOCK_HEADER_NONE.:
243 if (!BrotliSafeReadBitscxx . . $ BrotliSafeReadBits(d859fb483c1e4a60).(br, 1, &bits)) {
244 return BROTLI_DECODER_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_INPUT.;
245 }
246 s->is_last_metablockcxx . . $ BrotliDecoderStateStruct#is_last_metablock. = bits ? 1 : 0;
247 s->meta_block_remaining_lencxx . . $ BrotliDecoderStateStruct#meta_block_remaining_len. = 0;
248 s->is_uncompressedcxx . . $ BrotliDecoderStateStruct#is_uncompressed. = 0;
249 s->is_metadatacxx . . $ BrotliDecoderStateStruct#is_metadata. = 0;
250 if (!s->is_last_metablockcxx . . $ BrotliDecoderStateStruct#is_last_metablock.) {
251 s->substate_metablock_headercxx . . $ BrotliDecoderStateStruct#substate_metablock_header. = BROTLI_STATE_METABLOCK_HEADER_NIBBLEScxx . . $ BROTLI_STATE_METABLOCK_HEADER_NIBBLES.;
252 break;
253 }
254 s->substate_metablock_headercxx . . $ BrotliDecoderStateStruct#substate_metablock_header. = BROTLI_STATE_METABLOCK_HEADER_EMPTYcxx . . $ BROTLI_STATE_METABLOCK_HEADER_EMPTY.;
255 /* Fall through. */
256
257 case BROTLI_STATE_METABLOCK_HEADER_EMPTYcxx . . $ BROTLI_STATE_METABLOCK_HEADER_EMPTY.:
258 if (!BrotliSafeReadBitscxx . . $ BrotliSafeReadBits(d859fb483c1e4a60).(br, 1, &bits)) {
259 return BROTLI_DECODER_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_INPUT.;
260 }
261 if (bits) {
262 s->substate_metablock_headercxx . . $ BrotliDecoderStateStruct#substate_metablock_header. = BROTLI_STATE_METABLOCK_HEADER_NONEcxx . . $ BROTLI_STATE_METABLOCK_HEADER_NONE.;
263 return BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.;
264 }
265 s->substate_metablock_headercxx . . $ BrotliDecoderStateStruct#substate_metablock_header. = BROTLI_STATE_METABLOCK_HEADER_NIBBLEScxx . . $ BROTLI_STATE_METABLOCK_HEADER_NIBBLES.;
266 /* Fall through. */
267
268 case BROTLI_STATE_METABLOCK_HEADER_NIBBLEScxx . . $ BROTLI_STATE_METABLOCK_HEADER_NIBBLES.:
269 if (!BrotliSafeReadBitscxx . . $ BrotliSafeReadBits(d859fb483c1e4a60).(br, 2, &bits)) {
270 return BROTLI_DECODER_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_INPUT.;
271 }
272 s->size_nibblescxx . . $ BrotliDecoderStateStruct#size_nibbles. = (uint8_tcxx . . $ uint8_t#)(bits + 4);
273 s->loop_countercxx . . $ BrotliDecoderStateStruct#loop_counter. = 0;
274 if (bits == 3) {
275 s->is_metadatacxx . . $ BrotliDecoderStateStruct#is_metadata. = 1;
276 s->substate_metablock_headercxx . . $ BrotliDecoderStateStruct#substate_metablock_header. = BROTLI_STATE_METABLOCK_HEADER_RESERVEDcxx . . $ BROTLI_STATE_METABLOCK_HEADER_RESERVED.;
277 break;
278 }
279 s->substate_metablock_headercxx . . $ BrotliDecoderStateStruct#substate_metablock_header. = BROTLI_STATE_METABLOCK_HEADER_SIZEcxx . . $ BROTLI_STATE_METABLOCK_HEADER_SIZE.;
280 /* Fall through. */
281
282 case BROTLI_STATE_METABLOCK_HEADER_SIZEcxx . . $ BROTLI_STATE_METABLOCK_HEADER_SIZE.:
283 i = s->loop_countercxx . . $ BrotliDecoderStateStruct#loop_counter.;
284 for (; i < (int)s->size_nibblescxx . . $ BrotliDecoderStateStruct#size_nibbles.; ++i) {
285 if (!BrotliSafeReadBitscxx . . $ BrotliSafeReadBits(d859fb483c1e4a60).(br, 4, &bits)) {
286 s->loop_countercxx . . $ BrotliDecoderStateStruct#loop_counter. = i;
287 return BROTLI_DECODER_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_INPUT.;
288 }
289 if (i + 1 == (int)s->size_nibblescxx . . $ BrotliDecoderStateStruct#size_nibbles. && s->size_nibblescxx . . $ BrotliDecoderStateStruct#size_nibbles. > 4 &&
290 bits == 0) {
291 return BROTLI_FAILUREcxx . . $ `c/dec/decode.c:30:9`!(BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE);
292 }
293 s->meta_block_remaining_lencxx . . $ BrotliDecoderStateStruct#meta_block_remaining_len. |= (int)(bits << (i * 4));
294 }
295 s->substate_metablock_headercxx . . $ BrotliDecoderStateStruct#substate_metablock_header. =
296 BROTLI_STATE_METABLOCK_HEADER_UNCOMPRESSEDcxx . . $ BROTLI_STATE_METABLOCK_HEADER_UNCOMPRESSED.;
297 /* Fall through. */
298
299 case BROTLI_STATE_METABLOCK_HEADER_UNCOMPRESSEDcxx . . $ BROTLI_STATE_METABLOCK_HEADER_UNCOMPRESSED.:
300 if (!s->is_last_metablockcxx . . $ BrotliDecoderStateStruct#is_last_metablock.) {
301 if (!BrotliSafeReadBitscxx . . $ BrotliSafeReadBits(d859fb483c1e4a60).(br, 1, &bits)) {
302 return BROTLI_DECODER_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_INPUT.;
303 }
304 s->is_uncompressedcxx . . $ BrotliDecoderStateStruct#is_uncompressed. = bits ? 1 : 0;
305 }
306 ++s->meta_block_remaining_lencxx . . $ BrotliDecoderStateStruct#meta_block_remaining_len.;
307 s->substate_metablock_headercxx . . $ BrotliDecoderStateStruct#substate_metablock_header. = BROTLI_STATE_METABLOCK_HEADER_NONEcxx . . $ BROTLI_STATE_METABLOCK_HEADER_NONE.;
308 return BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.;
309
310 case BROTLI_STATE_METABLOCK_HEADER_RESERVEDcxx . . $ BROTLI_STATE_METABLOCK_HEADER_RESERVED.:
311 if (!BrotliSafeReadBitscxx . . $ BrotliSafeReadBits(d859fb483c1e4a60).(br, 1, &bits)) {
312 return BROTLI_DECODER_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_INPUT.;
313 }
314 if (bits != 0) {
315 return BROTLI_FAILUREcxx . . $ `c/dec/decode.c:30:9`!(BROTLI_DECODER_ERROR_FORMAT_RESERVED);
316 }
317 s->substate_metablock_headercxx . . $ BrotliDecoderStateStruct#substate_metablock_header. = BROTLI_STATE_METABLOCK_HEADER_BYTEScxx . . $ BROTLI_STATE_METABLOCK_HEADER_BYTES.;
318 /* Fall through. */
319
320 case BROTLI_STATE_METABLOCK_HEADER_BYTEScxx . . $ BROTLI_STATE_METABLOCK_HEADER_BYTES.:
321 if (!BrotliSafeReadBitscxx . . $ BrotliSafeReadBits(d859fb483c1e4a60).(br, 2, &bits)) {
322 return BROTLI_DECODER_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_INPUT.;
323 }
324 if (bits == 0) {
325 s->substate_metablock_headercxx . . $ BrotliDecoderStateStruct#substate_metablock_header. = BROTLI_STATE_METABLOCK_HEADER_NONEcxx . . $ BROTLI_STATE_METABLOCK_HEADER_NONE.;
326 return BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.;
327 }
328 s->size_nibblescxx . . $ BrotliDecoderStateStruct#size_nibbles. = (uint8_tcxx . . $ uint8_t#)bits;
329 s->substate_metablock_headercxx . . $ BrotliDecoderStateStruct#substate_metablock_header. = BROTLI_STATE_METABLOCK_HEADER_METADATAcxx . . $ BROTLI_STATE_METABLOCK_HEADER_METADATA.;
330 /* Fall through. */
331
332 case BROTLI_STATE_METABLOCK_HEADER_METADATAcxx . . $ BROTLI_STATE_METABLOCK_HEADER_METADATA.:
333 i = s->loop_countercxx . . $ BrotliDecoderStateStruct#loop_counter.;
334 for (; i < (int)s->size_nibblescxx . . $ BrotliDecoderStateStruct#size_nibbles.; ++i) {
335 if (!BrotliSafeReadBitscxx . . $ BrotliSafeReadBits(d859fb483c1e4a60).(br, 8, &bits)) {
336 s->loop_countercxx . . $ BrotliDecoderStateStruct#loop_counter. = i;
337 return BROTLI_DECODER_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_INPUT.;
338 }
339 if (i + 1 == (int)s->size_nibblescxx . . $ BrotliDecoderStateStruct#size_nibbles. && s->size_nibblescxx . . $ BrotliDecoderStateStruct#size_nibbles. > 1 &&
340 bits == 0) {
341 return BROTLI_FAILUREcxx . . $ `c/dec/decode.c:30:9`!(
342 BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE);
343 }
344 s->meta_block_remaining_lencxx . . $ BrotliDecoderStateStruct#meta_block_remaining_len. |= (int)(bits << (i * 8));
345 }
346 ++s->meta_block_remaining_lencxx . . $ BrotliDecoderStateStruct#meta_block_remaining_len.;
347 s->substate_metablock_headercxx . . $ BrotliDecoderStateStruct#substate_metablock_header. = BROTLI_STATE_METABLOCK_HEADER_NONEcxx . . $ BROTLI_STATE_METABLOCK_HEADER_NONE.;
348 return BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.;
349
350 default:
351 return
352 BROTLI_FAILUREcxx . . $ `c/dec/decode.c:30:9`!(BROTLI_DECODER_ERROR_UNREACHABLE); /* COV_NF_LINE */
353 }
354 }
355 }
356
357 /* Decodes the Huffman code.
358 This method doesn't read data from the bit reader, BUT drops the amount of
359 bits that correspond to the decoded symbol.
360 bits MUST contain at least 15 (BROTLI_HUFFMAN_MAX_CODE_LENGTH) valid bits. */
361 static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! DecodeSymbolcxx . . $ DecodeSymbol(c63c4a8318c0a102).(brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! bits,
362 const HuffmanCodecxx . . $ HuffmanCode#* table,
363 BrotliBitReadercxx . . $ BrotliBitReader#* br) {
364 BROTLI_HC_MARK_TABLE_FOR_FAST_LOADcxx . . $ `c/dec/huffman.h:65:9`!(table);
365 BROTLI_HC_ADJUST_TABLE_INDEXcxx . . $ `c/dec/huffman.h:66:9`!(table, bits & HUFFMAN_TABLE_MASKcxx . . $ `c/dec/decode.c:39:9`!);
366 if (BROTLI_HC_FAST_LOAD_BITScxx . . $ `c/dec/huffman.h:69:9`!(table) > HUFFMAN_TABLE_BITScxx . . $ `c/dec/decode.c:38:9`!) {
367 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! nbits = BROTLI_HC_FAST_LOAD_BITScxx . . $ `c/dec/huffman.h:69:9`!(table) - HUFFMAN_TABLE_BITScxx . . $ `c/dec/decode.c:38:9`!;
368 BrotliDropBitscxx . . $ BrotliDropBits(aea9ea103d4b1d3f).(br, HUFFMAN_TABLE_BITScxx . . $ `c/dec/decode.c:38:9`!);
369 BROTLI_HC_ADJUST_TABLE_INDEXcxx . . $ `c/dec/huffman.h:66:9`!(table,
370 BROTLI_HC_FAST_LOAD_VALUEcxx . . $ `c/dec/huffman.h:70:9`!(table) +
371 ((bits >> HUFFMAN_TABLE_BITScxx . . $ `c/dec/decode.c:38:9`!) & BitMask(nbits)));
372 }
373 BrotliDropBitscxx . . $ BrotliDropBits(aea9ea103d4b1d3f).(br, BROTLI_HC_FAST_LOAD_BITScxx . . $ `c/dec/huffman.h:69:9`!(table));
374 return BROTLI_HC_FAST_LOAD_VALUEcxx . . $ `c/dec/huffman.h:70:9`!(table);
375 }
376
377 /* Reads and decodes the next Huffman code from bit-stream.
378 This method peeks 16 bits of input and drops 0 - 15 of them. */
379 static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! ReadSymbolcxx . . $ ReadSymbol(99805dca1a2a4b7b).(const HuffmanCodecxx . . $ HuffmanCode#* table,
380 BrotliBitReadercxx . . $ BrotliBitReader#* br) {
381 return DecodeSymbolcxx . . $ DecodeSymbol(c63c4a8318c0a102).(BrotliGet16BitsUnmaskedcxx . . $ BrotliGet16BitsUnmasked(a8eec9f290bacd2d).(br), table, br);
382 }
383
384 /* Same as DecodeSymbol, but it is known that there is less than 15 bits of
385 input are currently available. */
386 static BROTLI_NOINLINEcxx . . $ `c/common/platform.h:137:9`! BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! SafeDecodeSymbolcxx . . $ SafeDecodeSymbol(24ac31996b0a21de).(
387 const HuffmanCodecxx . . $ HuffmanCode#* table, BrotliBitReadercxx . . $ BrotliBitReader#* br, brotli_reg_tcxx . . $ `c/common/platform.h:237:9`!* result) {
388 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! val;
389 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! available_bits = BrotliGetAvailableBitscxx . . $ BrotliGetAvailableBits(d61fb7f759d9fbb3).(br);
390 BROTLI_HC_MARK_TABLE_FOR_FAST_LOADcxx . . $ `c/dec/huffman.h:65:9`!(table);
391 if (available_bits == 0) {
392 if (BROTLI_HC_FAST_LOAD_BITScxx . . $ `c/dec/huffman.h:69:9`!(table) == 0) {
393 *result = BROTLI_HC_FAST_LOAD_VALUEcxx . . $ `c/dec/huffman.h:70:9`!(table);
394 return BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!;
395 }
396 return BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!; /* No valid bits at all. */
397 }
398 val = BrotliGetBitsUnmaskedcxx . . $ BrotliGetBitsUnmasked(a8eec9f290bacd2d).(br);
399 BROTLI_HC_ADJUST_TABLE_INDEXcxx . . $ `c/dec/huffman.h:66:9`!(table, val & HUFFMAN_TABLE_MASKcxx . . $ `c/dec/decode.c:39:9`!);
400 if (BROTLI_HC_FAST_LOAD_BITScxx . . $ `c/dec/huffman.h:69:9`!(table) <= HUFFMAN_TABLE_BITScxx . . $ `c/dec/decode.c:38:9`!) {
401 if (BROTLI_HC_FAST_LOAD_BITScxx . . $ `c/dec/huffman.h:69:9`!(table) <= available_bits) {
402 BrotliDropBitscxx . . $ BrotliDropBits(aea9ea103d4b1d3f).(br, BROTLI_HC_FAST_LOAD_BITScxx . . $ `c/dec/huffman.h:69:9`!(table));
403 *result = BROTLI_HC_FAST_LOAD_VALUEcxx . . $ `c/dec/huffman.h:70:9`!(table);
404 return BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!;
405 } else {
406 return BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!; /* Not enough bits for the first level. */
407 }
408 }
409 if (available_bits <= HUFFMAN_TABLE_BITScxx . . $ `c/dec/decode.c:38:9`!) {
410 return BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!; /* Not enough bits to move to the second level. */
411 }
412
413 /* Speculatively drop HUFFMAN_TABLE_BITS. */
414 val = (val & BitMaskcxx . . $ BitMask(ecdaa1632f49f591).(BROTLI_HC_FAST_LOAD_BITScxx . . $ `c/dec/huffman.h:69:9`!(table))) >> HUFFMAN_TABLE_BITScxx . . $ `c/dec/decode.c:38:9`!;
415 available_bits -= HUFFMAN_TABLE_BITScxx . . $ `c/dec/decode.c:38:9`!;
416 BROTLI_HC_ADJUST_TABLE_INDEXcxx . . $ `c/dec/huffman.h:66:9`!(table, BROTLI_HC_FAST_LOAD_VALUEcxx . . $ `c/dec/huffman.h:70:9`!(table) + val);
417 if (available_bits < BROTLI_HC_FAST_LOAD_BITScxx . . $ `c/dec/huffman.h:69:9`!(table)) {
418 return BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!; /* Not enough bits for the second level. */
419 }
420
421 BrotliDropBitscxx . . $ BrotliDropBits(aea9ea103d4b1d3f).(br, HUFFMAN_TABLE_BITScxx . . $ `c/dec/decode.c:38:9`! + BROTLI_HC_FAST_LOAD_BITScxx . . $ `c/dec/huffman.h:69:9`!(table));
422 *result = BROTLI_HC_FAST_LOAD_VALUEcxx . . $ `c/dec/huffman.h:70:9`!(table);
423 return BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!;
424 }
425
426 static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! SafeReadSymbolcxx . . $ SafeReadSymbol(24ac31996b0a21de).(
427 const HuffmanCodecxx . . $ HuffmanCode#* table, BrotliBitReadercxx . . $ BrotliBitReader#* br, brotli_reg_tcxx . . $ `c/common/platform.h:237:9`!* result) {
428 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! val;
429 if (BROTLI_PREDICT_TRUEcxx . . $ `c/common/platform.h:73:9`!(BrotliSafeGetBits(br, 15, &val))) {
430 *result = DecodeSymbolcxx . . $ DecodeSymbol(c63c4a8318c0a102).(val, table, br);
431 return BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!;
432 }
433 return SafeDecodeSymbolcxx . . $ SafeDecodeSymbol(24ac31996b0a21de).(table, br, result);
434 }
435
436 /* Makes a look-up in first level Huffman table. Peeks 8 bits. */
437 static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! void PreloadSymbolcxx . . $ PreloadSymbol(5c393db4bc17ef8).(int safe,
438 const HuffmanCodecxx . . $ HuffmanCode#* table,
439 BrotliBitReadercxx . . $ BrotliBitReader#* br,
440 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`!* bits,
441 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`!* value) {
442 if (safe) {
443 return;
444 }
445 BROTLI_HC_MARK_TABLE_FOR_FAST_LOADcxx . . $ `c/dec/huffman.h:65:9`!(table);
446 BROTLI_HC_ADJUST_TABLE_INDEXcxx . . $ `c/dec/huffman.h:66:9`!(table, BrotliGetBits(br, HUFFMAN_TABLE_BITScxx . . $ `c/dec/decode.c:38:9`!));
447 *bits = BROTLI_HC_FAST_LOAD_BITScxx . . $ `c/dec/huffman.h:69:9`!(table);
448 *value = BROTLI_HC_FAST_LOAD_VALUEcxx . . $ `c/dec/huffman.h:70:9`!(table);
449 }
450
451 /* Decodes the next Huffman code using data prepared by PreloadSymbol.
452 Reads 0 - 15 bits. Also peeks 8 following bits. */
453 static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! ReadPreloadedSymbolcxx . . $ ReadPreloadedSymbol(5cad8357c765024f).(const HuffmanCodecxx . . $ HuffmanCode#* table,
454 BrotliBitReadercxx . . $ BrotliBitReader#* br,
455 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`!* bits,
456 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`!* value) {
457 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! result = *value;
458 if (BROTLI_PREDICT_FALSEcxx . . $ `c/common/platform.h:74:9`!(*bits > HUFFMAN_TABLE_BITScxx . . $ `c/dec/decode.c:38:9`!)) {
459 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! val = BrotliGet16BitsUnmaskedcxx . . $ BrotliGet16BitsUnmasked(a8eec9f290bacd2d).(br);
460 const HuffmanCodecxx . . $ HuffmanCode#* ext = table + (val & HUFFMAN_TABLE_MASKcxx . . $ `c/dec/decode.c:39:9`!) + *value;
461 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! mask = BitMaskcxx . . $ BitMask(ecdaa1632f49f591).((*bits - HUFFMAN_TABLE_BITScxx . . $ `c/dec/decode.c:38:9`!));
462 BROTLI_HC_MARK_TABLE_FOR_FAST_LOADcxx . . $ `c/dec/huffman.h:65:9`!(ext);
463 BrotliDropBitscxx . . $ BrotliDropBits(aea9ea103d4b1d3f).(br, HUFFMAN_TABLE_BITScxx . . $ `c/dec/decode.c:38:9`!);
464 BROTLI_HC_ADJUST_TABLE_INDEXcxx . . $ `c/dec/huffman.h:66:9`!(ext, (val >> HUFFMAN_TABLE_BITScxx . . $ `c/dec/decode.c:38:9`!) & mask);
465 BrotliDropBitscxx . . $ BrotliDropBits(aea9ea103d4b1d3f).(br, BROTLI_HC_FAST_LOAD_BITScxx . . $ `c/dec/huffman.h:69:9`!(ext));
466 result = BROTLI_HC_FAST_LOAD_VALUEcxx . . $ `c/dec/huffman.h:70:9`!(ext);
467 } else {
468 BrotliDropBitscxx . . $ BrotliDropBits(aea9ea103d4b1d3f).(br, *bits);
469 }
470 PreloadSymbolcxx . . $ PreloadSymbol(5c393db4bc17ef8).(0, table, br, bits, value);
471 return result;
472 }
473
474 /* Reads up to limit symbols from br and copies them into ringbuffer,
475 starting from pos. Caller must ensure that there is enough space
476 for the write. Returns the amount of symbols actually copied. */
477 static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! int BrotliCopyPreloadedSymbolsToU8cxx . . $ BrotliCopyPreloadedSymbolsToU8(a479f4dc9a681d5c).(const HuffmanCodecxx . . $ HuffmanCode#* table,
478 BrotliBitReadercxx . . $ BrotliBitReader#* br,
479 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`!* bits,
480 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`!* value,
481 uint8_tcxx . . $ uint8_t#* ringbuffer,
482 int pos,
483 const int limit) {
484 /* Calculate range where CheckInputAmount is always true.
485 Start with the number of bytes we can read. */
486 int64_tcxx . . $ int64_t# new_lim = br->guard_incxx . . $ $anonymous_type_83261257069d1fbd_0#guard_in. - br->next_incxx . . $ $anonymous_type_83261257069d1fbd_0#next_in.;
487 /* Convert to bits, since symbols use variable number of bits. */
488 new_lim *= 8;
489 /* At most 15 bits per symbol, so this is safe. */
490 new_lim /= 15;
491 const int kMaximalOverread = 4;
492 int pos_limit = limit;
493 int copies = 0;
494 if ((new_lim - kMaximalOverread) <= limit) {
495 // Safe cast, since new_lim is already < num_steps
496 pos_limit = (int)(new_lim - kMaximalOverread);
497 }
498 if (pos_limit < 0) {
499 pos_limit = 0;
500 }
501 copies = pos_limit;
502 pos_limit += pos;
503 /* Fast path, caller made sure it is safe to write,
504 we verified that is is safe to read. */
505 for (; pos < pos_limit; pos++) {
506 BROTLI_DCHECKcxx . . $ `c/common/platform.h:473:9`!(BrotliCheckInputAmount(br));
507 ringbuffer[pos] = (uint8_tcxx . . $ uint8_t#)ReadPreloadedSymbolcxx . . $ ReadPreloadedSymbol(5cad8357c765024f).(table, br, bits, value);
508 BROTLI_LOG_ARRAY_INDEXcxx . . $ `c/dec/decode.c:34:9`!(ringbuffer, pos);
509 }
510 /* Do the remainder, caller made sure it is safe to write,
511 we need to bverify that it is safe to read. */
512 while (BrotliCheckInputAmountcxx . . $ BrotliCheckInputAmount(4966df8ab2ee854a).(br) && copies < limit) {
513 ringbuffer[pos] = (uint8_tcxx . . $ uint8_t#)ReadPreloadedSymbolcxx . . $ ReadPreloadedSymbol(5cad8357c765024f).(table, br, bits, value);
514 BROTLI_LOG_ARRAY_INDEXcxx . . $ `c/dec/decode.c:34:9`!(ringbuffer, pos);
515 pos++;
516 copies++;
517 }
518 return copies;
519 }
520
521 static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! Log2Floorcxx . . $ Log2Floor(ecdaa1632f49f591).(brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! x) {
522 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! result = 0;
523 while (x) {
524 x >>= 1;
525 ++result;
526 }
527 return result;
528 }
529
530 /* Reads (s->symbol + 1) symbols.
531 Totally 1..4 symbols are read, 1..11 bits each.
532 The list of symbols MUST NOT contain duplicates. */
533 static BrotliDecoderErrorCodecxx . . $ BrotliDecoderErrorCode# ReadSimpleHuffmanSymbolscxx . . $ ReadSimpleHuffmanSymbols(4ee454aeda07035a).(
534 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! alphabet_size_max, brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! alphabet_size_limit,
535 BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s) {
536 /* max_bits == 1..11; symbol == 0..3; 1..44 bits will be read. */
537 BrotliBitReadercxx . . $ BrotliBitReader#* br = &s->brcxx . . $ BrotliDecoderStateStruct#br.;
538 BrotliMetablockHeaderArenacxx . . $ BrotliMetablockHeaderArena#* h = &s->arenacxx . . $ BrotliDecoderStateStruct#arena..headercxx . . $ BrotliDecoderStateStruct#$anonymous_type_9#header.;
539 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! max_bits = Log2Floorcxx . . $ Log2Floor(ecdaa1632f49f591).(alphabet_size_max - 1);
540 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! i = h->sub_loop_countercxx . . $ BrotliMetablockHeaderArena#sub_loop_counter.;
541 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! num_symbols = h->symbolcxx . . $ BrotliMetablockHeaderArena#symbol.;
542 while (i <= num_symbols) {
543 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! v;
544 if (BROTLI_PREDICT_FALSEcxx . . $ `c/common/platform.h:74:9`!(!BrotliSafeReadBits(br, max_bits, &v))) {
545 h->sub_loop_countercxx . . $ BrotliMetablockHeaderArena#sub_loop_counter. = i;
546 h->substate_huffmancxx . . $ BrotliMetablockHeaderArena#substate_huffman. = BROTLI_STATE_HUFFMAN_SIMPLE_READcxx . . $ BROTLI_STATE_HUFFMAN_SIMPLE_READ.;
547 return BROTLI_DECODER_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_INPUT.;
548 }
549 if (v >= alphabet_size_limit) {
550 return
551 BROTLI_FAILUREcxx . . $ `c/dec/decode.c:30:9`!(BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET);
552 }
553 h->symbols_lists_arraycxx . . $ BrotliMetablockHeaderArena#symbols_lists_array.[i] = (uint16_tcxx . . $ uint16_t#)v;
554 BROTLI_LOG_UINTcxx . . $ `c/dec/decode.c:32:9`!(h->symbols_lists_array[i]);
555 ++i;
556 }
557
558 for (i = 0; i < num_symbols; ++i) {
559 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! k = i + 1;
560 for (; k <= num_symbols; ++k) {
561 if (h->symbols_lists_arraycxx . . $ BrotliMetablockHeaderArena#symbols_lists_array.[i] == h->symbols_lists_arraycxx . . $ BrotliMetablockHeaderArena#symbols_lists_array.[k]) {
562 return BROTLI_FAILUREcxx . . $ `c/dec/decode.c:30:9`!(BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME);
563 }
564 }
565 }
566
567 return BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.;
568 }
569
570 /* Process single decoded symbol code length:
571 A) reset the repeat variable
572 B) remember code length (if it is not 0)
573 C) extend corresponding index-chain
574 D) reduce the Huffman space
575 E) update the histogram */
576 static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! void ProcessSingleCodeLengthcxx . . $ ProcessSingleCodeLength(e744fb9ca4ece724).(brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! code_len,
577 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`!* symbol, brotli_reg_tcxx . . $ `c/common/platform.h:237:9`!* repeat, brotli_reg_tcxx . . $ `c/common/platform.h:237:9`!* space,
578 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`!* prev_code_len, uint16_tcxx . . $ uint16_t#* symbol_lists,
579 uint16_tcxx . . $ uint16_t#* code_length_histo, int* next_symbol) {
580 *repeat = 0;
581 if (code_len != 0) { /* code_len == 1..15 */
582 symbol_lists[next_symbol[code_len]] = (uint16_tcxx . . $ uint16_t#)(*symbol);
583 next_symbol[code_len] = (int)(*symbol);
584 *prev_code_len = code_len;
585 *space -= 32768U >> code_len;
586 code_length_histo[code_len]++;
587 BROTLI_LOGcxx . . $ `c/common/platform.h:465:9`!(("[ReadHuffmanCode] code_length[%d] = %d\n",
588 (int)*symbol, (int)code_len));
589 }
590 (*symbol)++;
591 }
592
593 /* Process repeated symbol code length.
594 A) Check if it is the extension of previous repeat sequence; if the decoded
595 value is not BROTLI_REPEAT_PREVIOUS_CODE_LENGTH, then it is a new
596 symbol-skip
597 B) Update repeat variable
598 C) Check if operation is feasible (fits alphabet)
599 D) For each symbol do the same operations as in ProcessSingleCodeLength
600
601 PRECONDITION: code_len == BROTLI_REPEAT_PREVIOUS_CODE_LENGTH or
602 code_len == BROTLI_REPEAT_ZERO_CODE_LENGTH */
603 static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! void ProcessRepeatedCodeLengthcxx . . $ ProcessRepeatedCodeLength(d48ee6dacf759f98).(brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! code_len,
604 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! repeat_delta, brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! alphabet_size, brotli_reg_tcxx . . $ `c/common/platform.h:237:9`!* symbol,
605 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`!* repeat, brotli_reg_tcxx . . $ `c/common/platform.h:237:9`!* space, brotli_reg_tcxx . . $ `c/common/platform.h:237:9`!* prev_code_len,
606 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`!* repeat_code_len, uint16_tcxx . . $ uint16_t#* symbol_lists,
607 uint16_tcxx . . $ uint16_t#* code_length_histo, int* next_symbol) {
608 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! old_repeat;
609 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! extra_bits = 3; /* for BROTLI_REPEAT_ZERO_CODE_LENGTH */
610 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! new_len = 0; /* for BROTLI_REPEAT_ZERO_CODE_LENGTH */
611 if (code_len == BROTLI_REPEAT_PREVIOUS_CODE_LENGTHcxx . . $ `c/common/constants.h:32:9`!) {
612 new_len = *prev_code_len;
613 extra_bits = 2;
614 }
615 if (*repeat_code_len != new_len) {
616 *repeat = 0;
617 *repeat_code_len = new_len;
618 }
619 old_repeat = *repeat;
620 if (*repeat > 0) {
621 *repeat -= 2;
622 *repeat <<= extra_bits;
623 }
624 *repeat += repeat_delta + 3U;
625 repeat_delta = *repeat - old_repeat;
626 if (*symbol + repeat_delta > alphabet_size) {
627 BROTLI_DUMPcxx . . $ `c/common/platform.h:487:9`!();
628 *symbol = alphabet_size;
629 *space = 0xFFFFF;
630 return;
631 }
632 BROTLI_LOGcxx . . $ `c/common/platform.h:465:9`!(("[ReadHuffmanCode] code_length[%d..%d] = %d\n",
633 (int)*symbol, (int)(*symbol + repeat_delta - 1), (int)*repeat_code_len));
634 if (*repeat_code_len != 0) {
635 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! last = *symbol + repeat_delta;
636 int next = next_symbol[*repeat_code_len];
637 do {
638 symbol_lists[next] = (uint16_tcxx . . $ uint16_t#)*symbol;
639 next = (int)*symbol;
640 } while (++(*symbol) != last);
641 next_symbol[*repeat_code_len] = next;
642 *space -= repeat_delta << (15 - *repeat_code_len);
643 code_length_histo[*repeat_code_len] =
644 (uint16_tcxx . . $ uint16_t#)(code_length_histo[*repeat_code_len] + repeat_delta);
645 } else {
646 *symbol += repeat_delta;
647 }
648 }
649
650 /* Reads and decodes symbol codelengths. */
651 static BrotliDecoderErrorCodecxx . . $ BrotliDecoderErrorCode# ReadSymbolCodeLengthscxx . . $ ReadSymbolCodeLengths(78e5d5197c920321).(
652 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! alphabet_size, BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s) {
653 BrotliBitReadercxx . . $ BrotliBitReader#* br = &s->brcxx . . $ BrotliDecoderStateStruct#br.;
654 BrotliMetablockHeaderArenacxx . . $ BrotliMetablockHeaderArena#* h = &s->arenacxx . . $ BrotliDecoderStateStruct#arena..headercxx . . $ BrotliDecoderStateStruct#$anonymous_type_9#header.;
655 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! symbol = h->symbolcxx . . $ BrotliMetablockHeaderArena#symbol.;
656 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! repeat = h->repeatcxx . . $ BrotliMetablockHeaderArena#repeat.;
657 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! space = h->spacecxx . . $ BrotliMetablockHeaderArena#space.;
658 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! prev_code_len = h->prev_code_lencxx . . $ BrotliMetablockHeaderArena#prev_code_len.;
659 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! repeat_code_len = h->repeat_code_lencxx . . $ BrotliMetablockHeaderArena#repeat_code_len.;
660 uint16_tcxx . . $ uint16_t#* symbol_lists = h->symbol_listscxx . . $ BrotliMetablockHeaderArena#symbol_lists.;
661 uint16_tcxx . . $ uint16_t#* code_length_histo = h->code_length_histocxx . . $ BrotliMetablockHeaderArena#code_length_histo.;
662 int* next_symbol = h->next_symbolcxx . . $ BrotliMetablockHeaderArena#next_symbol.;
663 if (!BrotliWarmupBitReadercxx . . $ BrotliWarmupBitReader(4966df8ab2ee854a).(br)) {
664 return BROTLI_DECODER_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_INPUT.;
665 }
666 while (symbol < alphabet_size && space > 0) {
667 const HuffmanCodecxx . . $ HuffmanCode#* p = h->tablecxx . . $ BrotliMetablockHeaderArena#table.;
668 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! code_len;
669 BROTLI_HC_MARK_TABLE_FOR_FAST_LOADcxx . . $ `c/dec/huffman.h:65:9`!(p);
670 if (!BrotliCheckInputAmountcxx . . $ BrotliCheckInputAmount(4966df8ab2ee854a).(br)) {
671 h->symbolcxx . . $ BrotliMetablockHeaderArena#symbol. = symbol;
672 h->repeatcxx . . $ BrotliMetablockHeaderArena#repeat. = repeat;
673 h->prev_code_lencxx . . $ BrotliMetablockHeaderArena#prev_code_len. = prev_code_len;
674 h->repeat_code_lencxx . . $ BrotliMetablockHeaderArena#repeat_code_len. = repeat_code_len;
675 h->spacecxx . . $ BrotliMetablockHeaderArena#space. = space;
676 return BROTLI_DECODER_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_INPUT.;
677 }
678 BrotliFillBitWindow16cxx . . $ BrotliFillBitWindow16(165eb0102fa4fad4).(br);
679 BROTLI_HC_ADJUST_TABLE_INDEXcxx . . $ `c/dec/huffman.h:66:9`!(p, BrotliGetBitsUnmasked(br) &
680 BitMask(BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTHcxx . . $ `c/dec/huffman.h:27:9`!));
681 BrotliDropBitscxx . . $ BrotliDropBits(aea9ea103d4b1d3f).(br, BROTLI_HC_FAST_LOAD_BITScxx . . $ `c/dec/huffman.h:69:9`!(p)); /* Use 1..5 bits. */
682 code_len = BROTLI_HC_FAST_LOAD_VALUEcxx . . $ `c/dec/huffman.h:70:9`!(p); /* code_len == 0..17 */
683 if (code_len < BROTLI_REPEAT_PREVIOUS_CODE_LENGTHcxx . . $ `c/common/constants.h:32:9`!) {
684 ProcessSingleCodeLengthcxx . . $ ProcessSingleCodeLength(e744fb9ca4ece724).(code_len, &symbol, &repeat, &space,
685 &prev_code_len, symbol_lists, code_length_histo, next_symbol);
686 } else { /* code_len == 16..17, extra_bits == 2..3 */
687 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! extra_bits =
688 (code_len == BROTLI_REPEAT_PREVIOUS_CODE_LENGTHcxx . . $ `c/common/constants.h:32:9`!) ? 2 : 3;
689 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! repeat_delta =
690 BrotliGetBitsUnmaskedcxx . . $ BrotliGetBitsUnmasked(a8eec9f290bacd2d).(br) & BitMaskcxx . . $ BitMask(ecdaa1632f49f591).(extra_bits);
691 BrotliDropBitscxx . . $ BrotliDropBits(aea9ea103d4b1d3f).(br, extra_bits);
692 ProcessRepeatedCodeLengthcxx . . $ ProcessRepeatedCodeLength(d48ee6dacf759f98).(code_len, repeat_delta, alphabet_size,
693 &symbol, &repeat, &space, &prev_code_len, &repeat_code_len,
694 symbol_lists, code_length_histo, next_symbol);
695 }
696 }
697 h->spacecxx . . $ BrotliMetablockHeaderArena#space. = space;
698 return BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.;
699 }
700
701 static BrotliDecoderErrorCodecxx . . $ BrotliDecoderErrorCode# SafeReadSymbolCodeLengthscxx . . $ SafeReadSymbolCodeLengths(78e5d5197c920321).(
702 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! alphabet_size, BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s) {
703 BrotliBitReadercxx . . $ BrotliBitReader#* br = &s->brcxx . . $ BrotliDecoderStateStruct#br.;
704 BrotliMetablockHeaderArenacxx . . $ BrotliMetablockHeaderArena#* h = &s->arenacxx . . $ BrotliDecoderStateStruct#arena..headercxx . . $ BrotliDecoderStateStruct#$anonymous_type_9#header.;
705 BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! get_byte = BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!;
706 while (h->symbolcxx . . $ BrotliMetablockHeaderArena#symbol. < alphabet_size && h->spacecxx . . $ BrotliMetablockHeaderArena#space. > 0) {
707 const HuffmanCodecxx . . $ HuffmanCode#* p = h->tablecxx . . $ BrotliMetablockHeaderArena#table.;
708 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! code_len;
709 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! available_bits;
710 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! bits = 0;
711 BROTLI_HC_MARK_TABLE_FOR_FAST_LOADcxx . . $ `c/dec/huffman.h:65:9`!(p);
712 if (get_byte && !BrotliPullBytecxx . . $ BrotliPullByte(4966df8ab2ee854a).(br)) return BROTLI_DECODER_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_INPUT.;
713 get_byte = BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!;
714 available_bits = BrotliGetAvailableBitscxx . . $ BrotliGetAvailableBits(d61fb7f759d9fbb3).(br);
715 if (available_bits != 0) {
716 bits = (uint32_tcxx . . $ uint32_t#)BrotliGetBitsUnmaskedcxx . . $ BrotliGetBitsUnmasked(a8eec9f290bacd2d).(br);
717 }
718 BROTLI_HC_ADJUST_TABLE_INDEXcxx . . $ `c/dec/huffman.h:66:9`!(p,
719 bits & BitMask(BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTHcxx . . $ `c/dec/huffman.h:27:9`!));
720 if (BROTLI_HC_FAST_LOAD_BITScxx . . $ `c/dec/huffman.h:69:9`!(p) > available_bits) {
721 get_byte = BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!;
722 continue;
723 }
724 code_len = BROTLI_HC_FAST_LOAD_VALUEcxx . . $ `c/dec/huffman.h:70:9`!(p); /* code_len == 0..17 */
725 if (code_len < BROTLI_REPEAT_PREVIOUS_CODE_LENGTHcxx . . $ `c/common/constants.h:32:9`!) {
726 BrotliDropBitscxx . . $ BrotliDropBits(aea9ea103d4b1d3f).(br, BROTLI_HC_FAST_LOAD_BITScxx . . $ `c/dec/huffman.h:69:9`!(p));
727 ProcessSingleCodeLengthcxx . . $ ProcessSingleCodeLength(e744fb9ca4ece724).(code_len, &h->symbolcxx . . $ BrotliMetablockHeaderArena#symbol., &h->repeatcxx . . $ BrotliMetablockHeaderArena#repeat., &h->spacecxx . . $ BrotliMetablockHeaderArena#space.,
728 &h->prev_code_lencxx . . $ BrotliMetablockHeaderArena#prev_code_len., h->symbol_listscxx . . $ BrotliMetablockHeaderArena#symbol_lists., h->code_length_histocxx . . $ BrotliMetablockHeaderArena#code_length_histo.,
729 h->next_symbolcxx . . $ BrotliMetablockHeaderArena#next_symbol.);
730 } else { /* code_len == 16..17, extra_bits == 2..3 */
731 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! extra_bits = code_len - 14U;
732 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! repeat_delta = (bits >> BROTLI_HC_FAST_LOAD_BITScxx . . $ `c/dec/huffman.h:69:9`!(p)) &
733 BitMaskcxx . . $ BitMask(ecdaa1632f49f591).(extra_bits);
734 if (available_bits < BROTLI_HC_FAST_LOAD_BITScxx . . $ `c/dec/huffman.h:69:9`!(p) + extra_bits) {
735 get_byte = BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!;
736 continue;
737 }
738 BrotliDropBitscxx . . $ BrotliDropBits(aea9ea103d4b1d3f).(br, BROTLI_HC_FAST_LOAD_BITScxx . . $ `c/dec/huffman.h:69:9`!(p) + extra_bits);
739 ProcessRepeatedCodeLengthcxx . . $ ProcessRepeatedCodeLength(d48ee6dacf759f98).(code_len, repeat_delta, alphabet_size,
740 &h->symbolcxx . . $ BrotliMetablockHeaderArena#symbol., &h->repeatcxx . . $ BrotliMetablockHeaderArena#repeat., &h->spacecxx . . $ BrotliMetablockHeaderArena#space., &h->prev_code_lencxx . . $ BrotliMetablockHeaderArena#prev_code_len.,
741 &h->repeat_code_lencxx . . $ BrotliMetablockHeaderArena#repeat_code_len., h->symbol_listscxx . . $ BrotliMetablockHeaderArena#symbol_lists., h->code_length_histocxx . . $ BrotliMetablockHeaderArena#code_length_histo.,
742 h->next_symbolcxx . . $ BrotliMetablockHeaderArena#next_symbol.);
743 }
744 }
745 return BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.;
746 }
747
748 /* Reads and decodes 15..18 codes using static prefix code.
749 Each code is 2..4 bits long. In total 30..72 bits are used. */
750 static BrotliDecoderErrorCodecxx . . $ BrotliDecoderErrorCode# ReadCodeLengthCodeLengthscxx . . $ ReadCodeLengthCodeLengths(fe8ed989e3875dcf).(BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s) {
751 BrotliBitReadercxx . . $ BrotliBitReader#* br = &s->brcxx . . $ BrotliDecoderStateStruct#br.;
752 BrotliMetablockHeaderArenacxx . . $ BrotliMetablockHeaderArena#* h = &s->arenacxx . . $ BrotliDecoderStateStruct#arena..headercxx . . $ BrotliDecoderStateStruct#$anonymous_type_9#header.;
753 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! num_codes = h->repeatcxx . . $ BrotliMetablockHeaderArena#repeat.;
754 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! space = h->spacecxx . . $ BrotliMetablockHeaderArena#space.;
755 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! i = h->sub_loop_countercxx . . $ BrotliMetablockHeaderArena#sub_loop_counter.;
756 for (; i < BROTLI_CODE_LENGTH_CODEScxx . . $ `c/common/constants.h:34:9`!; ++i) {
757 const uint8_tcxx . . $ uint8_t# code_len_idx = kCodeLengthCodeOrdercxx . . $ kCodeLengthCodeOrder.[i];
758 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! ix;
759 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! v;
760 if (BROTLI_PREDICT_FALSEcxx . . $ `c/common/platform.h:74:9`!(!BrotliSafeGetBits(br, 4, &ix))) {
761 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! available_bits = BrotliGetAvailableBitscxx . . $ BrotliGetAvailableBits(d61fb7f759d9fbb3).(br);
762 if (available_bits != 0) {
763 ix = BrotliGetBitsUnmaskedcxx . . $ BrotliGetBitsUnmasked(a8eec9f290bacd2d).(br) & 0xF;
764 } else {
765 ix = 0;
766 }
767 if (kCodeLengthPrefixLengthcxx . . $ kCodeLengthPrefixLength.[ix] > available_bits) {
768 h->sub_loop_countercxx . . $ BrotliMetablockHeaderArena#sub_loop_counter. = i;
769 h->repeatcxx . . $ BrotliMetablockHeaderArena#repeat. = num_codes;
770 h->spacecxx . . $ BrotliMetablockHeaderArena#space. = space;
771 h->substate_huffmancxx . . $ BrotliMetablockHeaderArena#substate_huffman. = BROTLI_STATE_HUFFMAN_COMPLEXcxx . . $ BROTLI_STATE_HUFFMAN_COMPLEX.;
772 return BROTLI_DECODER_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_INPUT.;
773 }
774 }
775 v = kCodeLengthPrefixValuecxx . . $ kCodeLengthPrefixValue.[ix];
776 BrotliDropBitscxx . . $ BrotliDropBits(aea9ea103d4b1d3f).(br, kCodeLengthPrefixLengthcxx . . $ kCodeLengthPrefixLength.[ix]);
777 h->code_length_code_lengthscxx . . $ BrotliMetablockHeaderArena#code_length_code_lengths.[code_len_idx] = (uint8_tcxx . . $ uint8_t#)v;
778 BROTLI_LOG_ARRAY_INDEXcxx . . $ `c/dec/decode.c:34:9`!(h->code_length_code_lengths, code_len_idx);
779 if (v != 0) {
780 space = space - (32U >> v);
781 ++num_codes;
782 ++h->code_length_histocxx . . $ BrotliMetablockHeaderArena#code_length_histo.[v];
783 if (space - 1U >= 32U) {
784 /* space is 0 or wrapped around. */
785 break;
786 }
787 }
788 }
789 if (!(num_codes == 1 || space == 0)) {
790 return BROTLI_FAILUREcxx . . $ `c/dec/decode.c:30:9`!(BROTLI_DECODER_ERROR_FORMAT_CL_SPACE);
791 }
792 return BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.;
793 }
794
795 /* Decodes the Huffman tables.
796 There are 2 scenarios:
797 A) Huffman code contains only few symbols (1..4). Those symbols are read
798 directly; their code lengths are defined by the number of symbols.
799 For this scenario 4 - 49 bits will be read.
800
801 B) 2-phase decoding:
802 B.1) Small Huffman table is decoded; it is specified with code lengths
803 encoded with predefined entropy code. 32 - 74 bits are used.
804 B.2) Decoded table is used to decode code lengths of symbols in resulting
805 Huffman table. In worst case 3520 bits are read. */
806 static BrotliDecoderErrorCodecxx . . $ BrotliDecoderErrorCode# ReadHuffmanCodecxx . . $ ReadHuffmanCode(acffa3267fb3b9f8).(brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! alphabet_size_max,
807 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! alphabet_size_limit,
808 HuffmanCodecxx . . $ HuffmanCode#* table,
809 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`!* opt_table_size,
810 BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s) {
811 BrotliBitReadercxx . . $ BrotliBitReader#* br = &s->brcxx . . $ BrotliDecoderStateStruct#br.;
812 BrotliMetablockHeaderArenacxx . . $ BrotliMetablockHeaderArena#* h = &s->arenacxx . . $ BrotliDecoderStateStruct#arena..headercxx . . $ BrotliDecoderStateStruct#$anonymous_type_9#header.;
813 /* State machine. */
814 for (;;) {
815 switch (h->substate_huffmancxx . . $ BrotliMetablockHeaderArena#substate_huffman.) {
816 case BROTLI_STATE_HUFFMAN_NONEcxx . . $ BROTLI_STATE_HUFFMAN_NONE.:
817 if (!BrotliSafeReadBitscxx . . $ BrotliSafeReadBits(d859fb483c1e4a60).(br, 2, &h->sub_loop_countercxx . . $ BrotliMetablockHeaderArena#sub_loop_counter.)) {
818 return BROTLI_DECODER_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_INPUT.;
819 }
820 BROTLI_LOG_UINTcxx . . $ `c/dec/decode.c:32:9`!(h->sub_loop_counter);
821 /* The value is used as follows:
822 1 for simple code;
823 0 for no skipping, 2 skips 2 code lengths, 3 skips 3 code lengths */
824 if (h->sub_loop_countercxx . . $ BrotliMetablockHeaderArena#sub_loop_counter. != 1) {
825 h->spacecxx . . $ BrotliMetablockHeaderArena#space. = 32;
826 h->repeatcxx . . $ BrotliMetablockHeaderArena#repeat. = 0; /* num_codes */
827 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&h->code_length_histocxx . . $ BrotliMetablockHeaderArena#code_length_histo.[0], 0, sizeof(h->code_length_histocxx . . $ BrotliMetablockHeaderArena#code_length_histo.[0]) *
828 (BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTHcxx . . $ `c/dec/huffman.h:27:9`! + 1));
829 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&h->code_length_code_lengthscxx . . $ BrotliMetablockHeaderArena#code_length_code_lengths.[0], 0,
830 sizeof(h->code_length_code_lengthscxx . . $ BrotliMetablockHeaderArena#code_length_code_lengths.));
831 h->substate_huffmancxx . . $ BrotliMetablockHeaderArena#substate_huffman. = BROTLI_STATE_HUFFMAN_COMPLEXcxx . . $ BROTLI_STATE_HUFFMAN_COMPLEX.;
832 continue;
833 }
834 /* Fall through. */
835
836 case BROTLI_STATE_HUFFMAN_SIMPLE_SIZEcxx . . $ BROTLI_STATE_HUFFMAN_SIMPLE_SIZE.:
837 /* Read symbols, codes & code lengths directly. */
838 if (!BrotliSafeReadBitscxx . . $ BrotliSafeReadBits(d859fb483c1e4a60).(br, 2, &h->symbolcxx . . $ BrotliMetablockHeaderArena#symbol.)) { /* num_symbols */
839 h->substate_huffmancxx . . $ BrotliMetablockHeaderArena#substate_huffman. = BROTLI_STATE_HUFFMAN_SIMPLE_SIZEcxx . . $ BROTLI_STATE_HUFFMAN_SIMPLE_SIZE.;
840 return BROTLI_DECODER_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_INPUT.;
841 }
842 h->sub_loop_countercxx . . $ BrotliMetablockHeaderArena#sub_loop_counter. = 0;
843 /* Fall through. */
844
845 case BROTLI_STATE_HUFFMAN_SIMPLE_READcxx . . $ BROTLI_STATE_HUFFMAN_SIMPLE_READ.: {
846 BrotliDecoderErrorCodecxx . . $ BrotliDecoderErrorCode# result =
847 ReadSimpleHuffmanSymbolscxx . . $ ReadSimpleHuffmanSymbols(4ee454aeda07035a).(alphabet_size_max, alphabet_size_limit, s);
848 if (result != BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.) {
849 return result;
850 }
851 }
852 /* Fall through. */
853
854 case BROTLI_STATE_HUFFMAN_SIMPLE_BUILDcxx . . $ BROTLI_STATE_HUFFMAN_SIMPLE_BUILD.: {
855 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! table_size;
856 if (h->symbolcxx . . $ BrotliMetablockHeaderArena#symbol. == 3) {
857 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! bits;
858 if (!BrotliSafeReadBitscxx . . $ BrotliSafeReadBits(d859fb483c1e4a60).(br, 1, &bits)) {
859 h->substate_huffmancxx . . $ BrotliMetablockHeaderArena#substate_huffman. = BROTLI_STATE_HUFFMAN_SIMPLE_BUILDcxx . . $ BROTLI_STATE_HUFFMAN_SIMPLE_BUILD.;
860 return BROTLI_DECODER_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_INPUT.;
861 }
862 h->symbolcxx . . $ BrotliMetablockHeaderArena#symbol. += bits;
863 }
864 BROTLI_LOG_UINTcxx . . $ `c/dec/decode.c:32:9`!(h->symbol);
865 table_size = BrotliBuildSimpleHuffmanTablecxx . . $ BrotliBuildSimpleHuffmanTable(128cfb7b6641eca7).(table, HUFFMAN_TABLE_BITScxx . . $ `c/dec/decode.c:38:9`!,
866 h->symbols_lists_arraycxx . . $ BrotliMetablockHeaderArena#symbols_lists_array.,
867 (uint32_tcxx . . $ uint32_t#)h->symbolcxx . . $ BrotliMetablockHeaderArena#symbol.);
868 if (opt_table_size) {
869 *opt_table_size = table_size;
870 }
871 h->substate_huffmancxx . . $ BrotliMetablockHeaderArena#substate_huffman. = BROTLI_STATE_HUFFMAN_NONEcxx . . $ BROTLI_STATE_HUFFMAN_NONE.;
872 return BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.;
873 }
874
875 /* Decode Huffman-coded code lengths. */
876 case BROTLI_STATE_HUFFMAN_COMPLEXcxx . . $ BROTLI_STATE_HUFFMAN_COMPLEX.: {
877 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! i;
878 BrotliDecoderErrorCodecxx . . $ BrotliDecoderErrorCode# result = ReadCodeLengthCodeLengthscxx . . $ ReadCodeLengthCodeLengths(fe8ed989e3875dcf).(s);
879 if (result != BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.) {
880 return result;
881 }
882 BrotliBuildCodeLengthsHuffmanTablecxx . . $ BrotliBuildCodeLengthsHuffmanTable(f1294370fd0a8600).(h->tablecxx . . $ BrotliMetablockHeaderArena#table.,
883 h->code_length_code_lengthscxx . . $ BrotliMetablockHeaderArena#code_length_code_lengths.,
884 h->code_length_histocxx . . $ BrotliMetablockHeaderArena#code_length_histo.);
885 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&h->code_length_histocxx . . $ BrotliMetablockHeaderArena#code_length_histo.[0], 0, sizeof(h->code_length_histocxx . . $ BrotliMetablockHeaderArena#code_length_histo.));
886 for (i = 0; i <= BROTLI_HUFFMAN_MAX_CODE_LENGTHcxx . . $ `c/dec/huffman.h:18:9`!; ++i) {
887 h->next_symbolcxx . . $ BrotliMetablockHeaderArena#next_symbol.[i] = (int)i - (BROTLI_HUFFMAN_MAX_CODE_LENGTHcxx . . $ `c/dec/huffman.h:18:9`! + 1);
888 h->symbol_listscxx . . $ BrotliMetablockHeaderArena#symbol_lists.[h->next_symbolcxx . . $ BrotliMetablockHeaderArena#next_symbol.[i]] = 0xFFFF;
889 }
890
891 h->symbolcxx . . $ BrotliMetablockHeaderArena#symbol. = 0;
892 h->prev_code_lencxx . . $ BrotliMetablockHeaderArena#prev_code_len. = BROTLI_INITIAL_REPEATED_CODE_LENGTHcxx . . $ `c/common/constants.h:36:9`!;
893 h->repeatcxx . . $ BrotliMetablockHeaderArena#repeat. = 0;
894 h->repeat_code_lencxx . . $ BrotliMetablockHeaderArena#repeat_code_len. = 0;
895 h->spacecxx . . $ BrotliMetablockHeaderArena#space. = 32768;
896 h->substate_huffmancxx . . $ BrotliMetablockHeaderArena#substate_huffman. = BROTLI_STATE_HUFFMAN_LENGTH_SYMBOLScxx . . $ BROTLI_STATE_HUFFMAN_LENGTH_SYMBOLS.;
897 }
898 /* Fall through. */
899
900 case BROTLI_STATE_HUFFMAN_LENGTH_SYMBOLScxx . . $ BROTLI_STATE_HUFFMAN_LENGTH_SYMBOLS.: {
901 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! table_size;
902 BrotliDecoderErrorCodecxx . . $ BrotliDecoderErrorCode# result = ReadSymbolCodeLengthscxx . . $ ReadSymbolCodeLengths(78e5d5197c920321).(
903 alphabet_size_limit, s);
904 if (result == BROTLI_DECODER_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_INPUT.) {
905 result = SafeReadSymbolCodeLengthscxx . . $ SafeReadSymbolCodeLengths(78e5d5197c920321).(alphabet_size_limit, s);
906 }
907 if (result != BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.) {
908 return result;
909 }
910
911 if (h->spacecxx . . $ BrotliMetablockHeaderArena#space. != 0) {
912 BROTLI_LOGcxx . . $ `c/common/platform.h:465:9`!(("[ReadHuffmanCode] space = %d\n", (int)h->space));
913 return BROTLI_FAILUREcxx . . $ `c/dec/decode.c:30:9`!(BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE);
914 }
915 table_size = BrotliBuildHuffmanTablecxx . . $ BrotliBuildHuffmanTable(aff94dc29a236ff6).(
916 table, HUFFMAN_TABLE_BITScxx . . $ `c/dec/decode.c:38:9`!, h->symbol_listscxx . . $ BrotliMetablockHeaderArena#symbol_lists., h->code_length_histocxx . . $ BrotliMetablockHeaderArena#code_length_histo.);
917 if (opt_table_size) {
918 *opt_table_size = table_size;
919 }
920 h->substate_huffmancxx . . $ BrotliMetablockHeaderArena#substate_huffman. = BROTLI_STATE_HUFFMAN_NONEcxx . . $ BROTLI_STATE_HUFFMAN_NONE.;
921 return BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.;
922 }
923
924 default:
925 return
926 BROTLI_FAILUREcxx . . $ `c/dec/decode.c:30:9`!(BROTLI_DECODER_ERROR_UNREACHABLE); /* COV_NF_LINE */
927 }
928 }
929 }
930
931 /* Decodes a block length by reading 3..39 bits. */
932 static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! ReadBlockLengthcxx . . $ ReadBlockLength(99805dca1a2a4b7b).(const HuffmanCodecxx . . $ HuffmanCode#* table,
933 BrotliBitReadercxx . . $ BrotliBitReader#* br) {
934 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! code;
935 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! nbits;
936 code = ReadSymbolcxx . . $ ReadSymbol(99805dca1a2a4b7b).(table, br);
937 nbits = _kBrotliPrefixCodeRangescxx . . $ _kBrotliPrefixCodeRanges.[code].nbitscxx . . $ $anonymous_type_f7176a257296a212_0#nbits.; /* nbits == 2..24 */
938 return _kBrotliPrefixCodeRangescxx . . $ _kBrotliPrefixCodeRanges.[code].offsetcxx . . $ $anonymous_type_f7176a257296a212_0#offset. + BrotliReadBits24cxx . . $ BrotliReadBits24(b970e0c403979745).(br, nbits);
939 }
940
941 /* WARNING: if state is not BROTLI_STATE_READ_BLOCK_LENGTH_NONE, then
942 reading can't be continued with ReadBlockLength. */
943 static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! SafeReadBlockLengthcxx . . $ SafeReadBlockLength(b640658b5edcb718).(
944 BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s, brotli_reg_tcxx . . $ `c/common/platform.h:237:9`!* result, const HuffmanCodecxx . . $ HuffmanCode#* table,
945 BrotliBitReadercxx . . $ BrotliBitReader#* br) {
946 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! index;
947 if (s->substate_read_block_lengthcxx . . $ BrotliDecoderStateStruct#substate_read_block_length. == BROTLI_STATE_READ_BLOCK_LENGTH_NONEcxx . . $ BROTLI_STATE_READ_BLOCK_LENGTH_NONE.) {
948 if (!SafeReadSymbolcxx . . $ SafeReadSymbol(24ac31996b0a21de).(table, br, &index)) {
949 return BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!;
950 }
951 } else {
952 index = s->block_length_indexcxx . . $ BrotliDecoderStateStruct#block_length_index.;
953 }
954 {
955 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! bits;
956 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! nbits = _kBrotliPrefixCodeRangescxx . . $ _kBrotliPrefixCodeRanges.[index].nbitscxx . . $ $anonymous_type_f7176a257296a212_0#nbits.;
957 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! offset = _kBrotliPrefixCodeRangescxx . . $ _kBrotliPrefixCodeRanges.[index].offsetcxx . . $ $anonymous_type_f7176a257296a212_0#offset.;
958 if (!BrotliSafeReadBitscxx . . $ BrotliSafeReadBits(d859fb483c1e4a60).(br, nbits, &bits)) {
959 s->block_length_indexcxx . . $ BrotliDecoderStateStruct#block_length_index. = index;
960 s->substate_read_block_lengthcxx . . $ BrotliDecoderStateStruct#substate_read_block_length. = BROTLI_STATE_READ_BLOCK_LENGTH_SUFFIXcxx . . $ BROTLI_STATE_READ_BLOCK_LENGTH_SUFFIX.;
961 return BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!;
962 }
963 *result = offset + bits;
964 s->substate_read_block_lengthcxx . . $ BrotliDecoderStateStruct#substate_read_block_length. = BROTLI_STATE_READ_BLOCK_LENGTH_NONEcxx . . $ BROTLI_STATE_READ_BLOCK_LENGTH_NONE.;
965 return BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!;
966 }
967 }
968
969 /* Transform:
970 1) initialize list L with values 0, 1,... 255
971 2) For each input element X:
972 2.1) let Y = L[X]
973 2.2) remove X-th element from L
974 2.3) prepend Y to L
975 2.4) append Y to output
976
977 In most cases max(Y) <= 7, so most of L remains intact.
978 To reduce the cost of initialization, we reuse L, remember the upper bound
979 of Y values, and reinitialize only first elements in L.
980
981 Most of input values are 0 and 1. To reduce number of branches, we replace
982 inner for loop with do-while. */
983 static BROTLI_NOINLINEcxx . . $ `c/common/platform.h:137:9`! void InverseMoveToFrontTransformcxx . . $ InverseMoveToFrontTransform(9befc3ede1a11ed2).(
984 uint8_tcxx . . $ uint8_t#* v, brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! v_len, BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* state) {
985 /* Reinitialize elements that could have been changed. */
986 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! i = 1;
987 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! upper_bound = state->mtf_upper_boundcxx . . $ BrotliDecoderStateStruct#mtf_upper_bound.;
988 uint32_tcxx . . $ uint32_t#* mtf = &state->mtfcxx . . $ BrotliDecoderStateStruct#mtf.[1]; /* Make mtf[-1] addressable. */
989 uint8_tcxx . . $ uint8_t#* mtf_u8 = (uint8_tcxx . . $ uint8_t#*)mtf;
990 /* Load endian-aware constant. */
991 const uint8_tcxx . . $ uint8_t# b0123[4] = {0, 1, 2, 3};
992 uint32_tcxx . . $ uint32_t# pattern;
993 memcpycxx . . $ memcpy(cc817cb175f282d).(&pattern, &b0123, 4);
994
995 /* Initialize list using 4 consequent values pattern. */
996 mtf[0] = pattern;
997 do {
998 pattern += 0x04040404; /* Advance all 4 values by 4. */
999 mtf[i] = pattern;
1000 i++;
1001 } while (i <= upper_bound);
1002
1003 /* Transform the input. */
1004 upper_bound = 0;
1005 for (i = 0; i < v_len; ++i) {
1006 int index = v[i];
1007 uint8_tcxx . . $ uint8_t# value = mtf_u8[index];
1008 upper_bound |= v[i];
1009 v[i] = value;
1010 mtf_u8[-1] = value;
1011 do {
1012 index--;
1013 mtf_u8[index + 1] = mtf_u8[index];
1014 } while (index >= 0);
1015 }
1016 /* Remember amount of elements to be reinitialized. */
1017 state->mtf_upper_boundcxx . . $ BrotliDecoderStateStruct#mtf_upper_bound. = upper_bound >> 2;
1018 }
1019
1020 /* Decodes a series of Huffman table using ReadHuffmanCode function. */
1021 static BrotliDecoderErrorCodecxx . . $ BrotliDecoderErrorCode# HuffmanTreeGroupDecodecxx . . $ HuffmanTreeGroupDecode(86fcbd07aef51349).(
1022 HuffmanTreeGroupcxx . . $ HuffmanTreeGroup#* group, BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s) {
1023 BrotliMetablockHeaderArenacxx . . $ BrotliMetablockHeaderArena#* h = &s->arenacxx . . $ BrotliDecoderStateStruct#arena..headercxx . . $ BrotliDecoderStateStruct#$anonymous_type_9#header.;
1024 if (h->substate_tree_groupcxx . . $ BrotliMetablockHeaderArena#substate_tree_group. != BROTLI_STATE_TREE_GROUP_LOOPcxx . . $ BROTLI_STATE_TREE_GROUP_LOOP.) {
1025 h->nextcxx . . $ BrotliMetablockHeaderArena#next. = group->codescxx . . $ $anonymous_type_421782d160a65272_1#codes.;
1026 h->htree_indexcxx . . $ BrotliMetablockHeaderArena#htree_index. = 0;
1027 h->substate_tree_groupcxx . . $ BrotliMetablockHeaderArena#substate_tree_group. = BROTLI_STATE_TREE_GROUP_LOOPcxx . . $ BROTLI_STATE_TREE_GROUP_LOOP.;
1028 }
1029 while (h->htree_indexcxx . . $ BrotliMetablockHeaderArena#htree_index. < group->num_htreescxx . . $ $anonymous_type_421782d160a65272_1#num_htrees.) {
1030 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! table_size;
1031 BrotliDecoderErrorCodecxx . . $ BrotliDecoderErrorCode# result = ReadHuffmanCodecxx . . $ ReadHuffmanCode(acffa3267fb3b9f8).(group->alphabet_size_maxcxx . . $ $anonymous_type_421782d160a65272_1#alphabet_size_max.,
1032 group->alphabet_size_limitcxx . . $ $anonymous_type_421782d160a65272_1#alphabet_size_limit., h->nextcxx . . $ BrotliMetablockHeaderArena#next., &table_size, s);
1033 if (result != BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.) return result;
1034 group->htreescxx . . $ $anonymous_type_421782d160a65272_1#htrees.[h->htree_indexcxx . . $ BrotliMetablockHeaderArena#htree_index.] = h->nextcxx . . $ BrotliMetablockHeaderArena#next.;
1035 h->nextcxx . . $ BrotliMetablockHeaderArena#next. += table_size;
1036 ++h->htree_indexcxx . . $ BrotliMetablockHeaderArena#htree_index.;
1037 }
1038 h->substate_tree_groupcxx . . $ BrotliMetablockHeaderArena#substate_tree_group. = BROTLI_STATE_TREE_GROUP_NONEcxx . . $ BROTLI_STATE_TREE_GROUP_NONE.;
1039 return BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.;
1040 }
1041
1042 /* Decodes a context map.
1043 Decoding is done in 4 phases:
1044 1) Read auxiliary information (6..16 bits) and allocate memory.
1045 In case of trivial context map, decoding is finished at this phase.
1046 2) Decode Huffman table using ReadHuffmanCode function.
1047 This table will be used for reading context map items.
1048 3) Read context map items; "0" values could be run-length encoded.
1049 4) Optionally, apply InverseMoveToFront transform to the resulting map. */
1050 static BrotliDecoderErrorCodecxx . . $ BrotliDecoderErrorCode# DecodeContextMapcxx . . $ DecodeContextMap(46820d3bfe197aa1).(brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! context_map_size,
1051 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`!* num_htrees,
1052 uint8_tcxx . . $ uint8_t#** context_map_arg,
1053 BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s) {
1054 BrotliBitReadercxx . . $ BrotliBitReader#* br = &s->brcxx . . $ BrotliDecoderStateStruct#br.;
1055 BrotliDecoderErrorCodecxx . . $ BrotliDecoderErrorCode# result = BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.;
1056 BrotliMetablockHeaderArenacxx . . $ BrotliMetablockHeaderArena#* h = &s->arenacxx . . $ BrotliDecoderStateStruct#arena..headercxx . . $ BrotliDecoderStateStruct#$anonymous_type_9#header.;
1057
1058 switch ((int)h->substate_context_mapcxx . . $ BrotliMetablockHeaderArena#substate_context_map.) {
1059 case BROTLI_STATE_CONTEXT_MAP_NONEcxx . . $ BROTLI_STATE_CONTEXT_MAP_NONE.:
1060 result = DecodeVarLenUint8cxx . . $ DecodeVarLenUint8(8f6e4a21f550f5f6).(s, br, num_htrees);
1061 if (result != BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.) {
1062 return result;
1063 }
1064 (*num_htrees)++;
1065 h->context_indexcxx . . $ BrotliMetablockHeaderArena#context_index. = 0;
1066 BROTLI_LOG_UINTcxx . . $ `c/dec/decode.c:32:9`!(context_map_size);
1067 BROTLI_LOG_UINTcxx . . $ `c/dec/decode.c:32:9`!(*num_htrees);
1068 *context_map_arg =
1069 (uint8_tcxx . . $ uint8_t#*)BROTLI_DECODER_ALLOCcxx . . $ `c/dec/state.h:381:9`!(s, (size_t)context_map_size);
1070 if (*context_map_arg == 0) {
1071 return BROTLI_FAILUREcxx . . $ `c/dec/decode.c:30:9`!(BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP);
1072 }
1073 if (*num_htrees <= 1) {
1074 memsetcxx . . $ memset(d1de1e4fb215f1c6).(*context_map_arg, 0, (size_t)context_map_size);
1075 return BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.;
1076 }
1077 h->substate_context_mapcxx . . $ BrotliMetablockHeaderArena#substate_context_map. = BROTLI_STATE_CONTEXT_MAP_READ_PREFIXcxx . . $ BROTLI_STATE_CONTEXT_MAP_READ_PREFIX.;
1078 /* Fall through. */
1079
1080 case BROTLI_STATE_CONTEXT_MAP_READ_PREFIXcxx . . $ BROTLI_STATE_CONTEXT_MAP_READ_PREFIX.: {
1081 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! bits;
1082 /* In next stage ReadHuffmanCode uses at least 4 bits, so it is safe
1083 to peek 4 bits ahead. */
1084 if (!BrotliSafeGetBitscxx . . $ BrotliSafeGetBits(d859fb483c1e4a60).(br, 5, &bits)) {
1085 return BROTLI_DECODER_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_INPUT.;
1086 }
1087 if ((bits & 1) != 0) { /* Use RLE for zeros. */
1088 h->max_run_length_prefixcxx . . $ BrotliMetablockHeaderArena#max_run_length_prefix. = (bits >> 1) + 1;
1089 BrotliDropBitscxx . . $ BrotliDropBits(aea9ea103d4b1d3f).(br, 5);
1090 } else {
1091 h->max_run_length_prefixcxx . . $ BrotliMetablockHeaderArena#max_run_length_prefix. = 0;
1092 BrotliDropBitscxx . . $ BrotliDropBits(aea9ea103d4b1d3f).(br, 1);
1093 }
1094 BROTLI_LOG_UINTcxx . . $ `c/dec/decode.c:32:9`!(h->max_run_length_prefix);
1095 h->substate_context_mapcxx . . $ BrotliMetablockHeaderArena#substate_context_map. = BROTLI_STATE_CONTEXT_MAP_HUFFMANcxx . . $ BROTLI_STATE_CONTEXT_MAP_HUFFMAN.;
1096 }
1097 /* Fall through. */
1098
1099 case BROTLI_STATE_CONTEXT_MAP_HUFFMANcxx . . $ BROTLI_STATE_CONTEXT_MAP_HUFFMAN.: {
1100 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! alphabet_size = *num_htrees + h->max_run_length_prefixcxx . . $ BrotliMetablockHeaderArena#max_run_length_prefix.;
1101 result = ReadHuffmanCodecxx . . $ ReadHuffmanCode(acffa3267fb3b9f8).(alphabet_size, alphabet_size,
1102 h->context_map_tablecxx . . $ BrotliMetablockHeaderArena#context_map_table., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, s);
1103 if (result != BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.) return result;
1104 h->codecxx . . $ BrotliMetablockHeaderArena#code. = 0xFFFF;
1105 h->substate_context_mapcxx . . $ BrotliMetablockHeaderArena#substate_context_map. = BROTLI_STATE_CONTEXT_MAP_DECODEcxx . . $ BROTLI_STATE_CONTEXT_MAP_DECODE.;
1106 }
1107 /* Fall through. */
1108
1109 case BROTLI_STATE_CONTEXT_MAP_DECODEcxx . . $ BROTLI_STATE_CONTEXT_MAP_DECODE.: {
1110 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! context_index = h->context_indexcxx . . $ BrotliMetablockHeaderArena#context_index.;
1111 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! max_run_length_prefix = h->max_run_length_prefixcxx . . $ BrotliMetablockHeaderArena#max_run_length_prefix.;
1112 uint8_tcxx . . $ uint8_t#* context_map = *context_map_arg;
1113 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! code = h->codecxx . . $ BrotliMetablockHeaderArena#code.;
1114 BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! skip_preamble = (code != 0xFFFF);
1115 while (context_index < context_map_size || skip_preamble) {
1116 if (!skip_preamble) {
1117 if (!SafeReadSymbolcxx . . $ SafeReadSymbol(24ac31996b0a21de).(h->context_map_tablecxx . . $ BrotliMetablockHeaderArena#context_map_table., br, &code)) {
1118 h->codecxx . . $ BrotliMetablockHeaderArena#code. = 0xFFFF;
1119 h->context_indexcxx . . $ BrotliMetablockHeaderArena#context_index. = context_index;
1120 return BROTLI_DECODER_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_INPUT.;
1121 }
1122 BROTLI_LOG_UINTcxx . . $ `c/dec/decode.c:32:9`!(code);
1123
1124 if (code == 0) {
1125 context_map[context_index++] = 0;
1126 continue;
1127 }
1128 if (code > max_run_length_prefix) {
1129 context_map[context_index++] =
1130 (uint8_tcxx . . $ uint8_t#)(code - max_run_length_prefix);
1131 continue;
1132 }
1133 } else {
1134 skip_preamble = BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!;
1135 }
1136 /* RLE sub-stage. */
1137 {
1138 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! reps;
1139 if (!BrotliSafeReadBitscxx . . $ BrotliSafeReadBits(d859fb483c1e4a60).(br, code, &reps)) {
1140 h->codecxx . . $ BrotliMetablockHeaderArena#code. = code;
1141 h->context_indexcxx . . $ BrotliMetablockHeaderArena#context_index. = context_index;
1142 return BROTLI_DECODER_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_INPUT.;
1143 }
1144 reps += (brotli_reg_tcxx . . $ `c/common/platform.h:237:9`!)1U << code;
1145 BROTLI_LOG_UINTcxx . . $ `c/dec/decode.c:32:9`!(reps);
1146 if (context_index + reps > context_map_size) {
1147 return
1148 BROTLI_FAILUREcxx . . $ `c/dec/decode.c:30:9`!(BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT);
1149 }
1150 do {
1151 context_map[context_index++] = 0;
1152 } while (--reps);
1153 }
1154 }
1155 }
1156 /* Fall through. */
1157
1158 case BROTLI_STATE_CONTEXT_MAP_TRANSFORMcxx . . $ BROTLI_STATE_CONTEXT_MAP_TRANSFORM.: {
1159 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! bits;
1160 if (!BrotliSafeReadBitscxx . . $ BrotliSafeReadBits(d859fb483c1e4a60).(br, 1, &bits)) {
1161 h->substate_context_mapcxx . . $ BrotliMetablockHeaderArena#substate_context_map. = BROTLI_STATE_CONTEXT_MAP_TRANSFORMcxx . . $ BROTLI_STATE_CONTEXT_MAP_TRANSFORM.;
1162 return BROTLI_DECODER_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_INPUT.;
1163 }
1164 if (bits != 0) {
1165 InverseMoveToFrontTransformcxx . . $ InverseMoveToFrontTransform(9befc3ede1a11ed2).(*context_map_arg, context_map_size, s);
1166 }
1167 h->substate_context_mapcxx . . $ BrotliMetablockHeaderArena#substate_context_map. = BROTLI_STATE_CONTEXT_MAP_NONEcxx . . $ BROTLI_STATE_CONTEXT_MAP_NONE.;
1168 return BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.;
1169 }
1170
1171 default:
1172 return
1173 BROTLI_FAILUREcxx . . $ `c/dec/decode.c:30:9`!(BROTLI_DECODER_ERROR_UNREACHABLE); /* COV_NF_LINE */
1174 }
1175 }
1176
1177 /* Decodes a command or literal and updates block type ring-buffer.
1178 Reads 3..54 bits. */
1179 static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! DecodeBlockTypeAndLengthcxx . . $ DecodeBlockTypeAndLength(6be4606050b2fb8f).(
1180 int safe, BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s, int tree_type) {
1181 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! max_block_type = s->num_block_typescxx . . $ BrotliDecoderStateStruct#num_block_types.[tree_type];
1182 const HuffmanCodecxx . . $ HuffmanCode#* type_tree = &s->block_type_treescxx . . $ BrotliDecoderStateStruct#block_type_trees.[
1183 tree_type * BROTLI_HUFFMAN_MAX_SIZE_258cxx . . $ `c/dec/huffman.h:23:9`!];
1184 const HuffmanCodecxx . . $ HuffmanCode#* len_tree = &s->block_len_treescxx . . $ BrotliDecoderStateStruct#block_len_trees.[
1185 tree_type * BROTLI_HUFFMAN_MAX_SIZE_26cxx . . $ `c/dec/huffman.h:21:9`!];
1186 BrotliBitReadercxx . . $ BrotliBitReader#* br = &s->brcxx . . $ BrotliDecoderStateStruct#br.;
1187 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`!* ringbuffer = &s->block_type_rbcxx . . $ BrotliDecoderStateStruct#block_type_rb.[tree_type * 2];
1188 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! block_type;
1189 if (max_block_type <= 1) {
1190 return BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!;
1191 }
1192
1193 /* Read 0..15 + 3..39 bits. */
1194 if (!safe) {
1195 block_type = ReadSymbolcxx . . $ ReadSymbol(99805dca1a2a4b7b).(type_tree, br);
1196 s->block_lengthcxx . . $ BrotliDecoderStateStruct#block_length.[tree_type] = ReadBlockLengthcxx . . $ ReadBlockLength(99805dca1a2a4b7b).(len_tree, br);
1197 } else {
1198 BrotliBitReaderStatecxx . . $ BrotliBitReaderState# memento;
1199 BrotliBitReaderSaveStatecxx . . $ BrotliBitReaderSaveState(c49e3454873146cb).(br, &memento);
1200 if (!SafeReadSymbolcxx . . $ SafeReadSymbol(24ac31996b0a21de).(type_tree, br, &block_type)) return BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!;
1201 if (!SafeReadBlockLengthcxx . . $ SafeReadBlockLength(b640658b5edcb718).(s, &s->block_lengthcxx . . $ BrotliDecoderStateStruct#block_length.[tree_type], len_tree, br)) {
1202 s->substate_read_block_lengthcxx . . $ BrotliDecoderStateStruct#substate_read_block_length. = BROTLI_STATE_READ_BLOCK_LENGTH_NONEcxx . . $ BROTLI_STATE_READ_BLOCK_LENGTH_NONE.;
1203 BrotliBitReaderRestoreStatecxx . . $ BrotliBitReaderRestoreState(c49e3454873146cb).(br, &memento);
1204 return BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!;
1205 }
1206 }
1207
1208 if (block_type == 1) {
1209 block_type = ringbuffer[1] + 1;
1210 } else if (block_type == 0) {
1211 block_type = ringbuffer[0];
1212 } else {
1213 block_type -= 2;
1214 }
1215 if (block_type >= max_block_type) {
1216 block_type -= max_block_type;
1217 }
1218 ringbuffer[0] = ringbuffer[1];
1219 ringbuffer[1] = block_type;
1220 return BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!;
1221 }
1222
1223 static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! void DetectTrivialLiteralBlockTypescxx . . $ DetectTrivialLiteralBlockTypes(bb1fb99afd41e748).(
1224 BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s) {
1225 size_t i;
1226 for (i = 0; i < 8; ++i) s->trivial_literal_contextscxx . . $ BrotliDecoderStateStruct#trivial_literal_contexts.[i] = 0;
1227 for (i = 0; i < s->num_block_typescxx . . $ BrotliDecoderStateStruct#num_block_types.[0]; i++) {
1228 size_t offset = i << BROTLI_LITERAL_CONTEXT_BITScxx . . $ `c/common/constants.h:92:9`!;
1229 size_t error = 0;
1230 size_t sample = s->context_mapcxx . . $ BrotliDecoderStateStruct#context_map.[offset];
1231 size_t j;
1232 for (j = 0; j < (1u << BROTLI_LITERAL_CONTEXT_BITScxx . . $ `c/common/constants.h:92:9`!);) {
1233 /* NOLINTNEXTLINE(bugprone-macro-repeated-side-effects) */
1234 BROTLI_REPEAT_4cxx . . $ `c/common/platform.h:510:9`!({ error |= s->context_map[offset + j++] ^ sample; })
1235 }
1236 if (error == 0) {
1237 s->trivial_literal_contextscxx . . $ BrotliDecoderStateStruct#trivial_literal_contexts.[i >> 5] |= 1u << (i & 31);
1238 }
1239 }
1240 }
1241
1242 static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! void PrepareLiteralDecodingcxx . . $ PrepareLiteralDecoding(bb1fb99afd41e748).(BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s) {
1243 uint8_tcxx . . $ uint8_t# context_mode;
1244 size_t trivial;
1245 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! block_type = s->block_type_rbcxx . . $ BrotliDecoderStateStruct#block_type_rb.[1];
1246 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! context_offset = block_type << BROTLI_LITERAL_CONTEXT_BITScxx . . $ `c/common/constants.h:92:9`!;
1247 s->context_map_slicecxx . . $ BrotliDecoderStateStruct#context_map_slice. = s->context_mapcxx . . $ BrotliDecoderStateStruct#context_map. + context_offset;
1248 trivial = s->trivial_literal_contextscxx . . $ BrotliDecoderStateStruct#trivial_literal_contexts.[block_type >> 5];
1249 s->trivial_literal_contextcxx . . $ BrotliDecoderStateStruct#trivial_literal_context. = (trivial >> (block_type & 31)) & 1;
1250 s->literal_htreecxx . . $ BrotliDecoderStateStruct#literal_htree. = s->literal_hgroupcxx . . $ BrotliDecoderStateStruct#literal_hgroup..htreescxx . . $ $anonymous_type_421782d160a65272_1#htrees.[s->context_map_slicecxx . . $ BrotliDecoderStateStruct#context_map_slice.[0]];
1251 context_mode = s->context_modescxx . . $ BrotliDecoderStateStruct#context_modes.[block_type] & 3;
1252 s->context_lookupcxx . . $ BrotliDecoderStateStruct#context_lookup. = BROTLI_CONTEXT_LUTcxx . . $ `c/common/context.h:107:9`!(context_mode);
1253 }
1254
1255 /* Decodes the block type and updates the state for literal context.
1256 Reads 3..54 bits. */
1257 static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! DecodeLiteralBlockSwitchInternalcxx . . $ DecodeLiteralBlockSwitchInternal(539fdcda20afff18).(
1258 int safe, BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s) {
1259 if (!DecodeBlockTypeAndLengthcxx . . $ DecodeBlockTypeAndLength(6be4606050b2fb8f).(safe, s, 0)) {
1260 return BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!;
1261 }
1262 PrepareLiteralDecodingcxx . . $ PrepareLiteralDecoding(bb1fb99afd41e748).(s);
1263 return BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!;
1264 }
1265
1266 static void BROTLI_NOINLINEcxx . . $ `c/common/platform.h:137:9`! DecodeLiteralBlockSwitchcxx . . $ DecodeLiteralBlockSwitch(bb1fb99afd41e748).(BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s) {
1267 DecodeLiteralBlockSwitchInternalcxx . . $ DecodeLiteralBlockSwitchInternal(539fdcda20afff18).(0, s);
1268 }
1269
1270 static BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! BROTLI_NOINLINEcxx . . $ `c/common/platform.h:137:9`! SafeDecodeLiteralBlockSwitchcxx . . $ SafeDecodeLiteralBlockSwitch(c67463180bf96cf).(
1271 BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s) {
1272 return DecodeLiteralBlockSwitchInternalcxx . . $ DecodeLiteralBlockSwitchInternal(539fdcda20afff18).(1, s);
1273 }
1274
1275 /* Block switch for insert/copy length.
1276 Reads 3..54 bits. */
1277 static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! DecodeCommandBlockSwitchInternalcxx . . $ DecodeCommandBlockSwitchInternal(539fdcda20afff18).(
1278 int safe, BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s) {
1279 if (!DecodeBlockTypeAndLengthcxx . . $ DecodeBlockTypeAndLength(6be4606050b2fb8f).(safe, s, 1)) {
1280 return BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!;
1281 }
1282 s->htree_commandcxx . . $ BrotliDecoderStateStruct#htree_command. = s->insert_copy_hgroupcxx . . $ BrotliDecoderStateStruct#insert_copy_hgroup..htreescxx . . $ $anonymous_type_421782d160a65272_1#htrees.[s->block_type_rbcxx . . $ BrotliDecoderStateStruct#block_type_rb.[3]];
1283 return BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!;
1284 }
1285
1286 static void BROTLI_NOINLINEcxx . . $ `c/common/platform.h:137:9`! DecodeCommandBlockSwitchcxx . . $ DecodeCommandBlockSwitch(bb1fb99afd41e748).(BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s) {
1287 DecodeCommandBlockSwitchInternalcxx . . $ DecodeCommandBlockSwitchInternal(539fdcda20afff18).(0, s);
1288 }
1289
1290 static BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! BROTLI_NOINLINEcxx . . $ `c/common/platform.h:137:9`! SafeDecodeCommandBlockSwitchcxx . . $ SafeDecodeCommandBlockSwitch(c67463180bf96cf).(
1291 BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s) {
1292 return DecodeCommandBlockSwitchInternalcxx . . $ DecodeCommandBlockSwitchInternal(539fdcda20afff18).(1, s);
1293 }
1294
1295 /* Block switch for distance codes.
1296 Reads 3..54 bits. */
1297 static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! DecodeDistanceBlockSwitchInternalcxx . . $ DecodeDistanceBlockSwitchInternal(539fdcda20afff18).(
1298 int safe, BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s) {
1299 if (!DecodeBlockTypeAndLengthcxx . . $ DecodeBlockTypeAndLength(6be4606050b2fb8f).(safe, s, 2)) {
1300 return BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!;
1301 }
1302 s->dist_context_map_slicecxx . . $ BrotliDecoderStateStruct#dist_context_map_slice. = s->dist_context_mapcxx . . $ BrotliDecoderStateStruct#dist_context_map. +
1303 (s->block_type_rbcxx . . $ BrotliDecoderStateStruct#block_type_rb.[5] << BROTLI_DISTANCE_CONTEXT_BITScxx . . $ `c/common/constants.h:95:9`!);
1304 s->dist_htree_indexcxx . . $ BrotliDecoderStateStruct#dist_htree_index. = s->dist_context_map_slicecxx . . $ BrotliDecoderStateStruct#dist_context_map_slice.[s->distance_contextcxx . . $ BrotliDecoderStateStruct#distance_context.];
1305 return BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!;
1306 }
1307
1308 static void BROTLI_NOINLINEcxx . . $ `c/common/platform.h:137:9`! DecodeDistanceBlockSwitchcxx . . $ DecodeDistanceBlockSwitch(bb1fb99afd41e748).(BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s) {
1309 DecodeDistanceBlockSwitchInternalcxx . . $ DecodeDistanceBlockSwitchInternal(539fdcda20afff18).(0, s);
1310 }
1311
1312 static BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! BROTLI_NOINLINEcxx . . $ `c/common/platform.h:137:9`! SafeDecodeDistanceBlockSwitchcxx . . $ SafeDecodeDistanceBlockSwitch(c67463180bf96cf).(
1313 BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s) {
1314 return DecodeDistanceBlockSwitchInternalcxx . . $ DecodeDistanceBlockSwitchInternal(539fdcda20afff18).(1, s);
1315 }
1316
1317 static size_t UnwrittenBytescxx . . $ UnwrittenBytes(4f3e99c12927eda6).(const BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s, BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! wrap) {
1318 size_t pos = wrap && s->poscxx . . $ BrotliDecoderStateStruct#pos. > s->ringbuffer_sizecxx . . $ BrotliDecoderStateStruct#ringbuffer_size. ?
1319 (size_t)s->ringbuffer_sizecxx . . $ BrotliDecoderStateStruct#ringbuffer_size. : (size_t)(s->poscxx . . $ BrotliDecoderStateStruct#pos.);
1320 size_t partial_pos_rb = (s->rb_roundtripscxx . . $ BrotliDecoderStateStruct#rb_roundtrips. * (size_t)s->ringbuffer_sizecxx . . $ BrotliDecoderStateStruct#ringbuffer_size.) + pos;
1321 return partial_pos_rb - s->partial_pos_outcxx . . $ BrotliDecoderStateStruct#partial_pos_out.;
1322 }
1323
1324 /* Dumps output.
1325 Returns BROTLI_DECODER_NEEDS_MORE_OUTPUT only if there is more output to push
1326 and either ring-buffer is as big as window size, or |force| is true. */
1327 static BrotliDecoderErrorCodecxx . . $ BrotliDecoderErrorCode# BROTLI_NOINLINEcxx . . $ `c/common/platform.h:137:9`! WriteRingBuffercxx . . $ WriteRingBuffer(717a5536caf5ab00).(
1328 BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s, size_t* available_out, uint8_tcxx . . $ uint8_t#** next_out,
1329 size_t* total_out, BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! force) {
1330 uint8_tcxx . . $ uint8_t#* start =
1331 s->ringbuffercxx . . $ BrotliDecoderStateStruct#ringbuffer. + (s->partial_pos_outcxx . . $ BrotliDecoderStateStruct#partial_pos_out. & (size_t)s->ringbuffer_maskcxx . . $ BrotliDecoderStateStruct#ringbuffer_mask.);
1332 size_t to_write = UnwrittenBytescxx . . $ UnwrittenBytes(4f3e99c12927eda6).(s, BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!);
1333 size_t num_written = *available_out;
1334 if (num_written > to_write) {
1335 num_written = to_write;
1336 }
1337 if (s->meta_block_remaining_lencxx . . $ BrotliDecoderStateStruct#meta_block_remaining_len. < 0) {
1338 return BROTLI_FAILUREcxx . . $ `c/dec/decode.c:30:9`!(BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1);
1339 }
1340 if (next_out && !*next_out) {
1341 *next_out = start;
1342 } else {
1343 if (next_out) {
1344 memcpycxx . . $ memcpy(cc817cb175f282d).(*next_out, start, num_written);
1345 *next_out += num_written;
1346 }
1347 }
1348 *available_out -= num_written;
1349 BROTLI_LOG_UINTcxx . . $ `c/dec/decode.c:32:9`!(to_write);
1350 BROTLI_LOG_UINTcxx . . $ `c/dec/decode.c:32:9`!(num_written);
1351 s->partial_pos_outcxx . . $ BrotliDecoderStateStruct#partial_pos_out. += num_written;
1352 if (total_out) {
1353 *total_out = s->partial_pos_outcxx . . $ BrotliDecoderStateStruct#partial_pos_out.;
1354 }
1355 if (num_written < to_write) {
1356 if (s->ringbuffer_sizecxx . . $ BrotliDecoderStateStruct#ringbuffer_size. == (1 << s->window_bitscxx . . $ BrotliDecoderStateStruct#window_bits.) || force) {
1357 return BROTLI_DECODER_NEEDS_MORE_OUTPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_OUTPUT.;
1358 } else {
1359 return BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.;
1360 }
1361 }
1362 /* Wrap ring buffer only if it has reached its maximal size. */
1363 if (s->ringbuffer_sizecxx . . $ BrotliDecoderStateStruct#ringbuffer_size. == (1 << s->window_bitscxx . . $ BrotliDecoderStateStruct#window_bits.) &&
1364 s->poscxx . . $ BrotliDecoderStateStruct#pos. >= s->ringbuffer_sizecxx . . $ BrotliDecoderStateStruct#ringbuffer_size.) {
1365 s->poscxx . . $ BrotliDecoderStateStruct#pos. -= s->ringbuffer_sizecxx . . $ BrotliDecoderStateStruct#ringbuffer_size.;
1366 s->rb_roundtripscxx . . $ BrotliDecoderStateStruct#rb_roundtrips.++;
1367 s->should_wrap_ringbuffercxx . . $ BrotliDecoderStateStruct#should_wrap_ringbuffer. = (size_t)s->poscxx . . $ BrotliDecoderStateStruct#pos. != 0 ? 1 : 0;
1368 }
1369 return BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.;
1370 }
1371
1372 static void BROTLI_NOINLINEcxx . . $ `c/common/platform.h:137:9`! WrapRingBuffercxx . . $ WrapRingBuffer(bb1fb99afd41e748).(BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s) {
1373 if (s->should_wrap_ringbuffercxx . . $ BrotliDecoderStateStruct#should_wrap_ringbuffer.) {
1374 memcpycxx . . $ memcpy(cc817cb175f282d).(s->ringbuffercxx . . $ BrotliDecoderStateStruct#ringbuffer., s->ringbuffer_endcxx . . $ BrotliDecoderStateStruct#ringbuffer_end., (size_t)s->poscxx . . $ BrotliDecoderStateStruct#pos.);
1375 s->should_wrap_ringbuffercxx . . $ BrotliDecoderStateStruct#should_wrap_ringbuffer. = 0;
1376 }
1377 }
1378
1379 /* Allocates ring-buffer.
1380
1381 s->ringbuffer_size MUST be updated by BrotliCalculateRingBufferSize before
1382 this function is called.
1383
1384 Last two bytes of ring-buffer are initialized to 0, so context calculation
1385 could be done uniformly for the first two and all other positions. */
1386 static BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! BROTLI_NOINLINEcxx . . $ `c/common/platform.h:137:9`! BrotliEnsureRingBuffercxx . . $ BrotliEnsureRingBuffer(c67463180bf96cf).(
1387 BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s) {
1388 uint8_tcxx . . $ uint8_t#* old_ringbuffer = s->ringbuffercxx . . $ BrotliDecoderStateStruct#ringbuffer.;
1389 if (s->ringbuffer_sizecxx . . $ BrotliDecoderStateStruct#ringbuffer_size. == s->new_ringbuffer_sizecxx . . $ BrotliDecoderStateStruct#new_ringbuffer_size.) {
1390 return BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!;
1391 }
1392
1393 s->ringbuffercxx . . $ BrotliDecoderStateStruct#ringbuffer. = (uint8_tcxx . . $ uint8_t#*)BROTLI_DECODER_ALLOCcxx . . $ `c/dec/state.h:381:9`!(s,
1394 (size_t)(s->new_ringbuffer_size) + kRingBufferWriteAheadSlack);
1395 if (s->ringbuffercxx . . $ BrotliDecoderStateStruct#ringbuffer. == 0) {
1396 /* Restore previous value. */
1397 s->ringbuffercxx . . $ BrotliDecoderStateStruct#ringbuffer. = old_ringbuffer;
1398 return BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!;
1399 }
1400 s->ringbuffercxx . . $ BrotliDecoderStateStruct#ringbuffer.[s->new_ringbuffer_sizecxx . . $ BrotliDecoderStateStruct#new_ringbuffer_size. - 2] = 0;
1401 s->ringbuffercxx . . $ BrotliDecoderStateStruct#ringbuffer.[s->new_ringbuffer_sizecxx . . $ BrotliDecoderStateStruct#new_ringbuffer_size. - 1] = 0;
1402
1403 if (!!old_ringbuffer) {
1404 memcpycxx . . $ memcpy(cc817cb175f282d).(s->ringbuffercxx . . $ BrotliDecoderStateStruct#ringbuffer., old_ringbuffer, (size_t)s->poscxx . . $ BrotliDecoderStateStruct#pos.);
1405 BROTLI_DECODER_FREEcxx . . $ `c/dec/state.h:383:9`!(s, old_ringbuffer);
1406 }
1407
1408 s->ringbuffer_sizecxx . . $ BrotliDecoderStateStruct#ringbuffer_size. = s->new_ringbuffer_sizecxx . . $ BrotliDecoderStateStruct#new_ringbuffer_size.;
1409 s->ringbuffer_maskcxx . . $ BrotliDecoderStateStruct#ringbuffer_mask. = s->new_ringbuffer_sizecxx . . $ BrotliDecoderStateStruct#new_ringbuffer_size. - 1;
1410 s->ringbuffer_endcxx . . $ BrotliDecoderStateStruct#ringbuffer_end. = s->ringbuffercxx . . $ BrotliDecoderStateStruct#ringbuffer. + s->ringbuffer_sizecxx . . $ BrotliDecoderStateStruct#ringbuffer_size.;
1411
1412 return BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!;
1413 }
1414
1415 static BrotliDecoderErrorCodecxx . . $ BrotliDecoderErrorCode# BROTLI_NOINLINEcxx . . $ `c/common/platform.h:137:9`!
1416 SkipMetadataBlockcxx . . $ SkipMetadataBlock(fe8ed989e3875dcf).(BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s) {
1417 BrotliBitReadercxx . . $ BrotliBitReader#* br = &s->brcxx . . $ BrotliDecoderStateStruct#br.;
1418 int nbytes;
1419
1420 if (s->meta_block_remaining_lencxx . . $ BrotliDecoderStateStruct#meta_block_remaining_len. == 0) {
1421 return BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.;
1422 }
1423
1424 BROTLI_DCHECKcxx . . $ `c/common/platform.h:473:9`!((BrotliGetAvailableBits(br) & 7) == 0);
1425
1426 /* Drain accumulator. */
1427 if (BrotliGetAvailableBitscxx . . $ BrotliGetAvailableBits(d61fb7f759d9fbb3).(br) >= 8) {
1428 uint8_tcxx . . $ uint8_t# buffer[8];
1429 nbytes = (int)(BrotliGetAvailableBitscxx . . $ BrotliGetAvailableBits(d61fb7f759d9fbb3).(br)) >> 3;
1430 BROTLI_DCHECKcxx . . $ `c/common/platform.h:473:9`!(nbytes <= 8);
1431 if (nbytes > s->meta_block_remaining_lencxx . . $ BrotliDecoderStateStruct#meta_block_remaining_len.) {
1432 nbytes = s->meta_block_remaining_lencxx . . $ BrotliDecoderStateStruct#meta_block_remaining_len.;
1433 }
1434 BrotliCopyBytescxx . . $ BrotliCopyBytes(d008cefe4a22b384).(buffer, br, (size_t)nbytes);
1435 if (s->metadata_chunk_funccxx . . $ BrotliDecoderStateStruct#metadata_chunk_func.) {
1436 s->metadata_chunk_funccxx . . $ BrotliDecoderStateStruct#metadata_chunk_func.(s->metadata_callback_opaquecxx . . $ BrotliDecoderStateStruct#metadata_callback_opaque., buffer,
1437 (size_t)nbytes);
1438 }
1439 s->meta_block_remaining_lencxx . . $ BrotliDecoderStateStruct#meta_block_remaining_len. -= nbytes;
1440 if (s->meta_block_remaining_lencxx . . $ BrotliDecoderStateStruct#meta_block_remaining_len. == 0) {
1441 return BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.;
1442 }
1443 }
1444
1445 /* Direct access to metadata is possible. */
1446 nbytes = (int)BrotliGetRemainingBytescxx . . $ BrotliGetRemainingBytes(a8eec9f290bacd2d).(br);
1447 if (nbytes > s->meta_block_remaining_lencxx . . $ BrotliDecoderStateStruct#meta_block_remaining_len.) {
1448 nbytes = s->meta_block_remaining_lencxx . . $ BrotliDecoderStateStruct#meta_block_remaining_len.;
1449 }
1450 if (nbytes > 0) {
1451 if (s->metadata_chunk_funccxx . . $ BrotliDecoderStateStruct#metadata_chunk_func.) {
1452 s->metadata_chunk_funccxx . . $ BrotliDecoderStateStruct#metadata_chunk_func.(s->metadata_callback_opaquecxx . . $ BrotliDecoderStateStruct#metadata_callback_opaque., br->next_incxx . . $ $anonymous_type_83261257069d1fbd_0#next_in.,
1453 (size_t)nbytes);
1454 }
1455 BrotliDropBytescxx . . $ BrotliDropBytes(aea9ea103d4b1d3f).(br, (size_t)nbytes);
1456 s->meta_block_remaining_lencxx . . $ BrotliDecoderStateStruct#meta_block_remaining_len. -= nbytes;
1457 if (s->meta_block_remaining_lencxx . . $ BrotliDecoderStateStruct#meta_block_remaining_len. == 0) {
1458 return BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.;
1459 }
1460 }
1461
1462 BROTLI_DCHECKcxx . . $ `c/common/platform.h:473:9`!(BrotliGetRemainingBytes(br) == 0);
1463
1464 return BROTLI_DECODER_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_INPUT.;
1465 }
1466
1467 static BrotliDecoderErrorCodecxx . . $ BrotliDecoderErrorCode# BROTLI_NOINLINEcxx . . $ `c/common/platform.h:137:9`! CopyUncompressedBlockToOutputcxx . . $ CopyUncompressedBlockToOutput(fa575b40a6b6367e).(
1468 size_t* available_out, uint8_tcxx . . $ uint8_t#** next_out, size_t* total_out,
1469 BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s) {
1470 /* TODO(eustas): avoid allocation for single uncompressed block. */
1471 if (!BrotliEnsureRingBuffercxx . . $ BrotliEnsureRingBuffer(c67463180bf96cf).(s)) {
1472 return BROTLI_FAILUREcxx . . $ `c/dec/decode.c:30:9`!(BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1);
1473 }
1474
1475 /* State machine */
1476 for (;;) {
1477 switch (s->substate_uncompressedcxx . . $ BrotliDecoderStateStruct#substate_uncompressed.) {
1478 case BROTLI_STATE_UNCOMPRESSED_NONEcxx . . $ BROTLI_STATE_UNCOMPRESSED_NONE.: {
1479 int nbytes = (int)BrotliGetRemainingBytescxx . . $ BrotliGetRemainingBytes(a8eec9f290bacd2d).(&s->brcxx . . $ BrotliDecoderStateStruct#br.);
1480 if (nbytes > s->meta_block_remaining_lencxx . . $ BrotliDecoderStateStruct#meta_block_remaining_len.) {
1481 nbytes = s->meta_block_remaining_lencxx . . $ BrotliDecoderStateStruct#meta_block_remaining_len.;
1482 }
1483 if (s->poscxx . . $ BrotliDecoderStateStruct#pos. + nbytes > s->ringbuffer_sizecxx . . $ BrotliDecoderStateStruct#ringbuffer_size.) {
1484 nbytes = s->ringbuffer_sizecxx . . $ BrotliDecoderStateStruct#ringbuffer_size. - s->poscxx . . $ BrotliDecoderStateStruct#pos.;
1485 }
1486 /* Copy remaining bytes from s->br.buf_ to ring-buffer. */
1487 BrotliCopyBytescxx . . $ BrotliCopyBytes(d008cefe4a22b384).(&s->ringbuffercxx . . $ BrotliDecoderStateStruct#ringbuffer.[s->poscxx . . $ BrotliDecoderStateStruct#pos.], &s->brcxx . . $ BrotliDecoderStateStruct#br., (size_t)nbytes);
1488 s->poscxx . . $ BrotliDecoderStateStruct#pos. += nbytes;
1489 s->meta_block_remaining_lencxx . . $ BrotliDecoderStateStruct#meta_block_remaining_len. -= nbytes;
1490 if (s->poscxx . . $ BrotliDecoderStateStruct#pos. < 1 << s->window_bitscxx . . $ BrotliDecoderStateStruct#window_bits.) {
1491 if (s->meta_block_remaining_lencxx . . $ BrotliDecoderStateStruct#meta_block_remaining_len. == 0) {
1492 return BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.;
1493 }
1494 return BROTLI_DECODER_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_INPUT.;
1495 }
1496 s->substate_uncompressedcxx . . $ BrotliDecoderStateStruct#substate_uncompressed. = BROTLI_STATE_UNCOMPRESSED_WRITEcxx . . $ BROTLI_STATE_UNCOMPRESSED_WRITE.;
1497 }
1498 /* Fall through. */
1499
1500 case BROTLI_STATE_UNCOMPRESSED_WRITEcxx . . $ BROTLI_STATE_UNCOMPRESSED_WRITE.: {
1501 BrotliDecoderErrorCodecxx . . $ BrotliDecoderErrorCode# result;
1502 result = WriteRingBuffercxx . . $ WriteRingBuffer(717a5536caf5ab00).(
1503 s, available_out, next_out, total_out, BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!);
1504 if (result != BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.) {
1505 return result;
1506 }
1507 if (s->ringbuffer_sizecxx . . $ BrotliDecoderStateStruct#ringbuffer_size. == 1 << s->window_bitscxx . . $ BrotliDecoderStateStruct#window_bits.) {
1508 s->max_distancecxx . . $ BrotliDecoderStateStruct#max_distance. = s->max_backward_distancecxx . . $ BrotliDecoderStateStruct#max_backward_distance.;
1509 }
1510 s->substate_uncompressedcxx . . $ BrotliDecoderStateStruct#substate_uncompressed. = BROTLI_STATE_UNCOMPRESSED_NONEcxx . . $ BROTLI_STATE_UNCOMPRESSED_NONE.;
1511 break;
1512 }
1513 }
1514 }
1515 BROTLI_DCHECKcxx . . $ `c/common/platform.h:473:9`!(0); /* Unreachable */
1516 }
1517
1518 static BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! AttachCompoundDictionarycxx . . $ AttachCompoundDictionary(15c5a64c0e863726).(
1519 BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* state, const uint8_tcxx . . $ uint8_t#* data, size_t size) {
1520 BrotliDecoderCompoundDictionarycxx . . $ BrotliDecoderCompoundDictionary#* addon = state->compound_dictionarycxx . . $ BrotliDecoderStateStruct#compound_dictionary.;
1521 if (state->statecxx . . $ BrotliDecoderStateStruct#state. != BROTLI_STATE_UNINITEDcxx . . $ BROTLI_STATE_UNINITED.) return BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!;
1522 if (!addon) {
1523 addon = (BrotliDecoderCompoundDictionarycxx . . $ BrotliDecoderCompoundDictionary#*)BROTLI_DECODER_ALLOCcxx . . $ `c/dec/state.h:381:9`!(
1524 state, sizeof(BrotliDecoderCompoundDictionary));
1525 if (!addon) return BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!;
1526 addon->num_chunkscxx . . $ BrotliDecoderCompoundDictionary#num_chunks. = 0;
1527 addon->total_sizecxx . . $ BrotliDecoderCompoundDictionary#total_size. = 0;
1528 addon->br_lengthcxx . . $ BrotliDecoderCompoundDictionary#br_length. = 0;
1529 addon->br_copiedcxx . . $ BrotliDecoderCompoundDictionary#br_copied. = 0;
1530 addon->block_bitscxx . . $ BrotliDecoderCompoundDictionary#block_bits. = -1;
1531 addon->chunk_offsetscxx . . $ BrotliDecoderCompoundDictionary#chunk_offsets.[0] = 0;
1532 state->compound_dictionarycxx . . $ BrotliDecoderStateStruct#compound_dictionary. = addon;
1533 }
1534 if (addon->num_chunkscxx . . $ BrotliDecoderCompoundDictionary#num_chunks. == 15) return BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!;
1535 addon->chunkscxx . . $ BrotliDecoderCompoundDictionary#chunks.[addon->num_chunkscxx . . $ BrotliDecoderCompoundDictionary#num_chunks.] = data;
1536 addon->num_chunkscxx . . $ BrotliDecoderCompoundDictionary#num_chunks.++;
1537 addon->total_sizecxx . . $ BrotliDecoderCompoundDictionary#total_size. += (int)size;
1538 addon->chunk_offsetscxx . . $ BrotliDecoderCompoundDictionary#chunk_offsets.[addon->num_chunkscxx . . $ BrotliDecoderCompoundDictionary#num_chunks.] = addon->total_sizecxx . . $ BrotliDecoderCompoundDictionary#total_size.;
1539 return BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!;
1540 }
1541
1542 static void EnsureCompoundDictionaryInitializedcxx . . $ EnsureCompoundDictionaryInitialized(bb1fb99afd41e748).(BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* state) {
1543 BrotliDecoderCompoundDictionarycxx . . $ BrotliDecoderCompoundDictionary#* addon = state->compound_dictionarycxx . . $ BrotliDecoderStateStruct#compound_dictionary.;
1544 /* 256 = (1 << 8) slots in block map. */
1545 int block_bits = 8;
1546 int cursor = 0;
1547 int index = 0;
1548 if (addon->block_bitscxx . . $ BrotliDecoderCompoundDictionary#block_bits. != -1) return;
1549 while (((addon->total_sizecxx . . $ BrotliDecoderCompoundDictionary#total_size. - 1) >> block_bits) != 0) block_bits++;
1550 block_bits -= 8;
1551 addon->block_bitscxx . . $ BrotliDecoderCompoundDictionary#block_bits. = block_bits;
1552 while (cursor < addon->total_sizecxx . . $ BrotliDecoderCompoundDictionary#total_size.) {
1553 while (addon->chunk_offsetscxx . . $ BrotliDecoderCompoundDictionary#chunk_offsets.[index + 1] < cursor) index++;
1554 addon->block_mapcxx . . $ BrotliDecoderCompoundDictionary#block_map.[cursor >> block_bits] = (uint8_tcxx . . $ uint8_t#)index;
1555 cursor += 1 << block_bits;
1556 }
1557 }
1558
1559 static BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! InitializeCompoundDictionaryCopycxx . . $ InitializeCompoundDictionaryCopy(5b5a49a29526ad00).(BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s,
1560 int address, int length) {
1561 BrotliDecoderCompoundDictionarycxx . . $ BrotliDecoderCompoundDictionary#* addon = s->compound_dictionarycxx . . $ BrotliDecoderStateStruct#compound_dictionary.;
1562 int index;
1563 EnsureCompoundDictionaryInitializedcxx . . $ EnsureCompoundDictionaryInitialized(bb1fb99afd41e748).(s);
1564 index = addon->block_mapcxx . . $ BrotliDecoderCompoundDictionary#block_map.[address >> addon->block_bitscxx . . $ BrotliDecoderCompoundDictionary#block_bits.];
1565 while (address >= addon->chunk_offsetscxx . . $ BrotliDecoderCompoundDictionary#chunk_offsets.[index + 1]) index++;
1566 if (addon->total_sizecxx . . $ BrotliDecoderCompoundDictionary#total_size. < address + length) return BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!;
1567 /* Update the recent distances cache. */
1568 s->dist_rbcxx . . $ BrotliDecoderStateStruct#dist_rb.[s->dist_rb_idxcxx . . $ BrotliDecoderStateStruct#dist_rb_idx. & 3] = s->distance_codecxx . . $ BrotliDecoderStateStruct#distance_code.;
1569 ++s->dist_rb_idxcxx . . $ BrotliDecoderStateStruct#dist_rb_idx.;
1570 s->meta_block_remaining_lencxx . . $ BrotliDecoderStateStruct#meta_block_remaining_len. -= length;
1571 addon->br_indexcxx . . $ BrotliDecoderCompoundDictionary#br_index. = index;
1572 addon->br_offsetcxx . . $ BrotliDecoderCompoundDictionary#br_offset. = address - addon->chunk_offsetscxx . . $ BrotliDecoderCompoundDictionary#chunk_offsets.[index];
1573 addon->br_lengthcxx . . $ BrotliDecoderCompoundDictionary#br_length. = length;
1574 addon->br_copiedcxx . . $ BrotliDecoderCompoundDictionary#br_copied. = 0;
1575 return BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!;
1576 }
1577
1578 static int GetCompoundDictionarySizecxx . . $ GetCompoundDictionarySize(c67463180bf96cf).(BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s) {
1579 return s->compound_dictionarycxx . . $ BrotliDecoderStateStruct#compound_dictionary. ? s->compound_dictionarycxx . . $ BrotliDecoderStateStruct#compound_dictionary.->total_sizecxx . . $ BrotliDecoderCompoundDictionary#total_size. : 0;
1580 }
1581
1582 static int CopyFromCompoundDictionarycxx . . $ CopyFromCompoundDictionary(f13d6527b0ad88d0).(BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s, int pos) {
1583 BrotliDecoderCompoundDictionarycxx . . $ BrotliDecoderCompoundDictionary#* addon = s->compound_dictionarycxx . . $ BrotliDecoderStateStruct#compound_dictionary.;
1584 int orig_pos = pos;
1585 while (addon->br_lengthcxx . . $ BrotliDecoderCompoundDictionary#br_length. != addon->br_copiedcxx . . $ BrotliDecoderCompoundDictionary#br_copied.) {
1586 uint8_tcxx . . $ uint8_t#* copy_dst = &s->ringbuffercxx . . $ BrotliDecoderStateStruct#ringbuffer.[pos];
1587 const uint8_tcxx . . $ uint8_t#* copy_src =
1588 addon->chunkscxx . . $ BrotliDecoderCompoundDictionary#chunks.[addon->br_indexcxx . . $ BrotliDecoderCompoundDictionary#br_index.] + addon->br_offsetcxx . . $ BrotliDecoderCompoundDictionary#br_offset.;
1589 int space = s->ringbuffer_sizecxx . . $ BrotliDecoderStateStruct#ringbuffer_size. - pos;
1590 int rem_chunk_length = (addon->chunk_offsetscxx . . $ BrotliDecoderCompoundDictionary#chunk_offsets.[addon->br_indexcxx . . $ BrotliDecoderCompoundDictionary#br_index. + 1] -
1591 addon->chunk_offsetscxx . . $ BrotliDecoderCompoundDictionary#chunk_offsets.[addon->br_indexcxx . . $ BrotliDecoderCompoundDictionary#br_index.]) - addon->br_offsetcxx . . $ BrotliDecoderCompoundDictionary#br_offset.;
1592 int length = addon->br_lengthcxx . . $ BrotliDecoderCompoundDictionary#br_length. - addon->br_copiedcxx . . $ BrotliDecoderCompoundDictionary#br_copied.;
1593 if (length > rem_chunk_length) length = rem_chunk_length;
1594 if (length > space) length = space;
1595 memcpycxx . . $ memcpy(cc817cb175f282d).(copy_dst, copy_src, (size_t)length);
1596 pos += length;
1597 addon->br_offsetcxx . . $ BrotliDecoderCompoundDictionary#br_offset. += length;
1598 addon->br_copiedcxx . . $ BrotliDecoderCompoundDictionary#br_copied. += length;
1599 if (length == rem_chunk_length) {
1600 addon->br_indexcxx . . $ BrotliDecoderCompoundDictionary#br_index.++;
1601 addon->br_offsetcxx . . $ BrotliDecoderCompoundDictionary#br_offset. = 0;
1602 }
1603 if (pos == s->ringbuffer_sizecxx . . $ BrotliDecoderStateStruct#ringbuffer_size.) break;
1604 }
1605 return pos - orig_pos;
1606 }
1607
1608 BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! BrotliDecoderAttachDictionarycxx . . $ BrotliDecoderAttachDictionary(b159b47f130a2167).(
1609 BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* state, BrotliSharedDictionaryTypecxx . . $ BrotliSharedDictionaryType# type,
1610 size_t data_size, const uint8_tcxx . . $ uint8_t# data[BROTLI_ARRAY_PARAMcxx . . $ `c/include/brotli/port.h:263:9`!(data_size)]) {
1611 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! i;
1612 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! num_prefix_before = state->dictionarycxx . . $ BrotliDecoderStateStruct#dictionary.->num_prefixcxx . . $ BrotliSharedDictionaryStruct#num_prefix.;
1613 if (state->statecxx . . $ BrotliDecoderStateStruct#state. != BROTLI_STATE_UNINITEDcxx . . $ BROTLI_STATE_UNINITED.) return BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!;
1614 if (!BrotliSharedDictionaryAttachcxx . . $ BrotliSharedDictionaryAttach(1c61f0b5d13ac547).(state->dictionarycxx . . $ BrotliDecoderStateStruct#dictionary., type, data_size, data)) {
1615 return BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!;
1616 }
1617 for (i = num_prefix_before; i < state->dictionarycxx . . $ BrotliDecoderStateStruct#dictionary.->num_prefixcxx . . $ BrotliSharedDictionaryStruct#num_prefix.; i++) {
1618 if (!AttachCompoundDictionarycxx . . $ AttachCompoundDictionary(15c5a64c0e863726).(
1619 state, state->dictionarycxx . . $ BrotliDecoderStateStruct#dictionary.->prefixcxx . . $ BrotliSharedDictionaryStruct#prefix.[i],
1620 state->dictionarycxx . . $ BrotliDecoderStateStruct#dictionary.->prefix_sizecxx . . $ BrotliSharedDictionaryStruct#prefix_size.[i])) {
1621 return BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!;
1622 }
1623 }
1624 return BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!;
1625 }
1626
1627 /* Calculates the smallest feasible ring buffer.
1628
1629 If we know the data size is small, do not allocate more ring buffer
1630 size than needed to reduce memory usage.
1631
1632 When this method is called, metablock size and flags MUST be decoded. */
1633 static void BROTLI_NOINLINEcxx . . $ `c/common/platform.h:137:9`! BrotliCalculateRingBufferSizecxx . . $ BrotliCalculateRingBufferSize(bb1fb99afd41e748).(
1634 BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s) {
1635 int window_size = 1 << s->window_bitscxx . . $ BrotliDecoderStateStruct#window_bits.;
1636 int new_ringbuffer_size = window_size;
1637 /* We need at least 2 bytes of ring buffer size to get the last two
1638 bytes for context from there */
1639 int min_size = s->ringbuffer_sizecxx . . $ BrotliDecoderStateStruct#ringbuffer_size. ? s->ringbuffer_sizecxx . . $ BrotliDecoderStateStruct#ringbuffer_size. : 1024;
1640 int output_size;
1641
1642 /* If maximum is already reached, no further extension is retired. */
1643 if (s->ringbuffer_sizecxx . . $ BrotliDecoderStateStruct#ringbuffer_size. == window_size) {
1644 return;
1645 }
1646
1647 /* Metadata blocks does not touch ring buffer. */
1648 if (s->is_metadatacxx . . $ BrotliDecoderStateStruct#is_metadata.) {
1649 return;
1650 }
1651
1652 if (!s->ringbuffercxx . . $ BrotliDecoderStateStruct#ringbuffer.) {
1653 output_size = 0;
1654 } else {
1655 output_size = s->poscxx . . $ BrotliDecoderStateStruct#pos.;
1656 }
1657 output_size += s->meta_block_remaining_lencxx . . $ BrotliDecoderStateStruct#meta_block_remaining_len.;
1658 min_size = min_size < output_size ? output_size : min_size;
1659
1660 if (!!s->canny_ringbuffer_allocationcxx . . $ BrotliDecoderStateStruct#canny_ringbuffer_allocation.) {
1661 /* Reduce ring buffer size to save memory when server is unscrupulous.
1662 In worst case memory usage might be 1.5x bigger for a short period of
1663 ring buffer reallocation. */
1664 while ((new_ringbuffer_size >> 1) >= min_size) {
1665 new_ringbuffer_size >>= 1;
1666 }
1667 }
1668
1669 s->new_ringbuffer_sizecxx . . $ BrotliDecoderStateStruct#new_ringbuffer_size. = new_ringbuffer_size;
1670 }
1671
1672 /* Reads 1..256 2-bit context modes. */
1673 static BrotliDecoderErrorCodecxx . . $ BrotliDecoderErrorCode# ReadContextModescxx . . $ ReadContextModes(fe8ed989e3875dcf).(BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s) {
1674 BrotliBitReadercxx . . $ BrotliBitReader#* br = &s->brcxx . . $ BrotliDecoderStateStruct#br.;
1675 int i = s->loop_countercxx . . $ BrotliDecoderStateStruct#loop_counter.;
1676
1677 while (i < (int)s->num_block_typescxx . . $ BrotliDecoderStateStruct#num_block_types.[0]) {
1678 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! bits;
1679 if (!BrotliSafeReadBitscxx . . $ BrotliSafeReadBits(d859fb483c1e4a60).(br, 2, &bits)) {
1680 s->loop_countercxx . . $ BrotliDecoderStateStruct#loop_counter. = i;
1681 return BROTLI_DECODER_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_INPUT.;
1682 }
1683 s->context_modescxx . . $ BrotliDecoderStateStruct#context_modes.[i] = (uint8_tcxx . . $ uint8_t#)bits;
1684 BROTLI_LOG_ARRAY_INDEXcxx . . $ `c/dec/decode.c:34:9`!(s->context_modes, i);
1685 i++;
1686 }
1687 return BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.;
1688 }
1689
1690 static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! void TakeDistanceFromRingBuffercxx . . $ TakeDistanceFromRingBuffer(bb1fb99afd41e748).(BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s) {
1691 int offset = s->distance_codecxx . . $ BrotliDecoderStateStruct#distance_code. - 3;
1692 if (s->distance_codecxx . . $ BrotliDecoderStateStruct#distance_code. <= 3) {
1693 /* Compensate double distance-ring-buffer roll for dictionary items. */
1694 s->distance_contextcxx . . $ BrotliDecoderStateStruct#distance_context. = 1 >> s->distance_codecxx . . $ BrotliDecoderStateStruct#distance_code.;
1695 s->distance_codecxx . . $ BrotliDecoderStateStruct#distance_code. = s->dist_rbcxx . . $ BrotliDecoderStateStruct#dist_rb.[(s->dist_rb_idxcxx . . $ BrotliDecoderStateStruct#dist_rb_idx. - offset) & 3];
1696 s->dist_rb_idxcxx . . $ BrotliDecoderStateStruct#dist_rb_idx. -= s->distance_contextcxx . . $ BrotliDecoderStateStruct#distance_context.;
1697 } else {
1698 int index_delta = 3;
1699 int delta;
1700 int base = s->distance_codecxx . . $ BrotliDecoderStateStruct#distance_code. - 10;
1701 if (s->distance_codecxx . . $ BrotliDecoderStateStruct#distance_code. < 10) {
1702 base = s->distance_codecxx . . $ BrotliDecoderStateStruct#distance_code. - 4;
1703 } else {
1704 index_delta = 2;
1705 }
1706 /* Unpack one of six 4-bit values. */
1707 delta = ((0x605142 >> (4 * base)) & 0xF) - 3;
1708 s->distance_codecxx . . $ BrotliDecoderStateStruct#distance_code. = s->dist_rbcxx . . $ BrotliDecoderStateStruct#dist_rb.[(s->dist_rb_idxcxx . . $ BrotliDecoderStateStruct#dist_rb_idx. + index_delta) & 0x3] + delta;
1709 if (s->distance_codecxx . . $ BrotliDecoderStateStruct#distance_code. <= 0) {
1710 /* A huge distance will cause a BROTLI_FAILURE() soon.
1711 This is a little faster than failing here. */
1712 s->distance_codecxx . . $ BrotliDecoderStateStruct#distance_code. = 0x7FFFFFFF;
1713 }
1714 }
1715 }
1716
1717 static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! SafeReadBitscxx . . $ SafeReadBits(d859fb483c1e4a60).(
1718 BrotliBitReadercxx . . $ BrotliBitReader#* const br, brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! n_bits, brotli_reg_tcxx . . $ `c/common/platform.h:237:9`!* val) {
1719 if (n_bits != 0) {
1720 return BrotliSafeReadBitscxx . . $ BrotliSafeReadBits(d859fb483c1e4a60).(br, n_bits, val);
1721 } else {
1722 *val = 0;
1723 return BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!;
1724 }
1725 }
1726
1727 static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! SafeReadBits32cxx . . $ SafeReadBits32(d859fb483c1e4a60).(
1728 BrotliBitReadercxx . . $ BrotliBitReader#* const br, brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! n_bits, brotli_reg_tcxx . . $ `c/common/platform.h:237:9`!* val) {
1729 if (n_bits != 0) {
1730 return BrotliSafeReadBits32cxx . . $ BrotliSafeReadBits32(d859fb483c1e4a60).(br, n_bits, val);
1731 } else {
1732 *val = 0;
1733 return BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!;
1734 }
1735 }
1736
1737 /*
1738 RFC 7932 Section 4 with "..." shortenings and "[]" emendations.
1739
1740 Each distance ... is represented with a pair <distance code, extra bits>...
1741 The distance code is encoded using a prefix code... The number of extra bits
1742 can be 0..24... Two additional parameters: NPOSTFIX (0..3), and ...
1743 NDIRECT (0..120) ... are encoded in the meta-block header...
1744
1745 The first 16 distance symbols ... reference past distances... ring buffer ...
1746 Next NDIRECT distance symbols ... represent distances from 1 to NDIRECT...
1747 [For] distance symbols 16 + NDIRECT and greater ... the number of extra bits
1748 ... is given by the following formula:
1749
1750 [ xcode = dcode - NDIRECT - 16 ]
1751 ndistbits = 1 + [ xcode ] >> (NPOSTFIX + 1)
1752
1753 ...
1754 */
1755
1756 /*
1757 RFC 7932 Section 9.2 with "..." shortenings and "[]" emendations.
1758
1759 ... to get the actual value of the parameter NDIRECT, left-shift this
1760 four-bit number by NPOSTFIX bits ...
1761 */
1762
1763 /* Remaining formulas from RFC 7932 Section 4 could be rewritten as following:
1764
1765 alphabet_size = 16 + NDIRECT + (max_distbits << (NPOSTFIX + 1))
1766
1767 half = ((xcode >> NPOSTFIX) & 1) << ndistbits
1768 postfix = xcode & ((1 << NPOSTFIX) - 1)
1769 range_start = 2 * (1 << ndistbits - 1 - 1)
1770
1771 distance = (range_start + half + extra) << NPOSTFIX + postfix + NDIRECT + 1
1772
1773 NB: ndistbits >= 1 -> range_start >= 0
1774 NB: range_start has factor 2, as the range is covered by 2 "halves"
1775 NB: extra -1 offset in range_start formula covers the absence of
1776 ndistbits = 0 case
1777 NB: when NPOSTFIX = 0, NDIRECT is not greater than 15
1778
1779 In other words, xcode has the following binary structure - XXXHPPP:
1780 - XXX represent the number of extra distance bits
1781 - H selects upper / lower range of distances
1782 - PPP represent "postfix"
1783
1784 "Regular" distance encoding has NPOSTFIX = 0; omitting the postfix part
1785 simplifies distance calculation.
1786
1787 Using NPOSTFIX > 0 allows cheaper encoding of regular structures, e.g. where
1788 most of distances have the same reminder of division by 2/4/8. For example,
1789 the table of int32_t values that come from different sources; if it is likely
1790 that 3 highest bytes of values from the same source are the same, then
1791 copy distance often looks like 4x + y.
1792
1793 Distance calculation could be rewritten to:
1794
1795 ndistbits = NDISTBITS(NDIRECT, NPOSTFIX)[dcode]
1796 distance = OFFSET(NDIRECT, NPOSTFIX)[dcode] + extra << NPOSTFIX
1797
1798 NDISTBITS and OFFSET could be pre-calculated, as NDIRECT and NPOSTFIX could
1799 change only once per meta-block.
1800 */
1801
1802 /* Calculates distance lookup table.
1803 NB: it is possible to have all 64 tables precalculated. */
1804 static void CalculateDistanceLutcxx . . $ CalculateDistanceLut(bb1fb99afd41e748).(BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s) {
1805 BrotliMetablockBodyArenacxx . . $ BrotliMetablockBodyArena#* b = &s->arenacxx . . $ BrotliDecoderStateStruct#arena..bodycxx . . $ BrotliDecoderStateStruct#$anonymous_type_9#body.;
1806 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! npostfix = s->distance_postfix_bitscxx . . $ BrotliDecoderStateStruct#distance_postfix_bits.;
1807 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! ndirect = s->num_direct_distance_codescxx . . $ BrotliDecoderStateStruct#num_direct_distance_codes.;
1808 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! alphabet_size_limit = s->distance_hgroupcxx . . $ BrotliDecoderStateStruct#distance_hgroup..alphabet_size_limitcxx . . $ $anonymous_type_421782d160a65272_1#alphabet_size_limit.;
1809 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! postfix = (brotli_reg_tcxx . . $ `c/common/platform.h:237:9`!)1u << npostfix;
1810 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! j;
1811 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! bits = 1;
1812 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! half = 0;
1813
1814 /* Skip short codes. */
1815 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! i = BROTLI_NUM_DISTANCE_SHORT_CODEScxx . . $ `c/common/constants.h:58:9`!;
1816
1817 /* Fill direct codes. */
1818 for (j = 0; j < ndirect; ++j) {
1819 b->dist_extra_bitscxx . . $ BrotliMetablockBodyArena#dist_extra_bits.[i] = 0;
1820 b->dist_offsetcxx . . $ BrotliMetablockBodyArena#dist_offset.[i] = j + 1;
1821 ++i;
1822 }
1823
1824 /* Fill regular distance codes. */
1825 while (i < alphabet_size_limit) {
1826 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! base = ndirect + ((((2 + half) << bits) - 4) << npostfix) + 1;
1827 /* Always fill the complete group. */
1828 for (j = 0; j < postfix; ++j) {
1829 b->dist_extra_bitscxx . . $ BrotliMetablockBodyArena#dist_extra_bits.[i] = (uint8_tcxx . . $ uint8_t#)bits;
1830 b->dist_offsetcxx . . $ BrotliMetablockBodyArena#dist_offset.[i] = base + j;
1831 ++i;
1832 }
1833 bits = bits + half;
1834 half = half ^ 1;
1835 }
1836 }
1837
1838 /* Precondition: s->distance_code < 0. */
1839 static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! ReadDistanceInternalcxx . . $ ReadDistanceInternal(16cd540034e3d28c).(
1840 int safe, BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s, BrotliBitReadercxx . . $ BrotliBitReader#* br) {
1841 BrotliMetablockBodyArenacxx . . $ BrotliMetablockBodyArena#* b = &s->arenacxx . . $ BrotliDecoderStateStruct#arena..bodycxx . . $ BrotliDecoderStateStruct#$anonymous_type_9#body.;
1842 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! code;
1843 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! bits;
1844 BrotliBitReaderStatecxx . . $ BrotliBitReaderState# memento;
1845 HuffmanCodecxx . . $ HuffmanCode#* distance_tree = s->distance_hgroupcxx . . $ BrotliDecoderStateStruct#distance_hgroup..htreescxx . . $ $anonymous_type_421782d160a65272_1#htrees.[s->dist_htree_indexcxx . . $ BrotliDecoderStateStruct#dist_htree_index.];
1846 if (!safe) {
1847 code = ReadSymbolcxx . . $ ReadSymbol(99805dca1a2a4b7b).(distance_tree, br);
1848 } else {
1849 BrotliBitReaderSaveStatecxx . . $ BrotliBitReaderSaveState(c49e3454873146cb).(br, &memento);
1850 if (!SafeReadSymbolcxx . . $ SafeReadSymbol(24ac31996b0a21de).(distance_tree, br, &code)) {
1851 return BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!;
1852 }
1853 }
1854 --s->block_lengthcxx . . $ BrotliDecoderStateStruct#block_length.[2];
1855 /* Convert the distance code to the actual distance by possibly
1856 looking up past distances from the s->dist_rb. */
1857 s->distance_contextcxx . . $ BrotliDecoderStateStruct#distance_context. = 0;
1858 if ((code & ~0xFu) == 0) {
1859 s->distance_codecxx . . $ BrotliDecoderStateStruct#distance_code. = (int)code;
1860 TakeDistanceFromRingBuffercxx . . $ TakeDistanceFromRingBuffer(bb1fb99afd41e748).(s);
1861 return BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!;
1862 }
1863 if (!safe) {
1864 bits = BrotliReadBits32cxx . . $ BrotliReadBits32(b970e0c403979745).(br, b->dist_extra_bitscxx . . $ BrotliMetablockBodyArena#dist_extra_bits.[code]);
1865 } else {
1866 if (!SafeReadBits32cxx . . $ SafeReadBits32(d859fb483c1e4a60).(br, b->dist_extra_bitscxx . . $ BrotliMetablockBodyArena#dist_extra_bits.[code], &bits)) {
1867 ++s->block_lengthcxx . . $ BrotliDecoderStateStruct#block_length.[2];
1868 BrotliBitReaderRestoreStatecxx . . $ BrotliBitReaderRestoreState(c49e3454873146cb).(br, &memento);
1869 return BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!;
1870 }
1871 }
1872 s->distance_codecxx . . $ BrotliDecoderStateStruct#distance_code. =
1873 (int)(b->dist_offsetcxx . . $ BrotliMetablockBodyArena#dist_offset.[code] + (bits << s->distance_postfix_bitscxx . . $ BrotliDecoderStateStruct#distance_postfix_bits.));
1874 return BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!;
1875 }
1876
1877 static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! void ReadDistancecxx . . $ ReadDistance(d56e70bd74aaf5a).(
1878 BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s, BrotliBitReadercxx . . $ BrotliBitReader#* br) {
1879 ReadDistanceInternalcxx . . $ ReadDistanceInternal(16cd540034e3d28c).(0, s, br);
1880 }
1881
1882 static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! SafeReadDistancecxx . . $ SafeReadDistance(bbec0b04b3958f1b).(
1883 BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s, BrotliBitReadercxx . . $ BrotliBitReader#* br) {
1884 return ReadDistanceInternalcxx . . $ ReadDistanceInternal(16cd540034e3d28c).(1, s, br);
1885 }
1886
1887 static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! ReadCommandInternalcxx . . $ ReadCommandInternal(de9f1fd345892f30).(
1888 int safe, BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s, BrotliBitReadercxx . . $ BrotliBitReader#* br, int* insert_length) {
1889 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! cmd_code;
1890 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! insert_len_extra = 0;
1891 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! copy_length;
1892 CmdLutElementcxx . . $ CmdLutElement# v;
1893 BrotliBitReaderStatecxx . . $ BrotliBitReaderState# memento;
1894 if (!safe) {
1895 cmd_code = ReadSymbolcxx . . $ ReadSymbol(99805dca1a2a4b7b).(s->htree_commandcxx . . $ BrotliDecoderStateStruct#htree_command., br);
1896 } else {
1897 BrotliBitReaderSaveStatecxx . . $ BrotliBitReaderSaveState(c49e3454873146cb).(br, &memento);
1898 if (!SafeReadSymbolcxx . . $ SafeReadSymbol(24ac31996b0a21de).(s->htree_commandcxx . . $ BrotliDecoderStateStruct#htree_command., br, &cmd_code)) {
1899 return BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!;
1900 }
1901 }
1902 v = kCmdLutcxx . . $ kCmdLut.[cmd_code];
1903 s->distance_codecxx . . $ BrotliDecoderStateStruct#distance_code. = v.distance_codecxx . . $ CmdLutElement#distance_code.;
1904 s->distance_contextcxx . . $ BrotliDecoderStateStruct#distance_context. = v.contextcxx . . $ CmdLutElement#context.;
1905 s->dist_htree_indexcxx . . $ BrotliDecoderStateStruct#dist_htree_index. = s->dist_context_map_slicecxx . . $ BrotliDecoderStateStruct#dist_context_map_slice.[s->distance_contextcxx . . $ BrotliDecoderStateStruct#distance_context.];
1906 *insert_length = v.insert_len_offsetcxx . . $ CmdLutElement#insert_len_offset.;
1907 if (!safe) {
1908 if (BROTLI_PREDICT_FALSEcxx . . $ `c/common/platform.h:74:9`!(v.insert_len_extra_bits != 0)) {
1909 insert_len_extra = BrotliReadBits24cxx . . $ BrotliReadBits24(b970e0c403979745).(br, v.insert_len_extra_bitscxx . . $ CmdLutElement#insert_len_extra_bits.);
1910 }
1911 copy_length = BrotliReadBits24cxx . . $ BrotliReadBits24(b970e0c403979745).(br, v.copy_len_extra_bitscxx . . $ CmdLutElement#copy_len_extra_bits.);
1912 } else {
1913 if (!SafeReadBitscxx . . $ SafeReadBits(d859fb483c1e4a60).(br, v.insert_len_extra_bitscxx . . $ CmdLutElement#insert_len_extra_bits., &insert_len_extra) ||
1914 !SafeReadBitscxx . . $ SafeReadBits(d859fb483c1e4a60).(br, v.copy_len_extra_bitscxx . . $ CmdLutElement#copy_len_extra_bits., &copy_length)) {
1915 BrotliBitReaderRestoreStatecxx . . $ BrotliBitReaderRestoreState(c49e3454873146cb).(br, &memento);
1916 return BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!;
1917 }
1918 }
1919 s->copy_lengthcxx . . $ BrotliDecoderStateStruct#copy_length. = (int)copy_length + v.copy_len_offsetcxx . . $ CmdLutElement#copy_len_offset.;
1920 --s->block_lengthcxx . . $ BrotliDecoderStateStruct#block_length.[1];
1921 *insert_length += (int)insert_len_extra;
1922 return BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!;
1923 }
1924
1925 static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! void ReadCommandcxx . . $ ReadCommand(1190efc0177a2494).(
1926 BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s, BrotliBitReadercxx . . $ BrotliBitReader#* br, int* insert_length) {
1927 ReadCommandInternalcxx . . $ ReadCommandInternal(de9f1fd345892f30).(0, s, br, insert_length);
1928 }
1929
1930 static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! SafeReadCommandcxx . . $ SafeReadCommand(3291d6d91ee5dfd).(
1931 BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s, BrotliBitReadercxx . . $ BrotliBitReader#* br, int* insert_length) {
1932 return ReadCommandInternalcxx . . $ ReadCommandInternal(de9f1fd345892f30).(1, s, br, insert_length);
1933 }
1934
1935 static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! CheckInputAmountcxx . . $ CheckInputAmount(393c3b932f39d83c).(
1936 int safe, BrotliBitReadercxx . . $ BrotliBitReader#* const br) {
1937 if (safe) {
1938 return BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!;
1939 }
1940 return BrotliCheckInputAmountcxx . . $ BrotliCheckInputAmount(4966df8ab2ee854a).(br);
1941 }
1942
1943 #define BROTLI_SAFEcxx . . $ `c/dec/decode.c:1943:9`!(METHOD) \
1944 { \
1945 if (safe) { \
1946 if (!Safe##METHOD) { \
1947 result = BROTLI_DECODER_NEEDS_MORE_INPUT; \
1948 goto saveStateAndReturn; \
1949 } \
1950 } else { \
1951 METHOD; \
1952 } \
1953 }
1954
1955 static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! BrotliDecoderErrorCodecxx . . $ BrotliDecoderErrorCode# ProcessCommandsInternalcxx . . $ ProcessCommandsInternal(50d3245f9dfe98fe).(
1956 int safe, BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s) {
1957 int pos = s->poscxx . . $ BrotliDecoderStateStruct#pos.;
1958 int i = s->loop_countercxx . . $ BrotliDecoderStateStruct#loop_counter.;
1959 BrotliDecoderErrorCodecxx . . $ BrotliDecoderErrorCode# result = BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.;
1960 BrotliBitReadercxx . . $ BrotliBitReader#* br = &s->brcxx . . $ BrotliDecoderStateStruct#br.;
1961 int compound_dictionary_size = GetCompoundDictionarySizecxx . . $ GetCompoundDictionarySize(c67463180bf96cf).(s);
1962
1963 if (!CheckInputAmountcxx . . $ CheckInputAmount(393c3b932f39d83c).(safe, br)) {
1964 result = BROTLI_DECODER_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_INPUT.;
1965 goto saveStateAndReturn;
1966 }
1967 if (!safe) {
1968 BROTLI_UNUSEDcxx . . $ `c/common/platform.h:514:9`!(BrotliWarmupBitReader(br));
1969 }
1970
1971 /* Jump into state machine. */
1972 if (s->statecxx . . $ BrotliDecoderStateStruct#state. == BROTLI_STATE_COMMAND_BEGINcxx . . $ BROTLI_STATE_COMMAND_BEGIN.) {
1973 goto CommandBegin;
1974 } else if (s->statecxx . . $ BrotliDecoderStateStruct#state. == BROTLI_STATE_COMMAND_INNERcxx . . $ BROTLI_STATE_COMMAND_INNER.) {
1975 goto CommandInner;
1976 } else if (s->statecxx . . $ BrotliDecoderStateStruct#state. == BROTLI_STATE_COMMAND_POST_DECODE_LITERALScxx . . $ BROTLI_STATE_COMMAND_POST_DECODE_LITERALS.) {
1977 goto CommandPostDecodeLiterals;
1978 } else if (s->statecxx . . $ BrotliDecoderStateStruct#state. == BROTLI_STATE_COMMAND_POST_WRAP_COPYcxx . . $ BROTLI_STATE_COMMAND_POST_WRAP_COPY.) {
1979 goto CommandPostWrapCopy;
1980 } else {
1981 return BROTLI_FAILUREcxx . . $ `c/dec/decode.c:30:9`!(BROTLI_DECODER_ERROR_UNREACHABLE); /* COV_NF_LINE */
1982 }
1983
1984 CommandBegin:
1985 if (safe) {
1986 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_COMMAND_BEGINcxx . . $ BROTLI_STATE_COMMAND_BEGIN.;
1987 }
1988 if (!CheckInputAmountcxx . . $ CheckInputAmount(393c3b932f39d83c).(safe, br)) {
1989 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_COMMAND_BEGINcxx . . $ BROTLI_STATE_COMMAND_BEGIN.;
1990 result = BROTLI_DECODER_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_INPUT.;
1991 goto saveStateAndReturn;
1992 }
1993 if (BROTLI_PREDICT_FALSEcxx . . $ `c/common/platform.h:74:9`!(s->block_length[1] == 0)) {
1994 BROTLI_SAFEcxx . . $ `c/dec/decode.c:1943:9`!(DecodeCommandBlockSwitch(s));
1995 goto CommandBegin;
1996 }
1997 /* Read the insert/copy length in the command. */
1998 BROTLI_SAFEcxx . . $ `c/dec/decode.c:1943:9`!(ReadCommand(s, br, &i));
1999 BROTLI_LOGcxx . . $ `c/common/platform.h:465:9`!(("[ProcessCommandsInternal] pos = %d insert = %d copy = %d\n",
2000 pos, i, s->copy_length));
2001 if (i == 0) {
2002 goto CommandPostDecodeLiterals;
2003 }
2004 s->meta_block_remaining_lencxx . . $ BrotliDecoderStateStruct#meta_block_remaining_len. -= i;
2005
2006 CommandInner:
2007 if (safe) {
2008 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_COMMAND_INNERcxx . . $ BROTLI_STATE_COMMAND_INNER.;
2009 }
2010 /* Read the literals in the command. */
2011 if (s->trivial_literal_contextcxx . . $ BrotliDecoderStateStruct#trivial_literal_context.) {
2012 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! bits;
2013 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! value;
2014 PreloadSymbolcxx . . $ PreloadSymbol(5c393db4bc17ef8).(safe, s->literal_htreecxx . . $ BrotliDecoderStateStruct#literal_htree., br, &bits, &value);
2015 if (!safe) {
2016 // This is a hottest part of the decode, so we copy the loop below
2017 // and optimize it by calculating the number of steps where all checks
2018 // evaluate to false (ringbuffer size/block size/input size).
2019 // Since all checks are loop invariant, we just need to find
2020 // minimal number of iterations for a simple loop, and run
2021 // the full version for the remainder.
2022 int num_steps = i - 1;
2023 if (num_steps > 0 && ((brotli_reg_tcxx . . $ `c/common/platform.h:237:9`!)(num_steps) > s->block_lengthcxx . . $ BrotliDecoderStateStruct#block_length.[0])) {
2024 // Safe cast, since block_length < steps
2025 num_steps = (int)s->block_lengthcxx . . $ BrotliDecoderStateStruct#block_length.[0];
2026 }
2027 if (s->ringbuffer_sizecxx . . $ BrotliDecoderStateStruct#ringbuffer_size. >= pos &&
2028 (s->ringbuffer_sizecxx . . $ BrotliDecoderStateStruct#ringbuffer_size. - pos) <= num_steps) {
2029 num_steps = s->ringbuffer_sizecxx . . $ BrotliDecoderStateStruct#ringbuffer_size. - pos - 1;
2030 }
2031 if (num_steps < 0) {
2032 num_steps = 0;
2033 }
2034 num_steps = BrotliCopyPreloadedSymbolsToU8cxx . . $ BrotliCopyPreloadedSymbolsToU8(a479f4dc9a681d5c).(s->literal_htreecxx . . $ BrotliDecoderStateStruct#literal_htree., br, &bits,
2035 &value, s->ringbuffercxx . . $ BrotliDecoderStateStruct#ringbuffer., pos,
2036 num_steps);
2037 pos += num_steps;
2038 s->block_lengthcxx . . $ BrotliDecoderStateStruct#block_length.[0] -= (brotli_reg_tcxx . . $ `c/common/platform.h:237:9`!)num_steps;
2039 i -= num_steps;
2040 do {
2041 if (!CheckInputAmountcxx . . $ CheckInputAmount(393c3b932f39d83c).(safe, br)) {
2042 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_COMMAND_INNERcxx . . $ BROTLI_STATE_COMMAND_INNER.;
2043 result = BROTLI_DECODER_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_INPUT.;
2044 goto saveStateAndReturn;
2045 }
2046 if (BROTLI_PREDICT_FALSEcxx . . $ `c/common/platform.h:74:9`!(s->block_length[0] == 0)) {
2047 goto NextLiteralBlock;
2048 }
2049 BrotliCopyPreloadedSymbolsToU8cxx . . $ BrotliCopyPreloadedSymbolsToU8(a479f4dc9a681d5c).(s->literal_htreecxx . . $ BrotliDecoderStateStruct#literal_htree., br, &bits, &value,
2050 s->ringbuffercxx . . $ BrotliDecoderStateStruct#ringbuffer., pos, 1);
2051 --s->block_lengthcxx . . $ BrotliDecoderStateStruct#block_length.[0];
2052 BROTLI_LOG_ARRAY_INDEXcxx . . $ `c/dec/decode.c:34:9`!(s->ringbuffer, pos);
2053 ++pos;
2054 if (BROTLI_PREDICT_FALSEcxx . . $ `c/common/platform.h:74:9`!(pos == s->ringbuffer_size)) {
2055 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_COMMAND_INNER_WRITEcxx . . $ BROTLI_STATE_COMMAND_INNER_WRITE.;
2056 --i;
2057 goto saveStateAndReturn;
2058 }
2059 } while (--i != 0);
2060 } else { /* safe */
2061 do {
2062 if (BROTLI_PREDICT_FALSEcxx . . $ `c/common/platform.h:74:9`!(s->block_length[0] == 0)) {
2063 goto NextLiteralBlock;
2064 }
2065 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! literal;
2066 if (!SafeReadSymbolcxx . . $ SafeReadSymbol(24ac31996b0a21de).(s->literal_htreecxx . . $ BrotliDecoderStateStruct#literal_htree., br, &literal)) {
2067 result = BROTLI_DECODER_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_INPUT.;
2068 goto saveStateAndReturn;
2069 }
2070 s->ringbuffercxx . . $ BrotliDecoderStateStruct#ringbuffer.[pos] = (uint8_tcxx . . $ uint8_t#)literal;
2071 --s->block_lengthcxx . . $ BrotliDecoderStateStruct#block_length.[0];
2072 BROTLI_LOG_ARRAY_INDEXcxx . . $ `c/dec/decode.c:34:9`!(s->ringbuffer, pos);
2073 ++pos;
2074 if (BROTLI_PREDICT_FALSEcxx . . $ `c/common/platform.h:74:9`!(pos == s->ringbuffer_size)) {
2075 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_COMMAND_INNER_WRITEcxx . . $ BROTLI_STATE_COMMAND_INNER_WRITE.;
2076 --i;
2077 goto saveStateAndReturn;
2078 }
2079 } while (--i != 0);
2080 }
2081 } else {
2082 uint8_tcxx . . $ uint8_t# p1 = s->ringbuffercxx . . $ BrotliDecoderStateStruct#ringbuffer.[(pos - 1) & s->ringbuffer_maskcxx . . $ BrotliDecoderStateStruct#ringbuffer_mask.];
2083 uint8_tcxx . . $ uint8_t# p2 = s->ringbuffercxx . . $ BrotliDecoderStateStruct#ringbuffer.[(pos - 2) & s->ringbuffer_maskcxx . . $ BrotliDecoderStateStruct#ringbuffer_mask.];
2084 do {
2085 const HuffmanCodecxx . . $ HuffmanCode#* hc;
2086 uint8_tcxx . . $ uint8_t# context;
2087 if (!CheckInputAmountcxx . . $ CheckInputAmount(393c3b932f39d83c).(safe, br)) {
2088 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_COMMAND_INNERcxx . . $ BROTLI_STATE_COMMAND_INNER.;
2089 result = BROTLI_DECODER_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_INPUT.;
2090 goto saveStateAndReturn;
2091 }
2092 if (BROTLI_PREDICT_FALSEcxx . . $ `c/common/platform.h:74:9`!(s->block_length[0] == 0)) {
2093 goto NextLiteralBlock;
2094 }
2095 context = BROTLI_CONTEXTcxx . . $ `c/common/context.h:110:9`!(p1, p2, s->context_lookup);
2096 BROTLI_LOG_UINTcxx . . $ `c/dec/decode.c:32:9`!(context);
2097 hc = s->literal_hgroupcxx . . $ BrotliDecoderStateStruct#literal_hgroup..htreescxx . . $ $anonymous_type_421782d160a65272_1#htrees.[s->context_map_slicecxx . . $ BrotliDecoderStateStruct#context_map_slice.[context]];
2098 p2 = p1;
2099 if (!safe) {
2100 p1 = (uint8_tcxx . . $ uint8_t#)ReadSymbolcxx . . $ ReadSymbol(99805dca1a2a4b7b).(hc, br);
2101 } else {
2102 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! literal;
2103 if (!SafeReadSymbolcxx . . $ SafeReadSymbol(24ac31996b0a21de).(hc, br, &literal)) {
2104 result = BROTLI_DECODER_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_INPUT.;
2105 goto saveStateAndReturn;
2106 }
2107 p1 = (uint8_tcxx . . $ uint8_t#)literal;
2108 }
2109 s->ringbuffercxx . . $ BrotliDecoderStateStruct#ringbuffer.[pos] = p1;
2110 --s->block_lengthcxx . . $ BrotliDecoderStateStruct#block_length.[0];
2111 BROTLI_LOG_UINTcxx . . $ `c/dec/decode.c:32:9`!(s->context_map_slice[context]);
2112 BROTLI_LOG_ARRAY_INDEXcxx . . $ `c/dec/decode.c:34:9`!(s->ringbuffer, pos & s->ringbuffer_mask);
2113 ++pos;
2114 if (BROTLI_PREDICT_FALSEcxx . . $ `c/common/platform.h:74:9`!(pos == s->ringbuffer_size)) {
2115 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_COMMAND_INNER_WRITEcxx . . $ BROTLI_STATE_COMMAND_INNER_WRITE.;
2116 --i;
2117 goto saveStateAndReturn;
2118 }
2119 } while (--i != 0);
2120 }
2121 BROTLI_LOG_UINTcxx . . $ `c/dec/decode.c:32:9`!(s->meta_block_remaining_len);
2122 if (BROTLI_PREDICT_FALSEcxx . . $ `c/common/platform.h:74:9`!(s->meta_block_remaining_len <= 0)) {
2123 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_METABLOCK_DONEcxx . . $ BROTLI_STATE_METABLOCK_DONE.;
2124 goto saveStateAndReturn;
2125 }
2126
2127 CommandPostDecodeLiterals:
2128 if (safe) {
2129 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_COMMAND_POST_DECODE_LITERALScxx . . $ BROTLI_STATE_COMMAND_POST_DECODE_LITERALS.;
2130 }
2131 if (s->distance_codecxx . . $ BrotliDecoderStateStruct#distance_code. >= 0) {
2132 /* Implicit distance case. */
2133 s->distance_contextcxx . . $ BrotliDecoderStateStruct#distance_context. = s->distance_codecxx . . $ BrotliDecoderStateStruct#distance_code. ? 0 : 1;
2134 --s->dist_rb_idxcxx . . $ BrotliDecoderStateStruct#dist_rb_idx.;
2135 s->distance_codecxx . . $ BrotliDecoderStateStruct#distance_code. = s->dist_rbcxx . . $ BrotliDecoderStateStruct#dist_rb.[s->dist_rb_idxcxx . . $ BrotliDecoderStateStruct#dist_rb_idx. & 3];
2136 } else {
2137 /* Read distance code in the command, unless it was implicitly zero. */
2138 if (BROTLI_PREDICT_FALSEcxx . . $ `c/common/platform.h:74:9`!(s->block_length[2] == 0)) {
2139 BROTLI_SAFEcxx . . $ `c/dec/decode.c:1943:9`!(DecodeDistanceBlockSwitch(s));
2140 }
2141 BROTLI_SAFEcxx . . $ `c/dec/decode.c:1943:9`!(ReadDistance(s, br));
2142 }
2143 BROTLI_LOGcxx . . $ `c/common/platform.h:465:9`!(("[ProcessCommandsInternal] pos = %d distance = %d\n",
2144 pos, s->distance_code));
2145 if (s->max_distancecxx . . $ BrotliDecoderStateStruct#max_distance. != s->max_backward_distancecxx . . $ BrotliDecoderStateStruct#max_backward_distance.) {
2146 s->max_distancecxx . . $ BrotliDecoderStateStruct#max_distance. =
2147 (pos < s->max_backward_distancecxx . . $ BrotliDecoderStateStruct#max_backward_distance.) ? pos : s->max_backward_distancecxx . . $ BrotliDecoderStateStruct#max_backward_distance.;
2148 }
2149 i = s->copy_lengthcxx . . $ BrotliDecoderStateStruct#copy_length.;
2150 /* Apply copy of LZ77 back-reference, or static dictionary reference if
2151 the distance is larger than the max LZ77 distance */
2152 if (s->distance_codecxx . . $ BrotliDecoderStateStruct#distance_code. > s->max_distancecxx . . $ BrotliDecoderStateStruct#max_distance.) {
2153 /* The maximum allowed distance is BROTLI_MAX_ALLOWED_DISTANCE = 0x7FFFFFFC.
2154 With this choice, no signed overflow can occur after decoding
2155 a special distance code (e.g., after adding 3 to the last distance). */
2156 if (s->distance_codecxx . . $ BrotliDecoderStateStruct#distance_code. > BROTLI_MAX_ALLOWED_DISTANCEcxx . . $ `c/common/constants.h:84:9`!) {
2157 BROTLI_LOGcxx . . $ `c/common/platform.h:465:9`!(("Invalid backward reference. pos: %d distance: %d "
2158 "len: %d bytes left: %d\n",
2159 pos, s->distance_code, i, s->meta_block_remaining_len));
2160 return BROTLI_FAILUREcxx . . $ `c/dec/decode.c:30:9`!(BROTLI_DECODER_ERROR_FORMAT_DISTANCE);
2161 }
2162 if (s->distance_codecxx . . $ BrotliDecoderStateStruct#distance_code. - s->max_distancecxx . . $ BrotliDecoderStateStruct#max_distance. - 1 < compound_dictionary_size) {
2163 int address = compound_dictionary_size -
2164 (s->distance_codecxx . . $ BrotliDecoderStateStruct#distance_code. - s->max_distancecxx . . $ BrotliDecoderStateStruct#max_distance.);
2165 if (!InitializeCompoundDictionaryCopycxx . . $ InitializeCompoundDictionaryCopy(5b5a49a29526ad00).(s, address, i)) {
2166 return BROTLI_FAILUREcxx . . $ `c/dec/decode.c:30:9`!(BROTLI_DECODER_ERROR_COMPOUND_DICTIONARY);
2167 }
2168 pos += CopyFromCompoundDictionarycxx . . $ CopyFromCompoundDictionary(f13d6527b0ad88d0).(s, pos);
2169 if (pos >= s->ringbuffer_sizecxx . . $ BrotliDecoderStateStruct#ringbuffer_size.) {
2170 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_COMMAND_POST_WRITE_1cxx . . $ BROTLI_STATE_COMMAND_POST_WRITE_1.;
2171 goto saveStateAndReturn;
2172 }
2173 } else if (i >= SHARED_BROTLI_MIN_DICTIONARY_WORD_LENGTHcxx . . $ `c/include/brotli/shared_dictionary.h:19:9`! &&
2174 i <= SHARED_BROTLI_MAX_DICTIONARY_WORD_LENGTHcxx . . $ `c/include/brotli/shared_dictionary.h:20:9`!) {
2175 uint8_tcxx . . $ uint8_t# p1 = s->ringbuffercxx . . $ BrotliDecoderStateStruct#ringbuffer.[(pos - 1) & s->ringbuffer_maskcxx . . $ BrotliDecoderStateStruct#ringbuffer_mask.];
2176 uint8_tcxx . . $ uint8_t# p2 = s->ringbuffercxx . . $ BrotliDecoderStateStruct#ringbuffer.[(pos - 2) & s->ringbuffer_maskcxx . . $ BrotliDecoderStateStruct#ringbuffer_mask.];
2177 uint8_tcxx . . $ uint8_t# dict_id = s->dictionarycxx . . $ BrotliDecoderStateStruct#dictionary.->context_basedcxx . . $ BrotliSharedDictionaryStruct#context_based. ?
2178 s->dictionarycxx . . $ BrotliDecoderStateStruct#dictionary.->context_mapcxx . . $ BrotliSharedDictionaryStruct#context_map.[BROTLI_CONTEXTcxx . . $ `c/common/context.h:110:9`!(p1, p2, s->context_lookup)]
2179 : 0;
2180 const BrotliDictionarycxx . . $ BrotliDictionary#* words = s->dictionarycxx . . $ BrotliDecoderStateStruct#dictionary.->wordscxx . . $ BrotliSharedDictionaryStruct#words.[dict_id];
2181 const BrotliTransformscxx . . $ BrotliTransforms#* transforms = s->dictionarycxx . . $ BrotliDecoderStateStruct#dictionary.->transformscxx . . $ BrotliSharedDictionaryStruct#transforms.[dict_id];
2182 int offset = (int)words->offsets_by_lengthcxx . . $ BrotliDictionary#offsets_by_length.[i];
2183 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! shift = words->size_bits_by_lengthcxx . . $ BrotliDictionary#size_bits_by_length.[i];
2184 int address =
2185 s->distance_codecxx . . $ BrotliDecoderStateStruct#distance_code. - s->max_distancecxx . . $ BrotliDecoderStateStruct#max_distance. - 1 - compound_dictionary_size;
2186 int mask = (int)BitMaskcxx . . $ BitMask(ecdaa1632f49f591).(shift);
2187 int word_idx = address & mask;
2188 int transform_idx = address >> shift;
2189 /* Compensate double distance-ring-buffer roll. */
2190 s->dist_rb_idxcxx . . $ BrotliDecoderStateStruct#dist_rb_idx. += s->distance_contextcxx . . $ BrotliDecoderStateStruct#distance_context.;
2191 offset += word_idx * i;
2192 /* If the distance is out of bound, select a next static dictionary if
2193 there exist multiple. */
2194 if ((transform_idx >= (int)transforms->num_transformscxx . . $ BrotliTransforms#num_transforms. ||
2195 words->size_bits_by_lengthcxx . . $ BrotliDictionary#size_bits_by_length.[i] == 0) &&
2196 s->dictionarycxx . . $ BrotliDecoderStateStruct#dictionary.->num_dictionariescxx . . $ BrotliSharedDictionaryStruct#num_dictionaries. > 1) {
2197 uint8_tcxx . . $ uint8_t# dict_id2;
2198 int dist_remaining = address -
2199 (int)(((1u << shift) & ~1u)) * (int)transforms->num_transformscxx . . $ BrotliTransforms#num_transforms.;
2200 for (dict_id2 = 0; dict_id2 < s->dictionarycxx . . $ BrotliDecoderStateStruct#dictionary.->num_dictionariescxx . . $ BrotliSharedDictionaryStruct#num_dictionaries.;
2201 dict_id2++) {
2202 const BrotliDictionarycxx . . $ BrotliDictionary#* words2 = s->dictionarycxx . . $ BrotliDecoderStateStruct#dictionary.->wordscxx . . $ BrotliSharedDictionaryStruct#words.[dict_id2];
2203 if (dict_id2 != dict_id && words2->size_bits_by_lengthcxx . . $ BrotliDictionary#size_bits_by_length.[i] != 0) {
2204 const BrotliTransformscxx . . $ BrotliTransforms#* transforms2 =
2205 s->dictionarycxx . . $ BrotliDecoderStateStruct#dictionary.->transformscxx . . $ BrotliSharedDictionaryStruct#transforms.[dict_id2];
2206 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! shift2 = words2->size_bits_by_lengthcxx . . $ BrotliDictionary#size_bits_by_length.[i];
2207 int num = (int)((1u << shift2) & ~1u) *
2208 (int)transforms2->num_transformscxx . . $ BrotliTransforms#num_transforms.;
2209 if (dist_remaining < num) {
2210 dict_id = dict_id2;
2211 words = words2;
2212 transforms = transforms2;
2213 address = dist_remaining;
2214 shift = shift2;
2215 mask = (int)BitMaskcxx . . $ BitMask(ecdaa1632f49f591).(shift);
2216 word_idx = address & mask;
2217 transform_idx = address >> shift;
2218 offset = (int)words->offsets_by_lengthcxx . . $ BrotliDictionary#offsets_by_length.[i] + word_idx * i;
2219 break;
2220 }
2221 dist_remaining -= num;
2222 }
2223 }
2224 }
2225 if (BROTLI_PREDICT_FALSEcxx . . $ `c/common/platform.h:74:9`!(words->size_bits_by_length[i] == 0)) {
2226 BROTLI_LOGcxx . . $ `c/common/platform.h:465:9`!(("Invalid backward reference. pos: %d distance: %d "
2227 "len: %d bytes left: %d\n",
2228 pos, s->distance_code, i, s->meta_block_remaining_len));
2229 return BROTLI_FAILUREcxx . . $ `c/dec/decode.c:30:9`!(BROTLI_DECODER_ERROR_FORMAT_DICTIONARY);
2230 }
2231 if (BROTLI_PREDICT_FALSEcxx . . $ `c/common/platform.h:74:9`!(!words->data)) {
2232 return BROTLI_FAILUREcxx . . $ `c/dec/decode.c:30:9`!(BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET);
2233 }
2234 if (transform_idx < (int)transforms->num_transformscxx . . $ BrotliTransforms#num_transforms.) {
2235 const uint8_tcxx . . $ uint8_t#* word = &words->datacxx . . $ BrotliDictionary#data.[offset];
2236 int len = i;
2237 if (transform_idx == transforms->cutOffTransformscxx . . $ BrotliTransforms#cutOffTransforms.[0]) {
2238 memcpycxx . . $ memcpy(cc817cb175f282d).(&s->ringbuffercxx . . $ BrotliDecoderStateStruct#ringbuffer.[pos], word, (size_t)len);
2239 BROTLI_LOGcxx . . $ `c/common/platform.h:465:9`!(("[ProcessCommandsInternal] dictionary word: [%.*s]\n",
2240 len, word));
2241 } else {
2242 len = BrotliTransformDictionaryWordcxx . . $ BrotliTransformDictionaryWord(1ae3c5f2aac46052).(&s->ringbuffercxx . . $ BrotliDecoderStateStruct#ringbuffer.[pos], word, len,
2243 transforms, transform_idx);
2244 BROTLI_LOGcxx . . $ `c/common/platform.h:465:9`!(("[ProcessCommandsInternal] dictionary word: [%.*s],"
2245 " transform_idx = %d, transformed: [%.*s]\n",
2246 i, word, transform_idx, len, &s->ringbuffer[pos]));
2247 if (len == 0 && s->distance_codecxx . . $ BrotliDecoderStateStruct#distance_code. <= 120) {
2248 BROTLI_LOGcxx . . $ `c/common/platform.h:465:9`!(("Invalid length-0 dictionary word after transform\n"));
2249 return BROTLI_FAILUREcxx . . $ `c/dec/decode.c:30:9`!(BROTLI_DECODER_ERROR_FORMAT_TRANSFORM);
2250 }
2251 }
2252 pos += len;
2253 s->meta_block_remaining_lencxx . . $ BrotliDecoderStateStruct#meta_block_remaining_len. -= len;
2254 if (pos >= s->ringbuffer_sizecxx . . $ BrotliDecoderStateStruct#ringbuffer_size.) {
2255 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_COMMAND_POST_WRITE_1cxx . . $ BROTLI_STATE_COMMAND_POST_WRITE_1.;
2256 goto saveStateAndReturn;
2257 }
2258 } else {
2259 BROTLI_LOGcxx . . $ `c/common/platform.h:465:9`!(("Invalid backward reference. pos: %d distance: %d "
2260 "len: %d bytes left: %d\n",
2261 pos, s->distance_code, i, s->meta_block_remaining_len));
2262 return BROTLI_FAILUREcxx . . $ `c/dec/decode.c:30:9`!(BROTLI_DECODER_ERROR_FORMAT_TRANSFORM);
2263 }
2264 } else {
2265 BROTLI_LOGcxx . . $ `c/common/platform.h:465:9`!(("Invalid backward reference. pos: %d distance: %d "
2266 "len: %d bytes left: %d\n",
2267 pos, s->distance_code, i, s->meta_block_remaining_len));
2268 return BROTLI_FAILUREcxx . . $ `c/dec/decode.c:30:9`!(BROTLI_DECODER_ERROR_FORMAT_DICTIONARY);
2269 }
2270 } else {
2271 int src_start = (pos - s->distance_codecxx . . $ BrotliDecoderStateStruct#distance_code.) & s->ringbuffer_maskcxx . . $ BrotliDecoderStateStruct#ringbuffer_mask.;
2272 uint8_tcxx . . $ uint8_t#* copy_dst = &s->ringbuffercxx . . $ BrotliDecoderStateStruct#ringbuffer.[pos];
2273 uint8_tcxx . . $ uint8_t#* copy_src = &s->ringbuffercxx . . $ BrotliDecoderStateStruct#ringbuffer.[src_start];
2274 int dst_end = pos + i;
2275 int src_end = src_start + i;
2276 /* Update the recent distances cache. */
2277 s->dist_rbcxx . . $ BrotliDecoderStateStruct#dist_rb.[s->dist_rb_idxcxx . . $ BrotliDecoderStateStruct#dist_rb_idx. & 3] = s->distance_codecxx . . $ BrotliDecoderStateStruct#distance_code.;
2278 ++s->dist_rb_idxcxx . . $ BrotliDecoderStateStruct#dist_rb_idx.;
2279 s->meta_block_remaining_lencxx . . $ BrotliDecoderStateStruct#meta_block_remaining_len. -= i;
2280 /* There are 32+ bytes of slack in the ring-buffer allocation.
2281 Also, we have 16 short codes, that make these 16 bytes irrelevant
2282 in the ring-buffer. Let's copy over them as a first guess. */
2283 memmove16cxx . . $ memmove16(b400838b9938479d).(copy_dst, copy_src);
2284 if (src_end > pos && dst_end > src_start) {
2285 /* Regions intersect. */
2286 goto CommandPostWrapCopy;
2287 }
2288 if (dst_end >= s->ringbuffer_sizecxx . . $ BrotliDecoderStateStruct#ringbuffer_size. || src_end >= s->ringbuffer_sizecxx . . $ BrotliDecoderStateStruct#ringbuffer_size.) {
2289 /* At least one region wraps. */
2290 goto CommandPostWrapCopy;
2291 }
2292 pos += i;
2293 if (i > 16) {
2294 if (i > 32) {
2295 memcpycxx . . $ memcpy(cc817cb175f282d).(copy_dst + 16, copy_src + 16, (size_t)(i - 16));
2296 } else {
2297 /* This branch covers about 45% cases.
2298 Fixed size short copy allows more compiler optimizations. */
2299 memmove16cxx . . $ memmove16(b400838b9938479d).(copy_dst + 16, copy_src + 16);
2300 }
2301 }
2302 }
2303 BROTLI_LOG_UINTcxx . . $ `c/dec/decode.c:32:9`!(s->meta_block_remaining_len);
2304 if (s->meta_block_remaining_lencxx . . $ BrotliDecoderStateStruct#meta_block_remaining_len. <= 0) {
2305 /* Next metablock, if any. */
2306 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_METABLOCK_DONEcxx . . $ BROTLI_STATE_METABLOCK_DONE.;
2307 goto saveStateAndReturn;
2308 } else {
2309 goto CommandBegin;
2310 }
2311 CommandPostWrapCopy:
2312 {
2313 int wrap_guard = s->ringbuffer_sizecxx . . $ BrotliDecoderStateStruct#ringbuffer_size. - pos;
2314 while (--i >= 0) {
2315 s->ringbuffercxx . . $ BrotliDecoderStateStruct#ringbuffer.[pos] =
2316 s->ringbuffercxx . . $ BrotliDecoderStateStruct#ringbuffer.[(pos - s->distance_codecxx . . $ BrotliDecoderStateStruct#distance_code.) & s->ringbuffer_maskcxx . . $ BrotliDecoderStateStruct#ringbuffer_mask.];
2317 ++pos;
2318 if (BROTLI_PREDICT_FALSEcxx . . $ `c/common/platform.h:74:9`!(--wrap_guard == 0)) {
2319 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_COMMAND_POST_WRITE_2cxx . . $ BROTLI_STATE_COMMAND_POST_WRITE_2.;
2320 goto saveStateAndReturn;
2321 }
2322 }
2323 }
2324 if (s->meta_block_remaining_lencxx . . $ BrotliDecoderStateStruct#meta_block_remaining_len. <= 0) {
2325 /* Next metablock, if any. */
2326 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_METABLOCK_DONEcxx . . $ BROTLI_STATE_METABLOCK_DONE.;
2327 goto saveStateAndReturn;
2328 } else {
2329 goto CommandBegin;
2330 }
2331
2332 NextLiteralBlock:
2333 BROTLI_SAFEcxx . . $ `c/dec/decode.c:1943:9`!(DecodeLiteralBlockSwitch(s));
2334 goto CommandInner;
2335
2336 saveStateAndReturn:
2337 s->poscxx . . $ BrotliDecoderStateStruct#pos. = pos;
2338 s->loop_countercxx . . $ BrotliDecoderStateStruct#loop_counter. = i;
2339 return result;
2340 }
2341
2342 #undef BROTLI_SAFEcxx . . $ `c/dec/decode.c:1943:9`!
2343
2344 static BROTLI_NOINLINEcxx . . $ `c/common/platform.h:137:9`! BrotliDecoderErrorCodecxx . . $ BrotliDecoderErrorCode# ProcessCommandscxx . . $ ProcessCommands(fe8ed989e3875dcf).(
2345 BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s) {
2346 return ProcessCommandsInternalcxx . . $ ProcessCommandsInternal(50d3245f9dfe98fe).(0, s);
2347 }
2348
2349 static BROTLI_NOINLINEcxx . . $ `c/common/platform.h:137:9`! BrotliDecoderErrorCodecxx . . $ BrotliDecoderErrorCode# SafeProcessCommandscxx . . $ SafeProcessCommands(fe8ed989e3875dcf).(
2350 BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s) {
2351 return ProcessCommandsInternalcxx . . $ ProcessCommandsInternal(50d3245f9dfe98fe).(1, s);
2352 }
2353
2354 BrotliDecoderResultcxx . . $ BrotliDecoderResult# BrotliDecoderDecompresscxx . . $ BrotliDecoderDecompress(cdde8e160ffa6dd6).(
2355 size_t encoded_size,
2356 const uint8_tcxx . . $ uint8_t# encoded_buffer[BROTLI_ARRAY_PARAMcxx . . $ `c/include/brotli/port.h:263:9`!(encoded_size)],
2357 size_t* decoded_size,
2358 uint8_tcxx . . $ uint8_t# decoded_buffer[BROTLI_ARRAY_PARAMcxx . . $ `c/include/brotli/port.h:263:9`!(*decoded_size)]) {
2359 BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`! s;
2360 BrotliDecoderResultcxx . . $ BrotliDecoderResult# result;
2361 size_t total_out = 0;
2362 size_t available_in = encoded_size;
2363 const uint8_tcxx . . $ uint8_t#* next_in = encoded_buffer;
2364 size_t available_out = *decoded_size;
2365 uint8_tcxx . . $ uint8_t#* next_out = decoded_buffer;
2366 if (!BrotliDecoderStateInitcxx . . $ BrotliDecoderStateInit(6711db6abf207b4c).(&s, 0, 0, 0)) {
2367 return BROTLI_DECODER_RESULT_ERRORcxx . . $ BROTLI_DECODER_RESULT_ERROR.;
2368 }
2369 result = BrotliDecoderDecompressStreamcxx . . $ BrotliDecoderDecompressStream(391610b52170204b).(
2370 &s, &available_in, &next_in, &available_out, &next_out, &total_out);
2371 *decoded_size = total_out;
2372 BrotliDecoderStateCleanupcxx . . $ BrotliDecoderStateCleanup(bb1fb99afd41e748).(&s);
2373 if (result != BROTLI_DECODER_RESULT_SUCCESScxx . . $ BROTLI_DECODER_RESULT_SUCCESS.) {
2374 result = BROTLI_DECODER_RESULT_ERRORcxx . . $ BROTLI_DECODER_RESULT_ERROR.;
2375 }
2376 return result;
2377 }
2378
2379 /* Invariant: input stream is never overconsumed:
2380 - invalid input implies that the whole stream is invalid -> any amount of
2381 input could be read and discarded
2382 - when result is "needs more input", then at least one more byte is REQUIRED
2383 to complete decoding; all input data MUST be consumed by decoder, so
2384 client could swap the input buffer
2385 - when result is "needs more output" decoder MUST ensure that it doesn't
2386 hold more than 7 bits in bit reader; this saves client from swapping input
2387 buffer ahead of time
2388 - when result is "success" decoder MUST return all unused data back to input
2389 buffer; this is possible because the invariant is held on enter */
2390 BrotliDecoderResultcxx . . $ BrotliDecoderResult# BrotliDecoderDecompressStreamcxx . . $ BrotliDecoderDecompressStream(391610b52170204b).(
2391 BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s, size_t* available_in, const uint8_tcxx . . $ uint8_t#** next_in,
2392 size_t* available_out, uint8_tcxx . . $ uint8_t#** next_out, size_t* total_out) {
2393 BrotliDecoderErrorCodecxx . . $ BrotliDecoderErrorCode# result = BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.;
2394 BrotliBitReadercxx . . $ BrotliBitReader#* br = &s->brcxx . . $ BrotliDecoderStateStruct#br.;
2395 size_t input_size = *available_in;
2396 #define BROTLI_SAVE_ERROR_CODEcxx . . $ `c/dec/decode.c:2396:9`!(code) \
2397 SaveErrorCode(s, (code), input_size - *available_in)
2398 /* Ensure that |total_out| is set, even if no data will ever be pushed out. */
2399 if (total_out) {
2400 *total_out = s->partial_pos_outcxx . . $ BrotliDecoderStateStruct#partial_pos_out.;
2401 }
2402 /* Do not try to process further in a case of unrecoverable error. */
2403 if ((int)s->error_codecxx . . $ BrotliDecoderStateStruct#error_code. < 0) {
2404 return BROTLI_DECODER_RESULT_ERRORcxx . . $ BROTLI_DECODER_RESULT_ERROR.;
2405 }
2406 if (*available_out && (!next_out || !*next_out)) {
2407 return BROTLI_SAVE_ERROR_CODEcxx . . $ `c/dec/decode.c:2396:9`!(
2408 BROTLI_FAILUREcxx . . $ `c/dec/decode.c:30:9`!(BROTLI_DECODER_ERROR_INVALID_ARGUMENTS));
2409 }
2410 if (!*available_out) next_out = 0;
2411 if (s->buffer_lengthcxx . . $ BrotliDecoderStateStruct#buffer_length. == 0) { /* Just connect bit reader to input stream. */
2412 BrotliBitReaderSetInputcxx . . $ BrotliBitReaderSetInput(13366109ed4e2f6c).(br, *next_in, *available_in);
2413 } else {
2414 /* At least one byte of input is required. More than one byte of input may
2415 be required to complete the transaction -> reading more data must be
2416 done in a loop -> do it in a main loop. */
2417 result = BROTLI_DECODER_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_INPUT.;
2418 BrotliBitReaderSetInputcxx . . $ BrotliBitReaderSetInput(13366109ed4e2f6c).(br, &s->buffercxx . . $ BrotliDecoderStateStruct#buffer..u8cxx . . $ BrotliDecoderStateStruct#$anonymous_type_8#u8.[0], s->buffer_lengthcxx . . $ BrotliDecoderStateStruct#buffer_length.);
2419 }
2420 /* State machine */
2421 for (;;) {
2422 if (result != BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.) {
2423 /* Error, needs more input/output. */
2424 if (result == BROTLI_DECODER_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_INPUT.) {
2425 if (s->ringbuffercxx . . $ BrotliDecoderStateStruct#ringbuffer. != 0) { /* Pro-actively push output. */
2426 BrotliDecoderErrorCodecxx . . $ BrotliDecoderErrorCode# intermediate_result = WriteRingBuffercxx . . $ WriteRingBuffer(717a5536caf5ab00).(s,
2427 available_out, next_out, total_out, BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!);
2428 /* WriteRingBuffer checks s->meta_block_remaining_len validity. */
2429 if ((int)intermediate_result < 0) {
2430 result = intermediate_result;
2431 break;
2432 }
2433 }
2434 if (s->buffer_lengthcxx . . $ BrotliDecoderStateStruct#buffer_length. != 0) { /* Used with internal buffer. */
2435 if (br->next_incxx . . $ $anonymous_type_83261257069d1fbd_0#next_in. == br->last_incxx . . $ $anonymous_type_83261257069d1fbd_0#last_in.) {
2436 /* Successfully finished read transaction.
2437 Accumulator contains less than 8 bits, because internal buffer
2438 is expanded byte-by-byte until it is enough to complete read. */
2439 s->buffer_lengthcxx . . $ BrotliDecoderStateStruct#buffer_length. = 0;
2440 /* Switch to input stream and restart. */
2441 result = BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.;
2442 BrotliBitReaderSetInputcxx . . $ BrotliBitReaderSetInput(13366109ed4e2f6c).(br, *next_in, *available_in);
2443 continue;
2444 } else if (*available_in != 0) {
2445 /* Not enough data in buffer, but can take one more byte from
2446 input stream. */
2447 result = BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.;
2448 BROTLI_DCHECKcxx . . $ `c/common/platform.h:473:9`!(s->buffer_length < 8);
2449 s->buffercxx . . $ BrotliDecoderStateStruct#buffer..u8cxx . . $ BrotliDecoderStateStruct#$anonymous_type_8#u8.[s->buffer_lengthcxx . . $ BrotliDecoderStateStruct#buffer_length.] = **next_in;
2450 s->buffer_lengthcxx . . $ BrotliDecoderStateStruct#buffer_length.++;
2451 BrotliBitReaderSetInputcxx . . $ BrotliBitReaderSetInput(13366109ed4e2f6c).(br, &s->buffercxx . . $ BrotliDecoderStateStruct#buffer..u8cxx . . $ BrotliDecoderStateStruct#$anonymous_type_8#u8.[0], s->buffer_lengthcxx . . $ BrotliDecoderStateStruct#buffer_length.);
2452 (*next_in)++;
2453 (*available_in)--;
2454 /* Retry with more data in buffer. */
2455 continue;
2456 }
2457 /* Can't finish reading and no more input. */
2458 break;
2459 } else { /* Input stream doesn't contain enough input. */
2460 /* Copy tail to internal buffer and return. */
2461 *next_in = br->next_incxx . . $ $anonymous_type_83261257069d1fbd_0#next_in.;
2462 *available_in = BrotliBitReaderGetAvailIncxx . . $ BrotliBitReaderGetAvailIn(a8eec9f290bacd2d).(br);
2463 while (*available_in) {
2464 s->buffercxx . . $ BrotliDecoderStateStruct#buffer..u8cxx . . $ BrotliDecoderStateStruct#$anonymous_type_8#u8.[s->buffer_lengthcxx . . $ BrotliDecoderStateStruct#buffer_length.] = **next_in;
2465 s->buffer_lengthcxx . . $ BrotliDecoderStateStruct#buffer_length.++;
2466 (*next_in)++;
2467 (*available_in)--;
2468 }
2469 break;
2470 }
2471 /* Unreachable. */
2472 }
2473
2474 /* Fail or needs more output. */
2475
2476 if (s->buffer_lengthcxx . . $ BrotliDecoderStateStruct#buffer_length. != 0) {
2477 /* Just consumed the buffered input and produced some output. Otherwise
2478 it would result in "needs more input". Reset internal buffer. */
2479 s->buffer_lengthcxx . . $ BrotliDecoderStateStruct#buffer_length. = 0;
2480 } else {
2481 /* Using input stream in last iteration. When decoder switches to input
2482 stream it has less than 8 bits in accumulator, so it is safe to
2483 return unused accumulator bits there. */
2484 BrotliBitReaderUnloadcxx . . $ BrotliBitReaderUnload(165eb0102fa4fad4).(br);
2485 *available_in = BrotliBitReaderGetAvailIncxx . . $ BrotliBitReaderGetAvailIn(a8eec9f290bacd2d).(br);
2486 *next_in = br->next_incxx . . $ $anonymous_type_83261257069d1fbd_0#next_in.;
2487 }
2488 break;
2489 }
2490 switch (s->statecxx . . $ BrotliDecoderStateStruct#state.) {
2491 case BROTLI_STATE_UNINITEDcxx . . $ BROTLI_STATE_UNINITED.:
2492 /* Prepare to the first read. */
2493 if (!BrotliWarmupBitReadercxx . . $ BrotliWarmupBitReader(4966df8ab2ee854a).(br)) {
2494 result = BROTLI_DECODER_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_INPUT.;
2495 break;
2496 }
2497 /* Decode window size. */
2498 result = DecodeWindowBitscxx . . $ DecodeWindowBits(2f206bf3bd0000ad).(s, br); /* Reads 1..8 bits. */
2499 if (result != BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.) {
2500 break;
2501 }
2502 if (s->large_windowcxx . . $ BrotliDecoderStateStruct#large_window.) {
2503 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_LARGE_WINDOW_BITScxx . . $ BROTLI_STATE_LARGE_WINDOW_BITS.;
2504 break;
2505 }
2506 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_INITIALIZEcxx . . $ BROTLI_STATE_INITIALIZE.;
2507 break;
2508
2509 case BROTLI_STATE_LARGE_WINDOW_BITScxx . . $ BROTLI_STATE_LARGE_WINDOW_BITS.: {
2510 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! bits;
2511 if (!BrotliSafeReadBitscxx . . $ BrotliSafeReadBits(d859fb483c1e4a60).(br, 6, &bits)) {
2512 result = BROTLI_DECODER_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_INPUT.;
2513 break;
2514 }
2515 s->window_bitscxx . . $ BrotliDecoderStateStruct#window_bits. = bits & 63u;
2516 if (s->window_bitscxx . . $ BrotliDecoderStateStruct#window_bits. < BROTLI_LARGE_MIN_WBITScxx . . $ `c/common/constants.h:49:9`! ||
2517 s->window_bitscxx . . $ BrotliDecoderStateStruct#window_bits. > BROTLI_LARGE_MAX_WBITScxx . . $ `c/common/constants.h:55:9`!) {
2518 result = BROTLI_FAILUREcxx . . $ `c/dec/decode.c:30:9`!(BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS);
2519 break;
2520 }
2521 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_INITIALIZEcxx . . $ BROTLI_STATE_INITIALIZE.;
2522 }
2523 /* Fall through. */
2524
2525 case BROTLI_STATE_INITIALIZEcxx . . $ BROTLI_STATE_INITIALIZE.:
2526 BROTLI_LOG_UINTcxx . . $ `c/dec/decode.c:32:9`!(s->window_bits);
2527 /* Maximum distance, see section 9.1. of the spec. */
2528 s->max_backward_distancecxx . . $ BrotliDecoderStateStruct#max_backward_distance. = (1 << s->window_bitscxx . . $ BrotliDecoderStateStruct#window_bits.) - BROTLI_WINDOW_GAPcxx . . $ `c/common/constants.h:100:9`!;
2529
2530 /* Allocate memory for both block_type_trees and block_len_trees. */
2531 s->block_type_treescxx . . $ BrotliDecoderStateStruct#block_type_trees. = (HuffmanCodecxx . . $ HuffmanCode#*)BROTLI_DECODER_ALLOCcxx . . $ `c/dec/state.h:381:9`!(s,
2532 sizeof(HuffmanCode) * 3 *
2533 (BROTLI_HUFFMAN_MAX_SIZE_258cxx . . $ `c/dec/huffman.h:23:9`! + BROTLI_HUFFMAN_MAX_SIZE_26cxx . . $ `c/dec/huffman.h:21:9`!));
2534 if (s->block_type_treescxx . . $ BrotliDecoderStateStruct#block_type_trees. == 0) {
2535 result = BROTLI_FAILUREcxx . . $ `c/dec/decode.c:30:9`!(BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES);
2536 break;
2537 }
2538 s->block_len_treescxx . . $ BrotliDecoderStateStruct#block_len_trees. =
2539 s->block_type_treescxx . . $ BrotliDecoderStateStruct#block_type_trees. + 3 * BROTLI_HUFFMAN_MAX_SIZE_258cxx . . $ `c/dec/huffman.h:23:9`!;
2540
2541 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_METABLOCK_BEGINcxx . . $ BROTLI_STATE_METABLOCK_BEGIN.;
2542 /* Fall through. */
2543
2544 case BROTLI_STATE_METABLOCK_BEGINcxx . . $ BROTLI_STATE_METABLOCK_BEGIN.:
2545 BrotliDecoderStateMetablockBegincxx . . $ BrotliDecoderStateMetablockBegin(bb1fb99afd41e748).(s);
2546 BROTLI_LOG_UINTcxx . . $ `c/dec/decode.c:32:9`!(s->pos);
2547 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_METABLOCK_HEADERcxx . . $ BROTLI_STATE_METABLOCK_HEADER.;
2548 /* Fall through. */
2549
2550 case BROTLI_STATE_METABLOCK_HEADERcxx . . $ BROTLI_STATE_METABLOCK_HEADER.:
2551 result = DecodeMetaBlockLengthcxx . . $ DecodeMetaBlockLength(2f206bf3bd0000ad).(s, br); /* Reads 2 - 31 bits. */
2552 if (result != BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.) {
2553 break;
2554 }
2555 BROTLI_LOG_UINTcxx . . $ `c/dec/decode.c:32:9`!(s->is_last_metablock);
2556 BROTLI_LOG_UINTcxx . . $ `c/dec/decode.c:32:9`!(s->meta_block_remaining_len);
2557 BROTLI_LOG_UINTcxx . . $ `c/dec/decode.c:32:9`!(s->is_metadata);
2558 BROTLI_LOG_UINTcxx . . $ `c/dec/decode.c:32:9`!(s->is_uncompressed);
2559 if (s->is_metadatacxx . . $ BrotliDecoderStateStruct#is_metadata. || s->is_uncompressedcxx . . $ BrotliDecoderStateStruct#is_uncompressed.) {
2560 if (!BrotliJumpToByteBoundarycxx . . $ BrotliJumpToByteBoundary(4966df8ab2ee854a).(br)) {
2561 result = BROTLI_FAILUREcxx . . $ `c/dec/decode.c:30:9`!(BROTLI_DECODER_ERROR_FORMAT_PADDING_1);
2562 break;
2563 }
2564 }
2565 if (s->is_metadatacxx . . $ BrotliDecoderStateStruct#is_metadata.) {
2566 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_METADATAcxx . . $ BROTLI_STATE_METADATA.;
2567 if (s->metadata_start_funccxx . . $ BrotliDecoderStateStruct#metadata_start_func.) {
2568 s->metadata_start_funccxx . . $ BrotliDecoderStateStruct#metadata_start_func.(s->metadata_callback_opaquecxx . . $ BrotliDecoderStateStruct#metadata_callback_opaque.,
2569 (size_t)s->meta_block_remaining_lencxx . . $ BrotliDecoderStateStruct#meta_block_remaining_len.);
2570 }
2571 break;
2572 }
2573 if (s->meta_block_remaining_lencxx . . $ BrotliDecoderStateStruct#meta_block_remaining_len. == 0) {
2574 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_METABLOCK_DONEcxx . . $ BROTLI_STATE_METABLOCK_DONE.;
2575 break;
2576 }
2577 BrotliCalculateRingBufferSizecxx . . $ BrotliCalculateRingBufferSize(bb1fb99afd41e748).(s);
2578 if (s->is_uncompressedcxx . . $ BrotliDecoderStateStruct#is_uncompressed.) {
2579 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_UNCOMPRESSEDcxx . . $ BROTLI_STATE_UNCOMPRESSED.;
2580 break;
2581 }
2582 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_BEFORE_COMPRESSED_METABLOCK_HEADERcxx . . $ BROTLI_STATE_BEFORE_COMPRESSED_METABLOCK_HEADER.;
2583 /* Fall through. */
2584
2585 case BROTLI_STATE_BEFORE_COMPRESSED_METABLOCK_HEADERcxx . . $ BROTLI_STATE_BEFORE_COMPRESSED_METABLOCK_HEADER.: {
2586 BrotliMetablockHeaderArenacxx . . $ BrotliMetablockHeaderArena#* h = &s->arenacxx . . $ BrotliDecoderStateStruct#arena..headercxx . . $ BrotliDecoderStateStruct#$anonymous_type_9#header.;
2587 s->loop_countercxx . . $ BrotliDecoderStateStruct#loop_counter. = 0;
2588 /* Initialize compressed metablock header arena. */
2589 h->sub_loop_countercxx . . $ BrotliMetablockHeaderArena#sub_loop_counter. = 0;
2590 /* Make small negative indexes addressable. */
2591 h->symbol_listscxx . . $ BrotliMetablockHeaderArena#symbol_lists. =
2592 &h->symbols_lists_arraycxx . . $ BrotliMetablockHeaderArena#symbols_lists_array.[BROTLI_HUFFMAN_MAX_CODE_LENGTHcxx . . $ `c/dec/huffman.h:18:9`! + 1];
2593 h->substate_huffmancxx . . $ BrotliMetablockHeaderArena#substate_huffman. = BROTLI_STATE_HUFFMAN_NONEcxx . . $ BROTLI_STATE_HUFFMAN_NONE.;
2594 h->substate_tree_groupcxx . . $ BrotliMetablockHeaderArena#substate_tree_group. = BROTLI_STATE_TREE_GROUP_NONEcxx . . $ BROTLI_STATE_TREE_GROUP_NONE.;
2595 h->substate_context_mapcxx . . $ BrotliMetablockHeaderArena#substate_context_map. = BROTLI_STATE_CONTEXT_MAP_NONEcxx . . $ BROTLI_STATE_CONTEXT_MAP_NONE.;
2596 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_HUFFMAN_CODE_0cxx . . $ BROTLI_STATE_HUFFMAN_CODE_0.;
2597 }
2598 /* Fall through. */
2599
2600 case BROTLI_STATE_HUFFMAN_CODE_0cxx . . $ BROTLI_STATE_HUFFMAN_CODE_0.:
2601 if (s->loop_countercxx . . $ BrotliDecoderStateStruct#loop_counter. >= 3) {
2602 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_METABLOCK_HEADER_2cxx . . $ BROTLI_STATE_METABLOCK_HEADER_2.;
2603 break;
2604 }
2605 /* Reads 1..11 bits. */
2606 result = DecodeVarLenUint8cxx . . $ DecodeVarLenUint8(8f6e4a21f550f5f6).(s, br, &s->num_block_typescxx . . $ BrotliDecoderStateStruct#num_block_types.[s->loop_countercxx . . $ BrotliDecoderStateStruct#loop_counter.]);
2607 if (result != BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.) {
2608 break;
2609 }
2610 s->num_block_typescxx . . $ BrotliDecoderStateStruct#num_block_types.[s->loop_countercxx . . $ BrotliDecoderStateStruct#loop_counter.]++;
2611 BROTLI_LOG_UINTcxx . . $ `c/dec/decode.c:32:9`!(s->num_block_types[s->loop_counter]);
2612 if (s->num_block_typescxx . . $ BrotliDecoderStateStruct#num_block_types.[s->loop_countercxx . . $ BrotliDecoderStateStruct#loop_counter.] < 2) {
2613 s->loop_countercxx . . $ BrotliDecoderStateStruct#loop_counter.++;
2614 break;
2615 }
2616 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_HUFFMAN_CODE_1cxx . . $ BROTLI_STATE_HUFFMAN_CODE_1.;
2617 /* Fall through. */
2618
2619 case BROTLI_STATE_HUFFMAN_CODE_1cxx . . $ BROTLI_STATE_HUFFMAN_CODE_1.: {
2620 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! alphabet_size = s->num_block_typescxx . . $ BrotliDecoderStateStruct#num_block_types.[s->loop_countercxx . . $ BrotliDecoderStateStruct#loop_counter.] + 2;
2621 int tree_offset = s->loop_countercxx . . $ BrotliDecoderStateStruct#loop_counter. * BROTLI_HUFFMAN_MAX_SIZE_258cxx . . $ `c/dec/huffman.h:23:9`!;
2622 result = ReadHuffmanCodecxx . . $ ReadHuffmanCode(acffa3267fb3b9f8).(alphabet_size, alphabet_size,
2623 &s->block_type_treescxx . . $ BrotliDecoderStateStruct#block_type_trees.[tree_offset], NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, s);
2624 if (result != BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.) break;
2625 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_HUFFMAN_CODE_2cxx . . $ BROTLI_STATE_HUFFMAN_CODE_2.;
2626 }
2627 /* Fall through. */
2628
2629 case BROTLI_STATE_HUFFMAN_CODE_2cxx . . $ BROTLI_STATE_HUFFMAN_CODE_2.: {
2630 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! alphabet_size = BROTLI_NUM_BLOCK_LEN_SYMBOLScxx . . $ `c/common/constants.h:26:9`!;
2631 int tree_offset = s->loop_countercxx . . $ BrotliDecoderStateStruct#loop_counter. * BROTLI_HUFFMAN_MAX_SIZE_26cxx . . $ `c/dec/huffman.h:21:9`!;
2632 result = ReadHuffmanCodecxx . . $ ReadHuffmanCode(acffa3267fb3b9f8).(alphabet_size, alphabet_size,
2633 &s->block_len_treescxx . . $ BrotliDecoderStateStruct#block_len_trees.[tree_offset], NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, s);
2634 if (result != BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.) break;
2635 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_HUFFMAN_CODE_3cxx . . $ BROTLI_STATE_HUFFMAN_CODE_3.;
2636 }
2637 /* Fall through. */
2638
2639 case BROTLI_STATE_HUFFMAN_CODE_3cxx . . $ BROTLI_STATE_HUFFMAN_CODE_3.: {
2640 int tree_offset = s->loop_countercxx . . $ BrotliDecoderStateStruct#loop_counter. * BROTLI_HUFFMAN_MAX_SIZE_26cxx . . $ `c/dec/huffman.h:21:9`!;
2641 if (!SafeReadBlockLengthcxx . . $ SafeReadBlockLength(b640658b5edcb718).(s, &s->block_lengthcxx . . $ BrotliDecoderStateStruct#block_length.[s->loop_countercxx . . $ BrotliDecoderStateStruct#loop_counter.],
2642 &s->block_len_treescxx . . $ BrotliDecoderStateStruct#block_len_trees.[tree_offset], br)) {
2643 result = BROTLI_DECODER_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_INPUT.;
2644 break;
2645 }
2646 BROTLI_LOG_UINTcxx . . $ `c/dec/decode.c:32:9`!(s->block_length[s->loop_counter]);
2647 s->loop_countercxx . . $ BrotliDecoderStateStruct#loop_counter.++;
2648 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_HUFFMAN_CODE_0cxx . . $ BROTLI_STATE_HUFFMAN_CODE_0.;
2649 break;
2650 }
2651
2652 case BROTLI_STATE_UNCOMPRESSEDcxx . . $ BROTLI_STATE_UNCOMPRESSED.: {
2653 result = CopyUncompressedBlockToOutputcxx . . $ CopyUncompressedBlockToOutput(fa575b40a6b6367e).(
2654 available_out, next_out, total_out, s);
2655 if (result != BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.) {
2656 break;
2657 }
2658 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_METABLOCK_DONEcxx . . $ BROTLI_STATE_METABLOCK_DONE.;
2659 break;
2660 }
2661
2662 case BROTLI_STATE_METADATAcxx . . $ BROTLI_STATE_METADATA.:
2663 result = SkipMetadataBlockcxx . . $ SkipMetadataBlock(fe8ed989e3875dcf).(s);
2664 if (result != BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.) {
2665 break;
2666 }
2667 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_METABLOCK_DONEcxx . . $ BROTLI_STATE_METABLOCK_DONE.;
2668 break;
2669
2670 case BROTLI_STATE_METABLOCK_HEADER_2cxx . . $ BROTLI_STATE_METABLOCK_HEADER_2.: {
2671 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! bits;
2672 if (!BrotliSafeReadBitscxx . . $ BrotliSafeReadBits(d859fb483c1e4a60).(br, 6, &bits)) {
2673 result = BROTLI_DECODER_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_INPUT.;
2674 break;
2675 }
2676 s->distance_postfix_bitscxx . . $ BrotliDecoderStateStruct#distance_postfix_bits. = bits & BitMaskcxx . . $ BitMask(ecdaa1632f49f591).(2);
2677 bits >>= 2;
2678 s->num_direct_distance_codescxx . . $ BrotliDecoderStateStruct#num_direct_distance_codes. = bits << s->distance_postfix_bitscxx . . $ BrotliDecoderStateStruct#distance_postfix_bits.;
2679 BROTLI_LOG_UINTcxx . . $ `c/dec/decode.c:32:9`!(s->num_direct_distance_codes);
2680 BROTLI_LOG_UINTcxx . . $ `c/dec/decode.c:32:9`!(s->distance_postfix_bits);
2681 s->context_modescxx . . $ BrotliDecoderStateStruct#context_modes. =
2682 (uint8_tcxx . . $ uint8_t#*)BROTLI_DECODER_ALLOCcxx . . $ `c/dec/state.h:381:9`!(s, (size_t)s->num_block_types[0]);
2683 if (s->context_modescxx . . $ BrotliDecoderStateStruct#context_modes. == 0) {
2684 result = BROTLI_FAILUREcxx . . $ `c/dec/decode.c:30:9`!(BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES);
2685 break;
2686 }
2687 s->loop_countercxx . . $ BrotliDecoderStateStruct#loop_counter. = 0;
2688 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_CONTEXT_MODEScxx . . $ BROTLI_STATE_CONTEXT_MODES.;
2689 }
2690 /* Fall through. */
2691
2692 case BROTLI_STATE_CONTEXT_MODEScxx . . $ BROTLI_STATE_CONTEXT_MODES.:
2693 result = ReadContextModescxx . . $ ReadContextModes(fe8ed989e3875dcf).(s);
2694 if (result != BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.) {
2695 break;
2696 }
2697 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_CONTEXT_MAP_1cxx . . $ BROTLI_STATE_CONTEXT_MAP_1.;
2698 /* Fall through. */
2699
2700 case BROTLI_STATE_CONTEXT_MAP_1cxx . . $ BROTLI_STATE_CONTEXT_MAP_1.:
2701 result = DecodeContextMapcxx . . $ DecodeContextMap(46820d3bfe197aa1).(
2702 s->num_block_typescxx . . $ BrotliDecoderStateStruct#num_block_types.[0] << BROTLI_LITERAL_CONTEXT_BITScxx . . $ `c/common/constants.h:92:9`!,
2703 &s->num_literal_htreescxx . . $ BrotliDecoderStateStruct#num_literal_htrees., &s->context_mapcxx . . $ BrotliDecoderStateStruct#context_map., s);
2704 if (result != BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.) {
2705 break;
2706 }
2707 DetectTrivialLiteralBlockTypescxx . . $ DetectTrivialLiteralBlockTypes(bb1fb99afd41e748).(s);
2708 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_CONTEXT_MAP_2cxx . . $ BROTLI_STATE_CONTEXT_MAP_2.;
2709 /* Fall through. */
2710
2711 case BROTLI_STATE_CONTEXT_MAP_2cxx . . $ BROTLI_STATE_CONTEXT_MAP_2.: {
2712 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! npostfix = s->distance_postfix_bitscxx . . $ BrotliDecoderStateStruct#distance_postfix_bits.;
2713 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! ndirect = s->num_direct_distance_codescxx . . $ BrotliDecoderStateStruct#num_direct_distance_codes.;
2714 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! distance_alphabet_size_max = BROTLI_DISTANCE_ALPHABET_SIZEcxx . . $ `c/common/constants.h:67:9`!(
2715 npostfix, ndirect, BROTLI_MAX_DISTANCE_BITScxx . . $ `c/common/constants.h:66:9`!);
2716 brotli_reg_tcxx . . $ `c/common/platform.h:237:9`! distance_alphabet_size_limit = distance_alphabet_size_max;
2717 BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! allocation_success = BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!;
2718 if (s->large_windowcxx . . $ BrotliDecoderStateStruct#large_window.) {
2719 BrotliDistanceCodeLimitcxx . . $ BrotliDistanceCodeLimit# limit = BrotliCalculateDistanceCodeLimitcxx . . $ BrotliCalculateDistanceCodeLimit(708cfc2bb1accb2c).(
2720 BROTLI_MAX_ALLOWED_DISTANCEcxx . . $ `c/common/constants.h:84:9`!, (uint32_tcxx . . $ uint32_t#)npostfix,
2721 (uint32_tcxx . . $ uint32_t#)ndirect);
2722 distance_alphabet_size_max = BROTLI_DISTANCE_ALPHABET_SIZEcxx . . $ `c/common/constants.h:67:9`!(
2723 npostfix, ndirect, BROTLI_LARGE_MAX_DISTANCE_BITScxx . . $ `c/common/constants.h:48:9`!);
2724 distance_alphabet_size_limit = limit.max_alphabet_sizecxx . . $ BrotliDistanceCodeLimit#max_alphabet_size.;
2725 }
2726 result = DecodeContextMapcxx . . $ DecodeContextMap(46820d3bfe197aa1).(
2727 s->num_block_typescxx . . $ BrotliDecoderStateStruct#num_block_types.[2] << BROTLI_DISTANCE_CONTEXT_BITScxx . . $ `c/common/constants.h:95:9`!,
2728 &s->num_dist_htreescxx . . $ BrotliDecoderStateStruct#num_dist_htrees., &s->dist_context_mapcxx . . $ BrotliDecoderStateStruct#dist_context_map., s);
2729 if (result != BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.) {
2730 break;
2731 }
2732 allocation_success &= BrotliDecoderHuffmanTreeGroupInitcxx . . $ BrotliDecoderHuffmanTreeGroupInit(20e2164bba7db65f).(
2733 s, &s->literal_hgroupcxx . . $ BrotliDecoderStateStruct#literal_hgroup., BROTLI_NUM_LITERAL_SYMBOLScxx . . $ `c/common/constants.h:24:9`!,
2734 BROTLI_NUM_LITERAL_SYMBOLScxx . . $ `c/common/constants.h:24:9`!, s->num_literal_htreescxx . . $ BrotliDecoderStateStruct#num_literal_htrees.);
2735 allocation_success &= BrotliDecoderHuffmanTreeGroupInitcxx . . $ BrotliDecoderHuffmanTreeGroupInit(20e2164bba7db65f).(
2736 s, &s->insert_copy_hgroupcxx . . $ BrotliDecoderStateStruct#insert_copy_hgroup., BROTLI_NUM_COMMAND_SYMBOLScxx . . $ `c/common/constants.h:25:9`!,
2737 BROTLI_NUM_COMMAND_SYMBOLScxx . . $ `c/common/constants.h:25:9`!, s->num_block_typescxx . . $ BrotliDecoderStateStruct#num_block_types.[1]);
2738 allocation_success &= BrotliDecoderHuffmanTreeGroupInitcxx . . $ BrotliDecoderHuffmanTreeGroupInit(20e2164bba7db65f).(
2739 s, &s->distance_hgroupcxx . . $ BrotliDecoderStateStruct#distance_hgroup., distance_alphabet_size_max,
2740 distance_alphabet_size_limit, s->num_dist_htreescxx . . $ BrotliDecoderStateStruct#num_dist_htrees.);
2741 if (!allocation_success) {
2742 return BROTLI_SAVE_ERROR_CODEcxx . . $ `c/dec/decode.c:2396:9`!(
2743 BROTLI_FAILUREcxx . . $ `c/dec/decode.c:30:9`!(BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS));
2744 }
2745 s->loop_countercxx . . $ BrotliDecoderStateStruct#loop_counter. = 0;
2746 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_TREE_GROUPcxx . . $ BROTLI_STATE_TREE_GROUP.;
2747 }
2748 /* Fall through. */
2749
2750 case BROTLI_STATE_TREE_GROUPcxx . . $ BROTLI_STATE_TREE_GROUP.: {
2751 HuffmanTreeGroupcxx . . $ HuffmanTreeGroup#* hgroup = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
2752 switch (s->loop_countercxx . . $ BrotliDecoderStateStruct#loop_counter.) {
2753 case 0: hgroup = &s->literal_hgroupcxx . . $ BrotliDecoderStateStruct#literal_hgroup.; break;
2754 case 1: hgroup = &s->insert_copy_hgroupcxx . . $ BrotliDecoderStateStruct#insert_copy_hgroup.; break;
2755 case 2: hgroup = &s->distance_hgroupcxx . . $ BrotliDecoderStateStruct#distance_hgroup.; break;
2756 default: return BROTLI_SAVE_ERROR_CODEcxx . . $ `c/dec/decode.c:2396:9`!(BROTLI_FAILUREcxx . . $ `c/dec/decode.c:30:9`!(
2757 BROTLI_DECODER_ERROR_UNREACHABLE)); /* COV_NF_LINE */
2758 }
2759 result = HuffmanTreeGroupDecodecxx . . $ HuffmanTreeGroupDecode(86fcbd07aef51349).(hgroup, s);
2760 if (result != BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.) break;
2761 s->loop_countercxx . . $ BrotliDecoderStateStruct#loop_counter.++;
2762 if (s->loop_countercxx . . $ BrotliDecoderStateStruct#loop_counter. < 3) {
2763 break;
2764 }
2765 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_BEFORE_COMPRESSED_METABLOCK_BODYcxx . . $ BROTLI_STATE_BEFORE_COMPRESSED_METABLOCK_BODY.;
2766 }
2767 /* Fall through. */
2768
2769 case BROTLI_STATE_BEFORE_COMPRESSED_METABLOCK_BODYcxx . . $ BROTLI_STATE_BEFORE_COMPRESSED_METABLOCK_BODY.:
2770 PrepareLiteralDecodingcxx . . $ PrepareLiteralDecoding(bb1fb99afd41e748).(s);
2771 s->dist_context_map_slicecxx . . $ BrotliDecoderStateStruct#dist_context_map_slice. = s->dist_context_mapcxx . . $ BrotliDecoderStateStruct#dist_context_map.;
2772 s->htree_commandcxx . . $ BrotliDecoderStateStruct#htree_command. = s->insert_copy_hgroupcxx . . $ BrotliDecoderStateStruct#insert_copy_hgroup..htreescxx . . $ $anonymous_type_421782d160a65272_1#htrees.[0];
2773 if (!BrotliEnsureRingBuffercxx . . $ BrotliEnsureRingBuffer(c67463180bf96cf).(s)) {
2774 result = BROTLI_FAILUREcxx . . $ `c/dec/decode.c:30:9`!(BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2);
2775 break;
2776 }
2777 CalculateDistanceLutcxx . . $ CalculateDistanceLut(bb1fb99afd41e748).(s);
2778 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_COMMAND_BEGINcxx . . $ BROTLI_STATE_COMMAND_BEGIN.;
2779 /* Fall through. */
2780
2781 case BROTLI_STATE_COMMAND_BEGINcxx . . $ BROTLI_STATE_COMMAND_BEGIN.:
2782 /* Fall through. */
2783 case BROTLI_STATE_COMMAND_INNERcxx . . $ BROTLI_STATE_COMMAND_INNER.:
2784 /* Fall through. */
2785 case BROTLI_STATE_COMMAND_POST_DECODE_LITERALScxx . . $ BROTLI_STATE_COMMAND_POST_DECODE_LITERALS.:
2786 /* Fall through. */
2787 case BROTLI_STATE_COMMAND_POST_WRAP_COPYcxx . . $ BROTLI_STATE_COMMAND_POST_WRAP_COPY.:
2788 result = ProcessCommandscxx . . $ ProcessCommands(fe8ed989e3875dcf).(s);
2789 if (result == BROTLI_DECODER_NEEDS_MORE_INPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_INPUT.) {
2790 result = SafeProcessCommandscxx . . $ SafeProcessCommands(fe8ed989e3875dcf).(s);
2791 }
2792 break;
2793
2794 case BROTLI_STATE_COMMAND_INNER_WRITEcxx . . $ BROTLI_STATE_COMMAND_INNER_WRITE.:
2795 /* Fall through. */
2796 case BROTLI_STATE_COMMAND_POST_WRITE_1cxx . . $ BROTLI_STATE_COMMAND_POST_WRITE_1.:
2797 /* Fall through. */
2798 case BROTLI_STATE_COMMAND_POST_WRITE_2cxx . . $ BROTLI_STATE_COMMAND_POST_WRITE_2.:
2799 result = WriteRingBuffercxx . . $ WriteRingBuffer(717a5536caf5ab00).(
2800 s, available_out, next_out, total_out, BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!);
2801 if (result != BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.) {
2802 break;
2803 }
2804 WrapRingBuffercxx . . $ WrapRingBuffer(bb1fb99afd41e748).(s);
2805 if (s->ringbuffer_sizecxx . . $ BrotliDecoderStateStruct#ringbuffer_size. == 1 << s->window_bitscxx . . $ BrotliDecoderStateStruct#window_bits.) {
2806 s->max_distancecxx . . $ BrotliDecoderStateStruct#max_distance. = s->max_backward_distancecxx . . $ BrotliDecoderStateStruct#max_backward_distance.;
2807 }
2808 if (s->statecxx . . $ BrotliDecoderStateStruct#state. == BROTLI_STATE_COMMAND_POST_WRITE_1cxx . . $ BROTLI_STATE_COMMAND_POST_WRITE_1.) {
2809 BrotliDecoderCompoundDictionarycxx . . $ BrotliDecoderCompoundDictionary#* addon = s->compound_dictionarycxx . . $ BrotliDecoderStateStruct#compound_dictionary.;
2810 if (addon && (addon->br_lengthcxx . . $ BrotliDecoderCompoundDictionary#br_length. != addon->br_copiedcxx . . $ BrotliDecoderCompoundDictionary#br_copied.)) {
2811 s->poscxx . . $ BrotliDecoderStateStruct#pos. += CopyFromCompoundDictionarycxx . . $ CopyFromCompoundDictionary(f13d6527b0ad88d0).(s, s->poscxx . . $ BrotliDecoderStateStruct#pos.);
2812 if (s->poscxx . . $ BrotliDecoderStateStruct#pos. >= s->ringbuffer_sizecxx . . $ BrotliDecoderStateStruct#ringbuffer_size.) continue;
2813 }
2814 if (s->meta_block_remaining_lencxx . . $ BrotliDecoderStateStruct#meta_block_remaining_len. == 0) {
2815 /* Next metablock, if any. */
2816 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_METABLOCK_DONEcxx . . $ BROTLI_STATE_METABLOCK_DONE.;
2817 } else {
2818 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_COMMAND_BEGINcxx . . $ BROTLI_STATE_COMMAND_BEGIN.;
2819 }
2820 break;
2821 } else if (s->statecxx . . $ BrotliDecoderStateStruct#state. == BROTLI_STATE_COMMAND_POST_WRITE_2cxx . . $ BROTLI_STATE_COMMAND_POST_WRITE_2.) {
2822 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_COMMAND_POST_WRAP_COPYcxx . . $ BROTLI_STATE_COMMAND_POST_WRAP_COPY.;
2823 } else { /* BROTLI_STATE_COMMAND_INNER_WRITE */
2824 if (s->loop_countercxx . . $ BrotliDecoderStateStruct#loop_counter. == 0) {
2825 if (s->meta_block_remaining_lencxx . . $ BrotliDecoderStateStruct#meta_block_remaining_len. == 0) {
2826 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_METABLOCK_DONEcxx . . $ BROTLI_STATE_METABLOCK_DONE.;
2827 } else {
2828 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_COMMAND_POST_DECODE_LITERALScxx . . $ BROTLI_STATE_COMMAND_POST_DECODE_LITERALS.;
2829 }
2830 break;
2831 }
2832 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_COMMAND_INNERcxx . . $ BROTLI_STATE_COMMAND_INNER.;
2833 }
2834 break;
2835
2836 case BROTLI_STATE_METABLOCK_DONEcxx . . $ BROTLI_STATE_METABLOCK_DONE.:
2837 if (s->meta_block_remaining_lencxx . . $ BrotliDecoderStateStruct#meta_block_remaining_len. < 0) {
2838 result = BROTLI_FAILUREcxx . . $ `c/dec/decode.c:30:9`!(BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2);
2839 break;
2840 }
2841 BrotliDecoderStateCleanupAfterMetablockcxx . . $ BrotliDecoderStateCleanupAfterMetablock(bb1fb99afd41e748).(s);
2842 if (!s->is_last_metablockcxx . . $ BrotliDecoderStateStruct#is_last_metablock.) {
2843 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_METABLOCK_BEGINcxx . . $ BROTLI_STATE_METABLOCK_BEGIN.;
2844 break;
2845 }
2846 if (!BrotliJumpToByteBoundarycxx . . $ BrotliJumpToByteBoundary(4966df8ab2ee854a).(br)) {
2847 result = BROTLI_FAILUREcxx . . $ `c/dec/decode.c:30:9`!(BROTLI_DECODER_ERROR_FORMAT_PADDING_2);
2848 break;
2849 }
2850 if (s->buffer_lengthcxx . . $ BrotliDecoderStateStruct#buffer_length. == 0) {
2851 BrotliBitReaderUnloadcxx . . $ BrotliBitReaderUnload(165eb0102fa4fad4).(br);
2852 *available_in = BrotliBitReaderGetAvailIncxx . . $ BrotliBitReaderGetAvailIn(a8eec9f290bacd2d).(br);
2853 *next_in = br->next_incxx . . $ $anonymous_type_83261257069d1fbd_0#next_in.;
2854 }
2855 s->statecxx . . $ BrotliDecoderStateStruct#state. = BROTLI_STATE_DONEcxx . . $ BROTLI_STATE_DONE.;
2856 /* Fall through. */
2857
2858 case BROTLI_STATE_DONEcxx . . $ BROTLI_STATE_DONE.:
2859 if (s->ringbuffercxx . . $ BrotliDecoderStateStruct#ringbuffer. != 0) {
2860 result = WriteRingBuffercxx . . $ WriteRingBuffer(717a5536caf5ab00).(
2861 s, available_out, next_out, total_out, BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!);
2862 if (result != BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS.) {
2863 break;
2864 }
2865 }
2866 return BROTLI_SAVE_ERROR_CODEcxx . . $ `c/dec/decode.c:2396:9`!(result);
2867 }
2868 }
2869 return BROTLI_SAVE_ERROR_CODEcxx . . $ `c/dec/decode.c:2396:9`!(result);
2870 #undef BROTLI_SAVE_ERROR_CODEcxx . . $ `c/dec/decode.c:2396:9`!
2871 }
2872
2873 BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! BrotliDecoderHasMoreOutputcxx . . $ BrotliDecoderHasMoreOutput(22169afd917f046c).(const BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s) {
2874 /* After unrecoverable error remaining output is considered nonsensical. */
2875 if ((int)s->error_codecxx . . $ BrotliDecoderStateStruct#error_code. < 0) {
2876 return BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!;
2877 }
2878 return TO_BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:55:9`!(
2879 s->ringbuffer != 0 && UnwrittenBytes(s, BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!) != 0);
2880 }
2881
2882 const uint8_tcxx . . $ uint8_t#* BrotliDecoderTakeOutputcxx . . $ BrotliDecoderTakeOutput(447a351043c1fef5).(BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s, size_t* size) {
2883 uint8_tcxx . . $ uint8_t#* result = 0;
2884 size_t available_out = *size ? *size : 1u << 24;
2885 size_t requested_out = available_out;
2886 BrotliDecoderErrorCodecxx . . $ BrotliDecoderErrorCode# status;
2887 if ((s->ringbuffercxx . . $ BrotliDecoderStateStruct#ringbuffer. == 0) || ((int)s->error_codecxx . . $ BrotliDecoderStateStruct#error_code. < 0)) {
2888 *size = 0;
2889 return 0;
2890 }
2891 WrapRingBuffercxx . . $ WrapRingBuffer(bb1fb99afd41e748).(s);
2892 status = WriteRingBuffercxx . . $ WriteRingBuffer(717a5536caf5ab00).(s, &available_out, &result, 0, BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!);
2893 /* Either WriteRingBuffer returns those "success" codes... */
2894 if (status == BROTLI_DECODER_SUCCESScxx . . $ BROTLI_DECODER_SUCCESS. ||
2895 status == BROTLI_DECODER_NEEDS_MORE_OUTPUTcxx . . $ BROTLI_DECODER_NEEDS_MORE_OUTPUT.) {
2896 *size = requested_out - available_out;
2897 } else {
2898 /* ... or stream is broken. Normally this should be caught by
2899 BrotliDecoderDecompressStream, this is just a safeguard. */
2900 if ((int)status < 0) SaveErrorCodecxx . . $ SaveErrorCode(77e1025b57b0953d).(s, status, 0);
2901 *size = 0;
2902 result = 0;
2903 }
2904 return result;
2905 }
2906
2907 BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! BrotliDecoderIsUsedcxx . . $ BrotliDecoderIsUsed(22169afd917f046c).(const BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s) {
2908 return TO_BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:55:9`!(s->state != BROTLI_STATE_UNINITED ||
2909 BrotliGetAvailableBits(&s->br) != 0);
2910 }
2911
2912 BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! BrotliDecoderIsFinishedcxx . . $ BrotliDecoderIsFinished(22169afd917f046c).(const BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s) {
2913 return TO_BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:55:9`!(s->state == BROTLI_STATE_DONE) &&
2914 !BrotliDecoderHasMoreOutputcxx . . $ BrotliDecoderHasMoreOutput(22169afd917f046c).(s);
2915 }
2916
2917 BrotliDecoderErrorCodecxx . . $ BrotliDecoderErrorCode# BrotliDecoderGetErrorCodecxx . . $ BrotliDecoderGetErrorCode(d2b9c2092cac6c53).(const BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* s) {
2918 return (BrotliDecoderErrorCodecxx . . $ BrotliDecoderErrorCode#)s->error_codecxx . . $ BrotliDecoderStateStruct#error_code.;
2919 }
2920
2921 const char* BrotliDecoderErrorStringcxx . . $ BrotliDecoderErrorString(305cc0e212fcaf65).(BrotliDecoderErrorCodecxx . . $ BrotliDecoderErrorCode# c) {
2922 switch (c) {
2923 #define BROTLI_ERROR_CODE_CASE_cxx . . $ `c/dec/decode.c:2923:9`!(PREFIX, NAME, CODE) \
2924 case BROTLI_DECODER ## PREFIX ## NAME: return #PREFIX #NAME;
2925 #define BROTLI_NOTHING_cxx . . $ `c/dec/decode.c:2925:9`!
2926 BROTLI_DECODER_ERROR_CODES_LISTcxx . . $ `c/include/brotli/decode.h:64:9`!(BROTLI_ERROR_CODE_CASE_cxx . . $ `c/dec/decode.c:2923:9`!, BROTLI_NOTHING_cxx . . $ `c/dec/decode.c:2925:9`!)
2927 #undef BROTLI_ERROR_CODE_CASE_cxx . . $ `c/dec/decode.c:2923:9`!
2928 #undef BROTLI_NOTHING_cxx . . $ `c/dec/decode.c:2925:9`!
2929 default: return "INVALID";
2930 }
2931 }
2932
2933 uint32_tcxx . . $ uint32_t# BrotliDecoderVersioncxx . . $ BrotliDecoderVersion(db52760e79bf9054).(void) {
2934 return BROTLI_VERSIONcxx . . $ `c/common/version.h:24:9`!;
2935 }
2936
2937 void BrotliDecoderSetMetadataCallbackscxx . . $ BrotliDecoderSetMetadataCallbacks(d86de944b677b10d).(
2938 BrotliDecoderStatecxx . . $ `c/dec/state.h:368:9`!* state,
2939 brotli_decoder_metadata_start_funccxx . . $ brotli_decoder_metadata_start_func# start_func,
2940 brotli_decoder_metadata_chunk_funccxx . . $ brotli_decoder_metadata_chunk_func# chunk_func, void* opaque) {
2941 state->metadata_start_funccxx . . $ BrotliDecoderStateStruct#metadata_start_func. = start_func;
2942 state->metadata_chunk_funccxx . . $ BrotliDecoderStateStruct#metadata_chunk_func. = chunk_func;
2943 state->metadata_callback_opaquecxx . . $ BrotliDecoderStateStruct#metadata_callback_opaque. = opaque;
2944 }
2945
2946 /* Escalate internal functions visibility; for testing purposes only. */
2947 #if defined(BROTLI_TEST)
2948 BROTLI_BOOL BrotliSafeReadSymbolForTest(
2949 const HuffmanCode*, BrotliBitReader*, brotli_reg_t*);
2950 BROTLI_BOOL BrotliSafeReadSymbolForTest(
2951 const HuffmanCode* table, BrotliBitReader* br, brotli_reg_t* result) {
2952 return SafeReadSymbol(table, br, result);
2953 }
2954 void BrotliInverseMoveToFrontTransformForTest(
2955 uint8_t*, brotli_reg_t, BrotliDecoderState*);
2956 void BrotliInverseMoveToFrontTransformForTest(
2957 uint8_t* v, brotli_reg_t l, BrotliDecoderState* s) {
2958 InverseMoveToFrontTransform(v, l, s);
2959 }
2960 #endif
2961
2962 #if defined(__cplusplus) || defined(c_plusplus)
2963 } /* extern "C" */
2964 #endif