From dc49c807926b96e503bd7c0dec35119eecd6c6fe Mon Sep 17 00:00:00 2001 From: Jason Summers Date: Mon, 15 May 2017 13:27:08 -0400 Subject: [PATCH] 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 --- src/imagew-api.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/imagew-api.c b/src/imagew-api.c index 3953731..80531ab 100644 --- a/src/imagew-api.c +++ b/src/imagew-api.c @@ -483,13 +483,20 @@ IW_IMPL(int) iw_get_input_density(struct iw_context *ctx, { *px = 1.0; *py = 1.0; - *pcode = ctx->img1.density_code; - if(ctx->img1.density_code!=IW_DENSITY_UNKNOWN) { - *px = ctx->img1.density_x; - *py = ctx->img1.density_y; - return 1; + *pcode = IW_DENSITY_UNKNOWN; + + if(ctx->img1.density_code==IW_DENSITY_UNKNOWN) { + return 0; } - return 0; + if(!iw_is_valid_density(ctx->img1.density_x, ctx->img1.density_y, + ctx->img1.density_code)) + { + return 0; + } + *px = ctx->img1.density_x; + *py = ctx->img1.density_y; + *pcode = ctx->img1.density_code; + return 1; } IW_IMPL(void) iw_set_output_density(struct iw_context *ctx,