mirror of
https://github.com/google/brotli.git
synced 2024-11-30 07:00:06 +00:00
Merge pull request #348 from google/safe-api
Make encoder API more safe
This commit is contained in:
commit
b00b000847
@ -442,7 +442,8 @@ BrotliCompressor::BrotliCompressor(BrotliParams params)
|
|||||||
large_table_(NULL),
|
large_table_(NULL),
|
||||||
cmd_code_numbits_(0),
|
cmd_code_numbits_(0),
|
||||||
command_buf_(NULL),
|
command_buf_(NULL),
|
||||||
literal_buf_(NULL) {
|
literal_buf_(NULL),
|
||||||
|
is_last_block_emitted_(0) {
|
||||||
// Sanitize params.
|
// Sanitize params.
|
||||||
params_.quality = std::max(0, params_.quality);
|
params_.quality = std::max(0, params_.quality);
|
||||||
if (params_.lgwin < kMinWindowBits) {
|
if (params_.lgwin < kMinWindowBits) {
|
||||||
@ -582,6 +583,10 @@ bool BrotliCompressor::WriteBrotliData(const bool is_last,
|
|||||||
const uint64_t delta = input_pos_ - last_processed_pos_;
|
const uint64_t delta = input_pos_ - last_processed_pos_;
|
||||||
const uint8_t* data = ringbuffer_->start();
|
const uint8_t* data = ringbuffer_->start();
|
||||||
const uint32_t mask = ringbuffer_->mask();
|
const uint32_t mask = ringbuffer_->mask();
|
||||||
|
|
||||||
|
/* Adding more blocks after "last" block is forbidden. */
|
||||||
|
if (is_last_block_emitted_) return false;
|
||||||
|
if (is_last) is_last_block_emitted_ = 1;
|
||||||
|
|
||||||
if (delta > input_block_size()) {
|
if (delta > input_block_size()) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -180,6 +180,8 @@ class BrotliCompressor {
|
|||||||
// Command and literal buffers for quality 1.
|
// Command and literal buffers for quality 1.
|
||||||
uint32_t* command_buf_;
|
uint32_t* command_buf_;
|
||||||
uint8_t* literal_buf_;
|
uint8_t* literal_buf_;
|
||||||
|
|
||||||
|
int is_last_block_emitted_;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Compresses the data in input_buffer into encoded_buffer, and sets
|
// Compresses the data in input_buffer into encoded_buffer, and sets
|
||||||
|
Loading…
Reference in New Issue
Block a user