Skip to content

Avoid possible overflow when multiplication result is cast up/down #4412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
- heifload: prevent possible int overflow for large images [kleisauke]
- tiffload: add missing read loop [kleisauke]
- prevent possible use-after-free when debugging via `--vips-leak` flag [lovell]
- avoid possible overflow when multiplication result is cast up [lovell]

10/10/24 8.16.0

Expand Down
4 changes: 2 additions & 2 deletions libvips/arithmetic/hist_find_indexed.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ histogram_new(VipsHistFindIndexed *indexed)
!(hist->reg = vips_region_new(indexed->index_ready)))
return NULL;

memset(hist->bins, 0, bands * hist->size * sizeof(double));
memset(hist->init, 0, hist->size * sizeof(int));
memset(hist->bins, 0, (size_t) bands * hist->size * sizeof(double));
memset(hist->init, 0, (size_t) hist->size * sizeof(int));

return hist;
}
Expand Down
4 changes: 2 additions & 2 deletions libvips/arithmetic/project.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ histogram_new(VipsProject *project)
!hist->row_sums)
return NULL;

memset(hist->column_sums, 0, psize * in->Xsize);
memset(hist->row_sums, 0, psize * in->Ysize);
memset(hist->column_sums, 0, (size_t) psize * in->Xsize);
memset(hist->row_sums, 0, (size_t) psize * in->Ysize);

return hist;
}
Expand Down
4 changes: 2 additions & 2 deletions libvips/colour/LCh2UCS.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ vips_col_Ch2hcmc(float C, float h)
}

P = cos(VIPS_RAD(k7 * h + k8));
D = k4 + k5 * P * pow(VIPS_FABS(P), k6);
D = k4 + k5 * P * powf(fabsf(P), k6);
g = C * C * C * C;
f = sqrt(g / (g + 1900.0));
f = sqrtf(g / (g + 1900.0F));
hcmc = h + D * f;

return hcmc;
Expand Down
2 changes: 1 addition & 1 deletion libvips/conversion/bandfold.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ vips_bandfold_gen(VipsRegion *out_region,
/* We can't use vips_region_region() since we change pixel
* coordinates.
*/
memcpy(q, p, psize * r->width);
memcpy(q, p, (size_t) psize * r->width);
}

return 0;
Expand Down
2 changes: 1 addition & 1 deletion libvips/conversion/bandunfold.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ vips_bandunfold_gen(VipsRegion *out_region,
/* We can't use vips_region_region() since we change pixel
* coordinates.
*/
memcpy(q, p, r->width * psize);
memcpy(q, p, (size_t) r->width * psize);
}

return 0;
Expand Down
2 changes: 1 addition & 1 deletion libvips/conversion/composite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ vips_composite_base_blend3(VipsCompositeSequence *seq,
/* You can't sqrt a vector, so we must loop.
*/
for (int b = 0; b < 3; b++) {
double g;
float g;

if (B[b] <= 0.25)
g = ((16 * B[b] - 12) * B[b] + 4) * B[b];
Expand Down
2 changes: 1 addition & 1 deletion libvips/conversion/embed.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ vips_embed_base_paint_edge(VipsEmbedBase *base,
*/
for (y = 0; y < todo.height; y++) {
q = VIPS_REGION_ADDR(out_region, todo.left, todo.top + y);
memcpy(q, p, bs * todo.width);
memcpy(q, p, (size_t) bs * todo.width);
}
}

Expand Down
2 changes: 1 addition & 1 deletion libvips/foreign/jp2ksave.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ vips_foreign_save_jp2k_sizeof_tile(VipsForeignSaveJp2k *jp2k, VipsRect *tile)
(double) tile->height / comp->dy);
;

size += output_width * output_height * sizeof_element;
size += (size_t) output_width * output_height * sizeof_element;
}

return size;
Expand Down
2 changes: 1 addition & 1 deletion libvips/foreign/nsgifload.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ vips_foreign_load_nsgif_generate(VipsRegion *out_region,
gif->frame_number = page;
}

