Skip to content

Commit

Permalink
Fix Adam Borowski's patch to work on inflated blocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
kspalaiologos authored May 20, 2023
1 parent 8154d1e commit b4478cc
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ static int process(FILE * input_des, FILE * output_des, int mode, int block_size
return 1;
}

u8 * buffer = malloc(block_size + block_size / 50 + 32);
u8 * buffer = malloc(bz3_bound(block_size));

if (!buffer) {
fprintf(stderr, "Failed to allocate memory.\n");
Expand Down Expand Up @@ -244,7 +244,7 @@ static int process(FILE * input_des, FILE * output_des, int mode, int block_size
new_size = read_neutral_s32(byteswap_buf);
xread_noeof(&byteswap_buf, 1, 4, input_des);
old_size = read_neutral_s32(byteswap_buf);
if (old_size > block_size || new_size > block_size + 31) {
if (old_size > bz3_bound(block_size) || new_size > bz3_bound(block_size)) {
fprintf(stderr, "Failed to decode a block: Inconsistent headers.\n");
return 1;
}
Expand All @@ -265,7 +265,7 @@ static int process(FILE * input_des, FILE * output_des, int mode, int block_size
new_size = read_neutral_s32(byteswap_buf);
xread_noeof(&byteswap_buf, 1, 4, input_des);
old_size = read_neutral_s32(byteswap_buf);
if (old_size > block_size || new_size > block_size + 31) {
if (old_size > bz3_bound(block_size) || new_size > bz3_bound(block_size)) {
fprintf(stderr, "Failed to decode a block: Inconsistent headers.\n");
return 1;
}
Expand Down Expand Up @@ -343,7 +343,7 @@ static int process(FILE * input_des, FILE * output_des, int mode, int block_size
sizes[i] = read_neutral_s32(byteswap_buf);
xread_noeof(&byteswap_buf, 1, 4, input_des);
old_sizes[i] = read_neutral_s32(byteswap_buf);
if (old_sizes[i] > block_size || sizes[i] > block_size + 31) {
if (old_sizes[i] > bz3_bound(block_size) || sizes[i] > bz3_bound(block_size)) {
fprintf(stderr, "Failed to decode a block: Inconsistent headers.\n");
return 1;
}
Expand Down Expand Up @@ -371,7 +371,7 @@ static int process(FILE * input_des, FILE * output_des, int mode, int block_size
sizes[i] = read_neutral_s32(byteswap_buf);
xread_noeof(&byteswap_buf, 1, 4, input_des);
old_sizes[i] = read_neutral_s32(byteswap_buf);
if (old_sizes[i] > block_size || sizes[i] > block_size + 31) {
if (old_sizes[i] > bz3_bound(block_size) || sizes[i] > bz3_bound(block_size)) {
fprintf(stderr, "Failed to decode a block: Inconsistent headers.\n");
return 1;
}
Expand Down

0 comments on commit b4478cc

Please sign in to comment.