Skip to content

Commit f67eafb

Browse files
committed
Fix Brotli output buffer size validation
1 parent ae8deec commit f67eafb

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

src/lib/brotli.inc.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ static uint32_t my_crc32(const uint8_t *data, size_t len, uint32_t crc) {
3939
}
4040

4141
static size_t simple_compress(const uint8_t *input, size_t input_len, uint8_t *output, size_t output_len) {
42-
if (output_len < input_len + 8) {
42+
const size_t header_size = 5 + 8 + 4;
43+
if (output_len < header_size || input_len > output_len - header_size) {
4344
return 0;
4445
}
4546
memcpy (output, "BROT", 4);
@@ -54,7 +55,7 @@ static size_t simple_compress(const uint8_t *input, size_t input_len, uint8_t *o
5455
}
5556

5657
static size_t simple_decompress(const uint8_t *input, size_t input_len, uint8_t *output, size_t output_len) {
57-
if (input_len < 5 + sizeof (size_t) + sizeof (uint32_t)) {
58+
if (input_len < 5 + 8 + 4) {
5859
return 0;
5960
}
6061
if (memcmp (input, "BROT", 4) != 0) {
@@ -69,7 +70,7 @@ static size_t simple_decompress(const uint8_t *input, size_t input_len, uint8_t
6970
return 0;
7071
}
7172
uint32_t stored_crc = otezip_read_le32 (input + 5 + 8);
72-
const uint8_t *data = input + 5 + sizeof (size_t) + sizeof (uint32_t);
73+
const uint8_t *data = input + 5 + 8 + 4;
7374
uint32_t computed_crc = my_crc32 (data, stored_len, 0);
7475
if (stored_crc != computed_crc) {
7576
return 0;

0 commit comments

Comments
 (0)