Skip to content

Commit

Permalink
Merge branch 'fix-issue-118-prevent-integer-overflow' into release-1.…
Browse files Browse the repository at this point in the history
…8-hotfixes
  • Loading branch information
saitoha committed Dec 18, 2019
2 parents 5ab5f35 + 7833572 commit 9e88a7c
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/fromsixel.c
Expand Up @@ -369,28 +369,28 @@ image_buffer_resize(
if (width > image->width) { /* if width is extended */
for (n = 0; n < min_height; ++n) {
/* copy from source image */
memcpy(alt_buffer + width * n,
image->data + image->width * n,
memcpy(alt_buffer + (size_t)width * (size_t)n,
image->data + (size_t)image->width * (size_t)n,
(size_t)image->width);
/* fill extended area with background color */
memset(alt_buffer + width * n + image->width,
memset(alt_buffer + (size_t)width * (size_t)n + (size_t)image->width,
bgindex,
(size_t)(width - image->width));
}
} else {
for (n = 0; n < min_height; ++n) {
/* copy from source image */
memcpy(alt_buffer + width * n,
image->data + image->width * n,
memcpy(alt_buffer + (size_t)width * (size_t)n,
image->data + (size_t)image->width * (size_t)n,
(size_t)width);
}
}

if (height > image->height) { /* if height is extended */
/* fill extended area with background color */
memset(alt_buffer + width * image->height,
memset(alt_buffer + (size_t)width * (size_t)image->height,
bgindex,
(size_t)(width * (height - image->height)));
(size_t)width * (size_t)(height - image->height));
}

/* free source image */
Expand Down Expand Up @@ -472,7 +472,7 @@ sixel_decode_raw_impl(
int sx;
int sy;
int c;
int pos;
size_t pos;
unsigned char *p0 = p;

while (p < p0 + len) {
Expand Down Expand Up @@ -674,7 +674,7 @@ sixel_decode_raw_impl(
if (context->repeat_count <= 1) {
for (i = 0; i < 6; i++) {
if ((bits & sixel_vertical_mask) != 0) {
pos = image->width * (context->pos_y + i) + context->pos_x;
pos = (size_t)image->width * (size_t)(context->pos_y + i) + (size_t)context->pos_x;
image->data[pos] = context->color_index;
if (context->max_x < context->pos_x) {
context->max_x = context->pos_x;
Expand All @@ -698,7 +698,7 @@ sixel_decode_raw_impl(
c <<= 1;
}
for (y = context->pos_y + i; y < context->pos_y + i + n; ++y) {
memset(image->data + image->width * y + context->pos_x,
memset(image->data + (size_t)image->width * (size_t)y + (size_t)context->pos_x,
context->color_index,
(size_t)context->repeat_count);
}
Expand Down

0 comments on commit 9e88a7c

Please sign in to comment.