diff --git a/c/dec/decode.c b/c/dec/decode.c index 220c7e8..7790f92 100644 --- a/c/dec/decode.c +++ b/c/dec/decode.c @@ -1899,6 +1899,22 @@ static BROTLI_INLINE BROTLI_BOOL CheckInputAmount( } \ } +/* Reads up to limit symbols from br and copies them into ringbuffer, + starting from pos. Caller must ensure that this is safe. */ +static BROTLI_INLINE void BrotliCopyPreloadedSymbols(BrotliBitReader* br, + brotli_reg_t* bits, + brotli_reg_t* value, + BrotliDecoderState* s, + int pos, + int limit) { + int pos_limit = pos + limit; + for (; pos < pos_limit; pos++) { + s->ringbuffer[pos] = + (uint8_t)ReadPreloadedSymbol(s->literal_htree, br, bits, value); + BROTLI_LOG_ARRAY_INDEX(s->ringbuffer, pos); + } +} + static BROTLI_INLINE BrotliDecoderErrorCode ProcessCommandsInternal( int safe, BrotliDecoderState* s) { int pos = s->pos; @@ -1969,8 +1985,7 @@ CommandInner: goto NextLiteralBlock; } if (!safe) { - s->ringbuffer[pos] = - (uint8_t)ReadPreloadedSymbol(s->literal_htree, br, &bits, &value); + BrotliCopyPreloadedSymbols(br, &bits, &value, s, pos, 1); } else { brotli_reg_t literal; if (!SafeReadSymbol(s->literal_htree, br, &literal)) {