[1.5] division by zero in j2k_read_siz
authorMathieu Malaterre <mathieu.malaterre@gmail.com>
Tue, 2 Oct 2012 07:09:57 +0000 (07:09 +0000)
committerMathieu Malaterre <mathieu.malaterre@gmail.com>
Tue, 2 Oct 2012 07:09:57 +0000 (07:09 +0000)
Fixes issue 169

libopenjpeg/j2k.c

index 3f8e27909a3a62cc036c9da1301891159ec27b60..2900e911f33721ac549bbee44e1e9841b7042e10 100644 (file)
@@ -468,6 +468,12 @@ static void j2k_read_siz(opj_j2k_t *j2k) {
        }
 #endif /* USE_JPWL */
 
+  /* prevent division by zero */
+  if (!(cp->tdx * cp->tdy)) {
+    opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: invalid tile size (tdx: %d, tdy: %d)\n", cp->tdx, cp->tdy);
+    return;
+  }
+
        image->comps = (opj_image_comp_t*) opj_calloc(image->numcomps, sizeof(opj_image_comp_t));
        for (i = 0; i < image->numcomps; i++) {
                int tmp, w, h;
@@ -506,6 +512,12 @@ static void j2k_read_siz(opj_j2k_t *j2k) {
                }
 #endif /* USE_JPWL */
 
+    /* prevent division by zero */
+    if (!(image->comps[i].dx * image->comps[i].dy)) {
+      opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: invalid component size (dx: %d, dy: %d)\n", image->comps[i].dx, image->comps[i].dy);
+      return;
+    }
+
                /* TODO: unused ? */
                w = int_ceildiv(image->x1 - image->x0, image->comps[i].dx);
                h = int_ceildiv(image->y1 - image->y0, image->comps[i].dy);