Skip to content

Commit dc49c80

Browse files
committed
Double-check that the input image's density is valid
Fixes a bug that could result in division by zero, at least for a JPEG source image. Fixes issues #19, #20
1 parent fd95654 commit dc49c80

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

Diff for: src/imagew-api.c

+13-6
Original file line numberDiff line numberDiff line change
@@ -483,13 +483,20 @@ IW_IMPL(int) iw_get_input_density(struct iw_context *ctx,
483483
{
484484
*px = 1.0;
485485
*py = 1.0;
486-
*pcode = ctx->img1.density_code;
487-
if(ctx->img1.density_code!=IW_DENSITY_UNKNOWN) {
488-
*px = ctx->img1.density_x;
489-
*py = ctx->img1.density_y;
490-
return 1;
486+
*pcode = IW_DENSITY_UNKNOWN;
487+
488+
if(ctx->img1.density_code==IW_DENSITY_UNKNOWN) {
489+
return 0;
491490
}
492-
return 0;
491+
if(!iw_is_valid_density(ctx->img1.density_x, ctx->img1.density_y,
492+
ctx->img1.density_code))
493+
{
494+
return 0;
495+
}
496+
*px = ctx->img1.density_x;
497+
*py = ctx->img1.density_y;
498+
*pcode = ctx->img1.density_code;
499+
return 1;
493500
}
494501

495502
IW_IMPL(void) iw_set_output_density(struct iw_context *ctx,

0 commit comments

Comments
 (0)