From 93adbb0b11218e684895520cba2fdd1f1ae11a15 Mon Sep 17 00:00:00 2001 From: Alexandre Perrin Date: Tue, 4 Oct 2016 11:10:55 +0200 Subject: [PATCH 1/2] Avoid division by zero. Before this patch, small images (i.e. 7x7 pixels or less) could trigger SIGFPE because of a (integer) division by zero. --- lib/identify.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/identify.c b/lib/identify.c index 9ae9ee5..80c9837 100644 --- a/lib/identify.c +++ b/lib/identify.c @@ -174,6 +174,7 @@ static void flood_fill_seed(struct quirc *q, int x, int y, int from, int to, * Adaptive thresholding */ +#define THRESHOLD_S_MIN 1 #define THRESHOLD_S_DEN 8 #define THRESHOLD_T 5 @@ -185,6 +186,15 @@ static void threshold(struct quirc *q) int threshold_s = q->w / THRESHOLD_S_DEN; quirc_pixel_t *row = q->pixels; + /* + * Ensure a sane, non-zero value for threshold_s to + * + * threshold_s can be zero if the image width is small. We need to avoid + * SIGFPE as it will be used as divisor. + */ + if (threshold_s < THRESHOLD_S_MIN) + threshold_s = THRESHOLD_S_MIN; + for (y = 0; y < q->h; y++) { int row_average[q->w]; From 6f0ed74aa2c01b46afdea9ec16a0ad826764446e Mon Sep 17 00:00:00 2001 From: Alexandre Perrin Date: Tue, 4 Oct 2016 11:13:49 +0200 Subject: [PATCH 2/2] Comment typo. --- lib/identify.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/identify.c b/lib/identify.c index 80c9837..bf7bd94 100644 --- a/lib/identify.c +++ b/lib/identify.c @@ -187,7 +187,7 @@ static void threshold(struct quirc *q) quirc_pixel_t *row = q->pixels; /* - * Ensure a sane, non-zero value for threshold_s to + * Ensure a sane, non-zero value for threshold_s. * * threshold_s can be zero if the image width is small. We need to avoid * SIGFPE as it will be used as divisor.