shithub: jbig2

Download patch

ref: 06ddc496c3ea047ccb440e42adec7580317ff06d
parent: 4845d4cc36f6dc27ccc420eea0942d98157e89d3
author: Sebastian Rasmussen <[email protected]>
date: Sun Jul 1 13:26:21 EDT 2018

jbig2dec: Read region segment height/width/x/y as unsigned.

The specification in 5.4.4 states that numbers are unsigned unless
otherwise stated. 7.4.1.1 through 7.4.1.4 specifying the region segment
height, width, x and y do not mention that these fields are signed,
hence they ought to read and handled as unsigned.

--- a/jbig2_generic.c
+++ b/jbig2_generic.c
@@ -839,7 +839,7 @@
         return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "segment too short");
 
     jbig2_get_region_segment_info(&rsi, segment_data);
-    jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number, "generic region: %d x %d @ (%d, %d), flags = %02x", rsi.width, rsi.height, rsi.x, rsi.y, rsi.flags);
+    jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number, "generic region: %u x %u @ (%u, %u), flags = %02x", rsi.width, rsi.height, rsi.x, rsi.y, rsi.flags);
 
     /* 7.4.6.4 */
     height = rsi.height;
--- a/jbig2_halftone.c
+++ b/jbig2_halftone.c
@@ -575,7 +575,7 @@
     offset += 1;
 
     jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number,
-                "halftone region: %d x %d @ (%x,%d) flags=%02x", region_info.width, region_info.height, region_info.x, region_info.y, params.flags);
+                "halftone region: %u x %u @ (%u, %u), flags = %02x", region_info.width, region_info.height, region_info.x, region_info.y, params.flags);
 
     if (params.HMMR && params.HTEMPLATE) {
         jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "HTEMPLATE is %d when HMMR is %d, contrary to spec", params.HTEMPLATE, params.HMMR);
--- a/jbig2_page.c
+++ b/jbig2_page.c
@@ -258,7 +258,7 @@
  * is an image) to a page image buffer
  **/
 int
-jbig2_page_add_result(Jbig2Ctx *ctx, Jbig2Page *page, Jbig2Image *image, int x, int y, Jbig2ComposeOp op)
+jbig2_page_add_result(Jbig2Ctx *ctx, Jbig2Page *page, Jbig2Image *image, uint32_t x, uint32_t y, Jbig2ComposeOp op)
 {
     int code;
 
--- a/jbig2_page.h
+++ b/jbig2_page.h
@@ -48,6 +48,6 @@
 int jbig2_page_info(Jbig2Ctx *ctx, Jbig2Segment *segment, const uint8_t *segment_data);
 int jbig2_end_of_stripe(Jbig2Ctx *ctx, Jbig2Segment *segment, const uint8_t *segment_data);
 int jbig2_end_of_page(Jbig2Ctx *ctx, Jbig2Segment *segment, const uint8_t *segment_data);
-int jbig2_page_add_result(Jbig2Ctx *ctx, Jbig2Page *page, Jbig2Image *src, int x, int y, Jbig2ComposeOp op);
+int jbig2_page_add_result(Jbig2Ctx *ctx, Jbig2Page *page, Jbig2Image *src, uint32_t x, uint32_t y, Jbig2ComposeOp op);
 
 #endif /* _JBIG2_PAGE_H */
--- a/jbig2_refinement.c
+++ b/jbig2_refinement.c
@@ -432,7 +432,7 @@
         return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "segment too short");
 
     jbig2_get_region_segment_info(&rsi, segment_data);
-    jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number, "generic region: %d x %d @ (%d, %d), flags = %02x", rsi.width, rsi.height, rsi.x, rsi.y, rsi.flags);
+    jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number, "generic region: %u x %u @ (%u, %u), flags = %02x", rsi.width, rsi.height, rsi.x, rsi.y, rsi.flags);
 
     /* 7.4.7.2 */
     seg_flags = segment_data[17];
--- a/jbig2_segment.c
+++ b/jbig2_segment.c
@@ -196,10 +196,10 @@
 jbig2_get_region_segment_info(Jbig2RegionSegmentInfo *info, const uint8_t *segment_data)
 {
     /* 7.4.1 */
-    info->width = jbig2_get_int32(segment_data);
-    info->height = jbig2_get_int32(segment_data + 4);
-    info->x = jbig2_get_int32(segment_data + 8);
-    info->y = jbig2_get_int32(segment_data + 12);
+    info->width = jbig2_get_uint32(segment_data);
+    info->height = jbig2_get_uint32(segment_data + 4);
+    info->x = jbig2_get_uint32(segment_data + 8);
+    info->y = jbig2_get_uint32(segment_data + 12);
     info->flags = segment_data[16];
     info->op = (Jbig2ComposeOp)(info->flags & 0x7);
 }
--- a/jbig2_segment.h
+++ b/jbig2_segment.h
@@ -41,10 +41,10 @@
 /* region segment info */
 
 typedef struct {
-    int32_t width;
-    int32_t height;
-    int32_t x;
-    int32_t y;
+    uint32_t width;
+    uint32_t height;
+    uint32_t x;
+    uint32_t y;
     Jbig2ComposeOp op;
     uint8_t flags;
 } Jbig2RegionSegmentInfo;