p = (VipsPel *) gif->bitmap + line * gif->info->width * sizeof(int);
p = (VipsPel *) gif->bitmap + (size_t) line * gif->info->width * sizeof(int);
q = VIPS_REGION_ADDR(out_region, 0, r->top + y);
if (gif->has_transparency)
memcpy(q, p, VIPS_REGION_SIZEOF_LINE(out_region));
Expand Down
4 changes: 2 additions & 2 deletions libvips/foreign/tiff2vips.c
Original file line number Diff line number Diff line change
Expand Up @@ -1659,7 +1659,7 @@ static void
rtiff_memcpy_f16_line(Rtiff *rtiff, VipsPel *q, VipsPel *p, int n, void *client)
{
VipsImage *im = (VipsImage *) client;
size_t len = n * im->Bands;
size_t len = (size_t) n * im->Bands;

if (im->BandFmt == VIPS_FORMAT_COMPLEX ||
im->BandFmt == VIPS_FORMAT_DPCOMPLEX)
Expand Down Expand Up @@ -2107,7 +2107,7 @@ rtiff_decompress_jpeg_run(Rtiff *rtiff, j_decompress_ptr cinfo,
}

jpeg_calc_output_dimensions(cinfo);
bytes_per_scanline = cinfo->output_width * bytes_per_pixel;
bytes_per_scanline = (size_t) cinfo->output_width * bytes_per_pixel;

/* Double-check tile dimensions.
*/
Expand Down
2 changes: 1 addition & 1 deletion libvips/foreign/vips2tiff.c
Original file line number Diff line number Diff line change
Expand Up @@ -2302,7 +2302,7 @@ wtiff_copy_tiles(Wtiff *wtiff, TIFF *out, TIFF *in)
* simpler than searching every page for the largest tile with
* TIFFTAG_TILEBYTECOUNTS.
*/
tile_size = 2 * wtiff->tls * wtiff->tileh;
tile_size = (tsize_t) 2 * wtiff->tls * wtiff->tileh;

buf = vips_malloc(NULL, tile_size);

Expand Down
2 changes: 1 addition & 1 deletion libvips/foreign/webp2vips.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ vips_image_paint_image(VipsImage *frame,
}
else
memcpy((char *) q, (char *) p,
ovl.width * ps);
(size_t) ovl.width * ps);

p += VIPS_IMAGE_SIZEOF_LINE(sub);
q += VIPS_IMAGE_SIZEOF_LINE(frame);
Expand Down
2 changes: 1 addition & 1 deletion libvips/foreign/webpsave.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ vips_foreign_save_webp_sink_disc(VipsRegion *region, VipsRect *area, void *a)
memcpy(webp->frame_bytes +
area->width * webp->write_y * save->ready->Bands,
VIPS_REGION_ADDR(region, 0, area->top + i),
area->width * save->ready->Bands);
(size_t) area->width * save->ready->Bands);

webp->write_y += 1;

Expand Down
2 changes: 1 addition & 1 deletion libvips/iofuncs/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -3241,7 +3241,7 @@ vips_image_write_line(VipsImage *image, int ypos, VipsPel *linebuffer)

/* Trigger evaluation callbacks for this image.
*/
vips_image_eval(image, ypos * image->Xsize);
vips_image_eval(image, (guint64) ypos * image->Xsize);
if (vips_image_iskilled(image))
return -1;

Expand Down
2 changes: 1 addition & 1 deletion libvips/iofuncs/sink.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ sink_area_allocate_fn(VipsThreadState *state, void *a, gboolean *stop)

/* Add the number of pixels we've just allocated to progress.
*/
sink_base->processed += state->pos.width * state->pos.height;
sink_base->processed += (guint64) state->pos.width * state->pos.height;

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion libvips/iofuncs/sinkdisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ wbuffer_allocate_fn(VipsThreadState *state, void *a, gboolean *stop)

/* Add the number of pixels we've just allocated to progress.
*/
sink_base->processed += state->pos.width * state->pos.height;
sink_base->processed += (guint64) state->pos.width * state->pos.height;

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion libvips/iofuncs/sinkmemory.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ sink_memory_area_allocate_fn(VipsThreadState *state, void *a, gboolean *stop)

/* Add the number of pixels we've just allocated to progress.
*/
sink_base->processed += state->pos.width * state->pos.height;
sink_base->processed += (guint64) state->pos.width * state->pos.height;

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion libvips/mosaicing/matrixinvert.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ lu_decomp(VipsImage *mat)

/* copy all coefficients and then perform decomposition in-place */
memcpy(VIPS_MATRIX(lu, 0, 0), VIPS_MATRIX(mat, 0, 0),
mat->Xsize * mat->Xsize * sizeof(double));
(size_t) mat->Xsize * mat->Xsize * sizeof(double));

for (i = 0; i < mat->Xsize; ++i) {
row_scale[i] = 0.0;
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy