Merge pull request #176 from szabadka/master

Fix a bug in CopyUncompressedBlockToOutput().
This commit is contained in:
szabadka 2015-09-25 19:33:03 +02:00
commit c11ce30a87
2 changed files with 6 additions and 15 deletions

View File

@ -826,23 +826,16 @@ BrotliResult BROTLI_NOINLINE CopyUncompressedBlockToOutput(BrotliOutput output,
/* No break, if state is updated, continue to next state */ /* No break, if state is updated, continue to next state */
case BROTLI_STATE_UNCOMPRESSED_WRITE_1: case BROTLI_STATE_UNCOMPRESSED_WRITE_1:
case BROTLI_STATE_UNCOMPRESSED_WRITE_2: case BROTLI_STATE_UNCOMPRESSED_WRITE_2:
case BROTLI_STATE_UNCOMPRESSED_WRITE_3:
result = WriteRingBuffer(output, s); result = WriteRingBuffer(output, s);
if (result != BROTLI_RESULT_SUCCESS) { if (result != BROTLI_RESULT_SUCCESS) {
return result; return result;
} }
pos &= s->ringbuffer_mask; pos &= s->ringbuffer_mask;
s->max_distance = s->max_backward_distance; s->max_distance = s->max_backward_distance;
if (s->substate_uncompressed == BROTLI_STATE_UNCOMPRESSED_WRITE_2) { /* If we wrote past the logical end of the ringbuffer, copy the tail
s->substate_uncompressed = BROTLI_STATE_UNCOMPRESSED_SHORT; of the ringbuffer to its beginning and flush the ringbuffer to the
break; output. */
} memcpy(s->ringbuffer, s->ringbuffer_end, (size_t)pos);
if (s->substate_uncompressed == BROTLI_STATE_UNCOMPRESSED_WRITE_1) {
/* If we wrote past the logical end of the ringbuffer, copy the tail
of the ringbuffer to its beginning and flush the ringbuffer to the
output. */
memcpy(s->ringbuffer, s->ringbuffer_end, (size_t)pos);
}
if (pos + s->meta_block_remaining_len >= s->ringbuffer_size) { if (pos + s->meta_block_remaining_len >= s->ringbuffer_size) {
s->substate_uncompressed = BROTLI_STATE_UNCOMPRESSED_FILL; s->substate_uncompressed = BROTLI_STATE_UNCOMPRESSED_FILL;
} else { } else {
@ -865,9 +858,8 @@ BrotliResult BROTLI_NOINLINE CopyUncompressedBlockToOutput(BrotliOutput output,
} }
s->to_write = s->ringbuffer_size; s->to_write = s->ringbuffer_size;
s->partially_written = 0; s->partially_written = 0;
s->substate_uncompressed = BROTLI_STATE_UNCOMPRESSED_WRITE_3; s->substate_uncompressed = BROTLI_STATE_UNCOMPRESSED_WRITE_1;
break; break;
/* No break, continue to next state */
case BROTLI_STATE_UNCOMPRESSED_COPY: case BROTLI_STATE_UNCOMPRESSED_COPY:
/* Copy straight from the input onto the ringbuffer. The ringbuffer will /* Copy straight from the input onto the ringbuffer. The ringbuffer will
be flushed to the output at a later time. */ be flushed to the output at a later time. */

View File

@ -70,8 +70,7 @@ typedef enum {
BROTLI_STATE_UNCOMPRESSED_FILL, BROTLI_STATE_UNCOMPRESSED_FILL,
BROTLI_STATE_UNCOMPRESSED_COPY, BROTLI_STATE_UNCOMPRESSED_COPY,
BROTLI_STATE_UNCOMPRESSED_WRITE_1, BROTLI_STATE_UNCOMPRESSED_WRITE_1,
BROTLI_STATE_UNCOMPRESSED_WRITE_2, BROTLI_STATE_UNCOMPRESSED_WRITE_2
BROTLI_STATE_UNCOMPRESSED_WRITE_3
} BrotliRunningUncompressedState; } BrotliRunningUncompressedState;
typedef enum { typedef enum {