diff options
-rw-r--r-- | base/sjbig2.c | 4 | ||||
-rw-r--r-- | gpdl/jbig2top.c | 2 | ||||
-rw-r--r-- | jbig2dec/jbig2.c | 40 | ||||
-rw-r--r-- | jbig2dec/jbig2.h | 3 | ||||
-rw-r--r-- | jbig2dec/jbig2_arith.c | 28 | ||||
-rw-r--r-- | jbig2dec/jbig2_arith_iaid.c | 8 | ||||
-rw-r--r-- | jbig2dec/jbig2_arith_int.c | 16 | ||||
-rw-r--r-- | jbig2dec/jbig2_halftone.c | 10 | ||||
-rw-r--r-- | jbig2dec/jbig2_huffman.c | 34 | ||||
-rw-r--r-- | jbig2dec/jbig2_image.c | 22 | ||||
-rw-r--r-- | jbig2dec/jbig2_mmr.c | 36 | ||||
-rw-r--r-- | jbig2dec/jbig2_page.c | 22 | ||||
-rw-r--r-- | jbig2dec/jbig2_priv.h | 2 | ||||
-rw-r--r-- | jbig2dec/jbig2_refinement.c | 8 | ||||
-rw-r--r-- | jbig2dec/jbig2_segment.c | 7 | ||||
-rw-r--r-- | jbig2dec/jbig2_symbol_dict.c | 6 | ||||
-rw-r--r-- | jbig2dec/jbig2dec.c | 14 |
17 files changed, 134 insertions, 128 deletions
diff --git a/base/sjbig2.c b/base/sjbig2.c index 6a573d6cb..490df7c65 100644 --- a/base/sjbig2.c +++ b/base/sjbig2.c | |||
@@ -42,7 +42,7 @@ private_st_jbig2decode_state(); /* creates a gc object for our state, defined in | |||
42 | /* error callback for jbig2 decoder */ | 42 | /* error callback for jbig2 decoder */ |
43 | static void | 43 | static void |
44 | s_jbig2decode_error(void *callback_data, const char *msg, Jbig2Severity severity, | 44 | s_jbig2decode_error(void *callback_data, const char *msg, Jbig2Severity severity, |
45 | int32_t seg_idx) | 45 | uint32_t seg_idx) |
46 | { | 46 | { |
47 | s_jbig2_callback_data_t *error_data = (s_jbig2_callback_data_t *)callback_data; | 47 | s_jbig2_callback_data_t *error_data = (s_jbig2_callback_data_t *)callback_data; |
48 | const char *type; | 48 | const char *type; |
@@ -62,7 +62,7 @@ s_jbig2decode_error(void *callback_data, const char *msg, Jbig2Severity severity | |||
62 | break;; | 62 | break;; |
63 | default: type = "unknown message:"; break;; | 63 | default: type = "unknown message:"; break;; |
64 | } | 64 | } |
65 | if (seg_idx == -1) segment[0] = '\0'; | 65 | if (seg_idx == JBIG2_UNKNOWN_SEGMENT_NUMBER) segment[0] = '\0'; |
66 | else gs_sprintf(segment, "(segment 0x%02x)", seg_idx); | 66 | else gs_sprintf(segment, "(segment 0x%02x)", seg_idx); |
67 | 67 | ||
68 | if (error_data) | 68 | if (error_data) |
diff --git a/gpdl/jbig2top.c b/gpdl/jbig2top.c index 4f872215f..a668e1b30 100644 --- a/gpdl/jbig2top.c +++ b/gpdl/jbig2top.c | |||
@@ -370,7 +370,7 @@ static JB2_Error JB2_Callback my_output(unsigned char *buffer, | |||
370 | } | 370 | } |
371 | 371 | ||
372 | #else | 372 | #else |
373 | static void my_errors(void *data, const char *msg, Jbig2Severity severity, int32_t seg_idx) | 373 | static void my_errors(void *data, const char *msg, Jbig2Severity severity, uint32_t seg_idx) |
374 | { | 374 | { |
375 | /* Do nothing */ | 375 | /* Do nothing */ |
376 | } | 376 | } |
diff --git a/jbig2dec/jbig2.c b/jbig2dec/jbig2.c index 1ea68df41..126e7a9ba 100644 --- a/jbig2dec/jbig2.c +++ b/jbig2dec/jbig2.c | |||
@@ -71,12 +71,12 @@ jbig2_alloc(Jbig2Allocator *allocator, size_t size, size_t num) | |||
71 | /* jbig2_free and jbig2_realloc moved to the bottom of this file */ | 71 | /* jbig2_free and jbig2_realloc moved to the bottom of this file */ |
72 | 72 | ||
73 | static void | 73 | static void |
74 | jbig2_default_error(void *data, const char *msg, Jbig2Severity severity, int32_t seg_idx) | 74 | jbig2_default_error(void *data, const char *msg, Jbig2Severity severity, uint32_t seg_idx) |
75 | { | 75 | { |
76 | /* report only fatal errors by default */ | 76 | /* report only fatal errors by default */ |
77 | if (severity == JBIG2_SEVERITY_FATAL) { | 77 | if (severity == JBIG2_SEVERITY_FATAL) { |
78 | fprintf(stderr, "jbig2 decoder FATAL ERROR: %s", msg); | 78 | fprintf(stderr, "jbig2 decoder FATAL ERROR: %s", msg); |
79 | if (seg_idx != -1) | 79 | if (seg_idx != JBIG2_UNKNOWN_SEGMENT_NUMBER) |
80 | fprintf(stderr, " (segment 0x%02x)", seg_idx); | 80 | fprintf(stderr, " (segment 0x%02x)", seg_idx); |
81 | fprintf(stderr, "\n"); | 81 | fprintf(stderr, "\n"); |
82 | fflush(stderr); | 82 | fflush(stderr); |
@@ -84,7 +84,7 @@ jbig2_default_error(void *data, const char *msg, Jbig2Severity severity, int32_t | |||
84 | } | 84 | } |
85 | 85 | ||
86 | int | 86 | int |
87 | jbig2_error(Jbig2Ctx *ctx, Jbig2Severity severity, int32_t segment_number, const char *fmt, ...) | 87 | jbig2_error(Jbig2Ctx *ctx, Jbig2Severity severity, uint32_t segment_number, const char *fmt, ...) |
88 | { | 88 | { |
89 | char buf[1024]; | 89 | char buf[1024]; |
90 | va_list ap; | 90 | va_list ap; |
@@ -108,7 +108,7 @@ jbig2_ctx_new_imp(Jbig2Allocator *allocator, Jbig2Options options, Jbig2GlobalCt | |||
108 | Jbig2Ctx fakectx; | 108 | Jbig2Ctx fakectx; |
109 | fakectx.error_callback = error_callback; | 109 | fakectx.error_callback = error_callback; |
110 | fakectx.error_callback_data = error_callback_data; | 110 | fakectx.error_callback_data = error_callback_data; |
111 | jbig2_error(&fakectx, JBIG2_SEVERITY_FATAL, -1, "incompatible jbig2dec header (%d.%d) and library (%d.%d) versions", | 111 | jbig2_error(&fakectx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "incompatible jbig2dec header (%d.%d) and library (%d.%d) versions", |
112 | jbig2_version_major, jbig2_version_minor, JBIG2_VERSION_MAJOR, JBIG2_VERSION_MINOR); | 112 | jbig2_version_major, jbig2_version_minor, JBIG2_VERSION_MAJOR, JBIG2_VERSION_MINOR); |
113 | return NULL; | 113 | return NULL; |
114 | } | 114 | } |
@@ -120,7 +120,7 @@ jbig2_ctx_new_imp(Jbig2Allocator *allocator, Jbig2Options options, Jbig2GlobalCt | |||
120 | 120 | ||
121 | result = (Jbig2Ctx *) jbig2_alloc(allocator, sizeof(Jbig2Ctx), 1); | 121 | result = (Jbig2Ctx *) jbig2_alloc(allocator, sizeof(Jbig2Ctx), 1); |
122 | if (result == NULL) { | 122 | if (result == NULL) { |
123 | error_callback(error_callback_data, "failed to allocate initial context", JBIG2_SEVERITY_FATAL, -1); | 123 | error_callback(error_callback_data, "failed to allocate initial context", JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER); |
124 | return NULL; | 124 | return NULL; |
125 | } | 125 | } |
126 | 126 | ||
@@ -138,7 +138,7 @@ jbig2_ctx_new_imp(Jbig2Allocator *allocator, Jbig2Options options, Jbig2GlobalCt | |||
138 | result->n_segments_max = 16; | 138 | result->n_segments_max = 16; |
139 | result->segments = jbig2_new(result, Jbig2Segment *, result->n_segments_max); | 139 | result->segments = jbig2_new(result, Jbig2Segment *, result->n_segments_max); |
140 | if (result->segments == NULL) { | 140 | if (result->segments == NULL) { |
141 | error_callback(error_callback_data, "failed to allocate initial segments", JBIG2_SEVERITY_FATAL, -1); | 141 | error_callback(error_callback_data, "failed to allocate initial segments", JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER); |
142 | jbig2_free(allocator, result); | 142 | jbig2_free(allocator, result); |
143 | return NULL; | 143 | return NULL; |
144 | } | 144 | } |
@@ -148,7 +148,7 @@ jbig2_ctx_new_imp(Jbig2Allocator *allocator, Jbig2Options options, Jbig2GlobalCt | |||
148 | result->max_page_index = 4; | 148 | result->max_page_index = 4; |
149 | result->pages = jbig2_new(result, Jbig2Page, result->max_page_index); | 149 | result->pages = jbig2_new(result, Jbig2Page, result->max_page_index); |
150 | if (result->pages == NULL) { | 150 | if (result->pages == NULL) { |
151 | error_callback(error_callback_data, "failed to allocated initial pages", JBIG2_SEVERITY_FATAL, -1); | 151 | error_callback(error_callback_data, "failed to allocated initial pages", JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER); |
152 | jbig2_free(allocator, result->segments); | 152 | jbig2_free(allocator, result->segments); |
153 | jbig2_free(allocator, result); | 153 | jbig2_free(allocator, result); |
154 | return NULL; | 154 | return NULL; |
@@ -236,7 +236,7 @@ jbig2_data_in(Jbig2Ctx *ctx, const unsigned char *data, size_t size) | |||
236 | while (buf_size < size); | 236 | while (buf_size < size); |
237 | ctx->buf = jbig2_new(ctx, byte, buf_size); | 237 | ctx->buf = jbig2_new(ctx, byte, buf_size); |
238 | if (ctx->buf == NULL) { | 238 | if (ctx->buf == NULL) { |
239 | return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate buffer when reading data"); | 239 | return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to allocate buffer when reading data"); |
240 | } | 240 | } |
241 | ctx->buf_size = buf_size; | 241 | ctx->buf_size = buf_size; |
242 | ctx->buf_rd_ix = 0; | 242 | ctx->buf_rd_ix = 0; |
@@ -253,7 +253,7 @@ jbig2_data_in(Jbig2Ctx *ctx, const unsigned char *data, size_t size) | |||
253 | while (buf_size < ctx->buf_wr_ix - ctx->buf_rd_ix + size); | 253 | while (buf_size < ctx->buf_wr_ix - ctx->buf_rd_ix + size); |
254 | buf = jbig2_new(ctx, byte, buf_size); | 254 | buf = jbig2_new(ctx, byte, buf_size); |
255 | if (buf == NULL) { | 255 | if (buf == NULL) { |
256 | return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate bigger buffer when reading data"); | 256 | return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to allocate bigger buffer when reading data"); |
257 | } | 257 | } |
258 | memcpy(buf, ctx->buf + ctx->buf_rd_ix, ctx->buf_wr_ix - ctx->buf_rd_ix); | 258 | memcpy(buf, ctx->buf + ctx->buf_rd_ix, ctx->buf_wr_ix - ctx->buf_rd_ix); |
259 | jbig2_free(ctx->allocator, ctx->buf); | 259 | jbig2_free(ctx->allocator, ctx->buf); |
@@ -280,17 +280,17 @@ jbig2_data_in(Jbig2Ctx *ctx, const unsigned char *data, size_t size) | |||
280 | if (ctx->buf_wr_ix - ctx->buf_rd_ix < 9) | 280 | if (ctx->buf_wr_ix - ctx->buf_rd_ix < 9) |
281 | return 0; | 281 | return 0; |
282 | if (memcmp(ctx->buf + ctx->buf_rd_ix, jbig2_id_string, 8)) | 282 | if (memcmp(ctx->buf + ctx->buf_rd_ix, jbig2_id_string, 8)) |
283 | return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "not a JBIG2 file header"); | 283 | return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "not a JBIG2 file header"); |
284 | /* D.4.2 */ | 284 | /* D.4.2 */ |
285 | ctx->file_header_flags = ctx->buf[ctx->buf_rd_ix + 8]; | 285 | ctx->file_header_flags = ctx->buf[ctx->buf_rd_ix + 8]; |
286 | /* Check for T.88 amendment 2 */ | 286 | /* Check for T.88 amendment 2 */ |
287 | if (ctx->file_header_flags & 0x04) | 287 | if (ctx->file_header_flags & 0x04) |
288 | return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "file header indicates use of 12 adaptive template pixels (NYI)"); | 288 | return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "file header indicates use of 12 adaptive template pixels (NYI)"); |
289 | /* Check for T.88 amendment 3 */ | 289 | /* Check for T.88 amendment 3 */ |
290 | if (ctx->file_header_flags & 0x08) | 290 | if (ctx->file_header_flags & 0x08) |
291 | return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "file header indicates use of colored region segments (NYI)"); | 291 | return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "file header indicates use of colored region segments (NYI)"); |
292 | if (ctx->file_header_flags & 0xFC) { | 292 | if (ctx->file_header_flags & 0xFC) { |
293 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "reserved bits (2-7) of file header flags are not zero (0x%02x)", ctx->file_header_flags); | 293 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "reserved bits (2-7) of file header flags are not zero (0x%02x)", ctx->file_header_flags); |
294 | } | 294 | } |
295 | /* D.4.3 */ | 295 | /* D.4.3 */ |
296 | if (!(ctx->file_header_flags & 2)) { /* number of pages is known */ | 296 | if (!(ctx->file_header_flags & 2)) { /* number of pages is known */ |
@@ -299,9 +299,9 @@ jbig2_data_in(Jbig2Ctx *ctx, const unsigned char *data, size_t size) | |||
299 | ctx->n_pages = jbig2_get_uint32(ctx->buf + ctx->buf_rd_ix + 9); | 299 | ctx->n_pages = jbig2_get_uint32(ctx->buf + ctx->buf_rd_ix + 9); |
300 | ctx->buf_rd_ix += 13; | 300 | ctx->buf_rd_ix += 13; |
301 | if (ctx->n_pages == 1) | 301 | if (ctx->n_pages == 1) |
302 | jbig2_error(ctx, JBIG2_SEVERITY_INFO, -1, "file header indicates a single page document"); | 302 | jbig2_error(ctx, JBIG2_SEVERITY_INFO, JBIG2_UNKNOWN_SEGMENT_NUMBER, "file header indicates a single page document"); |
303 | else | 303 | else |
304 | jbig2_error(ctx, JBIG2_SEVERITY_INFO, -1, "file header indicates a %d page document", ctx->n_pages); | 304 | jbig2_error(ctx, JBIG2_SEVERITY_INFO, JBIG2_UNKNOWN_SEGMENT_NUMBER, "file header indicates a %d page document", ctx->n_pages); |
305 | } else { /* number of pages not known */ | 305 | } else { /* number of pages not known */ |
306 | ctx->n_pages = 0; | 306 | ctx->n_pages = 0; |
307 | ctx->buf_rd_ix += 9; | 307 | ctx->buf_rd_ix += 9; |
@@ -309,10 +309,10 @@ jbig2_data_in(Jbig2Ctx *ctx, const unsigned char *data, size_t size) | |||
309 | /* determine the file organization based on the flags - D.4.2 again */ | 309 | /* determine the file organization based on the flags - D.4.2 again */ |
310 | if (ctx->file_header_flags & 1) { | 310 | if (ctx->file_header_flags & 1) { |
311 | ctx->state = JBIG2_FILE_SEQUENTIAL_HEADER; | 311 | ctx->state = JBIG2_FILE_SEQUENTIAL_HEADER; |
312 | jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, -1, "file header indicates sequential organization"); | 312 | jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, JBIG2_UNKNOWN_SEGMENT_NUMBER, "file header indicates sequential organization"); |
313 | } else { | 313 | } else { |
314 | ctx->state = JBIG2_FILE_RANDOM_HEADERS; | 314 | ctx->state = JBIG2_FILE_RANDOM_HEADERS; |
315 | jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, -1, "file header indicates random-access organization"); | 315 | jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, JBIG2_UNKNOWN_SEGMENT_NUMBER, "file header indicates random-access organization"); |
316 | } | 316 | } |
317 | break; | 317 | break; |
318 | case JBIG2_FILE_SEQUENTIAL_HEADER: | 318 | case JBIG2_FILE_SEQUENTIAL_HEADER: |
@@ -403,7 +403,7 @@ jbig2_data_in(Jbig2Ctx *ctx, const unsigned char *data, size_t size) | |||
403 | case JBIG2_FILE_EOF: | 403 | case JBIG2_FILE_EOF: |
404 | if (ctx->buf_rd_ix == ctx->buf_wr_ix) | 404 | if (ctx->buf_rd_ix == ctx->buf_wr_ix) |
405 | return 0; | 405 | return 0; |
406 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "garbage beyond end of file"); | 406 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "garbage beyond end of file"); |
407 | } | 407 | } |
408 | } | 408 | } |
409 | } | 409 | } |
@@ -468,7 +468,7 @@ jbig2_word_stream_buf_get_next_word(Jbig2Ctx *ctx, Jbig2WordStream *self, size_t | |||
468 | int ret = 0; | 468 | int ret = 0; |
469 | 469 | ||
470 | if (self == NULL || word == NULL) { | 470 | if (self == NULL || word == NULL) { |
471 | return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to read next word of stream because stream or output missing"); | 471 | return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to read next word of stream because stream or output missing"); |
472 | } | 472 | } |
473 | if (offset >= z->size) { | 473 | if (offset >= z->size) { |
474 | *word = 0; | 474 | *word = 0; |
@@ -501,7 +501,7 @@ jbig2_word_stream_buf_new(Jbig2Ctx *ctx, const byte *data, size_t size) | |||
501 | Jbig2WordStreamBuf *result = jbig2_new(ctx, Jbig2WordStreamBuf, 1); | 501 | Jbig2WordStreamBuf *result = jbig2_new(ctx, Jbig2WordStreamBuf, 1); |
502 | 502 | ||
503 | if (result == NULL) { | 503 | if (result == NULL) { |
504 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate word stream"); | 504 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to allocate word stream"); |
505 | return NULL; | 505 | return NULL; |
506 | } | 506 | } |
507 | 507 | ||
diff --git a/jbig2dec/jbig2.h b/jbig2dec/jbig2.h index fb195fec4..abd7cb6b4 100644 --- a/jbig2dec/jbig2.h +++ b/jbig2dec/jbig2.h | |||
@@ -65,7 +65,8 @@ struct _Jbig2Image { | |||
65 | handler is used which prints fatal errors to the stderr stream. */ | 65 | handler is used which prints fatal errors to the stderr stream. */ |
66 | 66 | ||
67 | /* error callback */ | 67 | /* error callback */ |
68 | typedef void (*Jbig2ErrorCallback)(void *data, const char *msg, Jbig2Severity severity, int32_t seg_idx); | 68 | #define JBIG2_UNKNOWN_SEGMENT_NUMBER ~0U |
69 | typedef void (*Jbig2ErrorCallback)(void *data, const char *msg, Jbig2Severity severity, uint32_t seg_idx); | ||
69 | 70 | ||
70 | /* memory allocation is likewise done via a set of callbacks so that | 71 | /* memory allocation is likewise done via a set of callbacks so that |
71 | clients can better control memory usage. If a NULL is passed for | 72 | clients can better control memory usage. If a NULL is passed for |
diff --git a/jbig2dec/jbig2_arith.c b/jbig2dec/jbig2_arith.c index 116c55c3d..efda89793 100644 --- a/jbig2dec/jbig2_arith.c +++ b/jbig2dec/jbig2_arith.c | |||
@@ -60,11 +60,11 @@ jbig2_arith_bytein(Jbig2Ctx *ctx, Jbig2ArithState *as) | |||
60 | 60 | ||
61 | /* Treat both errors and reading beyond end of stream as an error. */ | 61 | /* Treat both errors and reading beyond end of stream as an error. */ |
62 | if (as->next_word_bytes < 0) { | 62 | if (as->next_word_bytes < 0) { |
63 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to read from underlying stream during arithmetic decoding"); | 63 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to read from underlying stream during arithmetic decoding"); |
64 | return -1; | 64 | return -1; |
65 | } | 65 | } |
66 | if (as->next_word_bytes == 0) { | 66 | if (as->next_word_bytes == 0) { |
67 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to read beyond end of underlying stream during arithmetic decoding"); | 67 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to read beyond end of underlying stream during arithmetic decoding"); |
68 | return -1; | 68 | return -1; |
69 | } | 69 | } |
70 | 70 | ||
@@ -96,10 +96,10 @@ jbig2_arith_bytein(Jbig2Ctx *ctx, Jbig2ArithState *as) | |||
96 | if (as->next_word_bytes <= 1) { | 96 | if (as->next_word_bytes <= 1) { |
97 | as->next_word_bytes = as->ws->get_next_word(ctx, as->ws, as->offset, &as->next_word); | 97 | as->next_word_bytes = as->ws->get_next_word(ctx, as->ws, as->offset, &as->next_word); |
98 | if (as->next_word_bytes < 0) { | 98 | if (as->next_word_bytes < 0) { |
99 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to check for marker code due to failure in underlying stream during arithmetic decoding"); | 99 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to check for marker code due to failure in underlying stream during arithmetic decoding"); |
100 | } | 100 | } |
101 | if (as->next_word_bytes == 0) { | 101 | if (as->next_word_bytes == 0) { |
102 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to read end of possible terminating marker code, assuming terminating marker code"); | 102 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to read end of possible terminating marker code, assuming terminating marker code"); |
103 | as->next_word = 0xFF900000; | 103 | as->next_word = 0xFF900000; |
104 | as->next_word_bytes = 2; | 104 | as->next_word_bytes = 2; |
105 | as->C += 0xFF00; | 105 | as->C += 0xFF00; |
@@ -153,10 +153,10 @@ jbig2_arith_bytein(Jbig2Ctx *ctx, Jbig2ArithState *as) | |||
153 | if (as->next_word_bytes == 0) { | 153 | if (as->next_word_bytes == 0) { |
154 | as->next_word_bytes = as->ws->get_next_word(ctx, as->ws, as->offset, &as->next_word); | 154 | as->next_word_bytes = as->ws->get_next_word(ctx, as->ws, as->offset, &as->next_word); |
155 | if (as->next_word_bytes < 0) { | 155 | if (as->next_word_bytes < 0) { |
156 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to read from underlying stream during arithmetic decoding"); | 156 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to read from underlying stream during arithmetic decoding"); |
157 | } | 157 | } |
158 | if (as->next_word_bytes == 0) { | 158 | if (as->next_word_bytes == 0) { |
159 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to find terminating marker code before end of underlying stream, assuming terminating marker code"); | 159 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to find terminating marker code before end of underlying stream, assuming terminating marker code"); |
160 | as->next_word = 0xFF900000; | 160 | as->next_word = 0xFF900000; |
161 | as->next_word_bytes = 2; | 161 | as->next_word_bytes = 2; |
162 | as->C += 0xFF00; | 162 | as->C += 0xFF00; |
@@ -186,7 +186,7 @@ jbig2_arith_new(Jbig2Ctx *ctx, Jbig2WordStream *ws) | |||
186 | 186 | ||
187 | result = jbig2_new(ctx, Jbig2ArithState, 1); | 187 | result = jbig2_new(ctx, Jbig2ArithState, 1); |
188 | if (result == NULL) { | 188 | if (result == NULL) { |
189 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate arithmetic coding state"); | 189 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to allocate arithmetic coding state"); |
190 | return NULL; | 190 | return NULL; |
191 | } | 191 | } |
192 | 192 | ||
@@ -196,12 +196,12 @@ jbig2_arith_new(Jbig2Ctx *ctx, Jbig2WordStream *ws) | |||
196 | result->next_word_bytes = result->ws->get_next_word(ctx, result->ws, result->offset, &result->next_word); | 196 | result->next_word_bytes = result->ws->get_next_word(ctx, result->ws, result->offset, &result->next_word); |
197 | if (result->next_word_bytes < 0) { | 197 | if (result->next_word_bytes < 0) { |
198 | jbig2_free(ctx->allocator, result); | 198 | jbig2_free(ctx->allocator, result); |
199 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to initialize underlying stream of arithmetic decoder"); | 199 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to initialize underlying stream of arithmetic decoder"); |
200 | return NULL; | 200 | return NULL; |
201 | } | 201 | } |
202 | if (result->next_word_bytes == 0) { | 202 | if (result->next_word_bytes == 0) { |
203 | jbig2_free(ctx->allocator, result); | 203 | jbig2_free(ctx->allocator, result); |
204 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to read first byte from underlying stream when initializing arithmetic decoder"); | 204 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to read first byte from underlying stream when initializing arithmetic decoder"); |
205 | return NULL; | 205 | return NULL; |
206 | } | 206 | } |
207 | result->offset += result->next_word_bytes; | 207 | result->offset += result->next_word_bytes; |
@@ -212,7 +212,7 @@ jbig2_arith_new(Jbig2Ctx *ctx, Jbig2WordStream *ws) | |||
212 | /* Figure E.20 (2) */ | 212 | /* Figure E.20 (2) */ |
213 | if (jbig2_arith_bytein(ctx, result) < 0) { | 213 | if (jbig2_arith_bytein(ctx, result) < 0) { |
214 | jbig2_free(ctx->allocator, result); | 214 | jbig2_free(ctx->allocator, result); |
215 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to read second byte from underlying stream when initializing arithmetic decoder"); | 215 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to read second byte from underlying stream when initializing arithmetic decoder"); |
216 | return NULL; | 216 | return NULL; |
217 | } | 217 | } |
218 | 218 | ||
@@ -289,7 +289,7 @@ jbig2_arith_renormd(Jbig2Ctx *ctx, Jbig2ArithState *as) | |||
289 | /* Figure E.18 */ | 289 | /* Figure E.18 */ |
290 | do { | 290 | do { |
291 | if (as->CT == 0 && jbig2_arith_bytein(ctx, as) < 0) { | 291 | if (as->CT == 0 && jbig2_arith_bytein(ctx, as) < 0) { |
292 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to read byte from compressed data stream"); | 292 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to read byte from compressed data stream"); |
293 | } | 293 | } |
294 | as->A <<= 1; | 294 | as->A <<= 1; |
295 | as->C <<= 1; | 295 | as->C <<= 1; |
@@ -308,7 +308,7 @@ jbig2_arith_decode(Jbig2Ctx *ctx, Jbig2ArithState *as, Jbig2ArithCx *pcx) | |||
308 | bool D; | 308 | bool D; |
309 | 309 | ||
310 | if (index >= MAX_QE_ARRAY_SIZE) { | 310 | if (index >= MAX_QE_ARRAY_SIZE) { |
311 | return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to determine probability estimate because index out of range"); | 311 | return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to determine probability estimate because index out of range"); |
312 | } | 312 | } |
313 | 313 | ||
314 | pqe = &jbig2_arith_Qe[index]; | 314 | pqe = &jbig2_arith_Qe[index]; |
@@ -326,7 +326,7 @@ jbig2_arith_decode(Jbig2Ctx *ctx, Jbig2ArithState *as, Jbig2ArithCx *pcx) | |||
326 | *pcx ^= pqe->mps_xor; | 326 | *pcx ^= pqe->mps_xor; |
327 | } | 327 | } |
328 | if (jbig2_arith_renormd(ctx, as) < 0) { | 328 | if (jbig2_arith_renormd(ctx, as) < 0) { |
329 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to renormalize decoder"); | 329 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to renormalize decoder"); |
330 | } | 330 | } |
331 | 331 | ||
332 | return D; | 332 | return D; |
@@ -346,7 +346,7 @@ jbig2_arith_decode(Jbig2Ctx *ctx, Jbig2ArithState *as, Jbig2ArithCx *pcx) | |||
346 | *pcx ^= pqe->lps_xor; | 346 | *pcx ^= pqe->lps_xor; |
347 | } | 347 | } |
348 | if (jbig2_arith_renormd(ctx, as) < 0) { | 348 | if (jbig2_arith_renormd(ctx, as) < 0) { |
349 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to renormalize decoder"); | 349 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to renormalize decoder"); |
350 | } | 350 | } |
351 | 351 | ||
352 | return D; | 352 | return D; |
diff --git a/jbig2dec/jbig2_arith_iaid.c b/jbig2dec/jbig2_arith_iaid.c index 11358349d..1baedcfc3 100644 --- a/jbig2dec/jbig2_arith_iaid.c +++ b/jbig2dec/jbig2_arith_iaid.c | |||
@@ -49,7 +49,7 @@ jbig2_arith_iaid_ctx_new(Jbig2Ctx *ctx, uint8_t SBSYMCODELEN) | |||
49 | 49 | ||
50 | if (sizeof(ctx_size) * 8 <= SBSYMCODELEN) | 50 | if (sizeof(ctx_size) * 8 <= SBSYMCODELEN) |
51 | { | 51 | { |
52 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "requested IAID arithmetic coding state size too large"); | 52 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "requested IAID arithmetic coding state size too large"); |
53 | return NULL; | 53 | return NULL; |
54 | } | 54 | } |
55 | 55 | ||
@@ -57,7 +57,7 @@ jbig2_arith_iaid_ctx_new(Jbig2Ctx *ctx, uint8_t SBSYMCODELEN) | |||
57 | 57 | ||
58 | result = jbig2_new(ctx, Jbig2ArithIaidCtx, 1); | 58 | result = jbig2_new(ctx, Jbig2ArithIaidCtx, 1); |
59 | if (result == NULL) { | 59 | if (result == NULL) { |
60 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate IAID arithmetic coding state"); | 60 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to allocate IAID arithmetic coding state"); |
61 | return NULL; | 61 | return NULL; |
62 | } | 62 | } |
63 | 63 | ||
@@ -66,7 +66,7 @@ jbig2_arith_iaid_ctx_new(Jbig2Ctx *ctx, uint8_t SBSYMCODELEN) | |||
66 | if (result->IAIDx == NULL) | 66 | if (result->IAIDx == NULL) |
67 | { | 67 | { |
68 | jbig2_free(ctx->allocator, result); | 68 | jbig2_free(ctx->allocator, result); |
69 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate symbol ID in IAID arithmetic coding state"); | 69 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to allocate symbol ID in IAID arithmetic coding state"); |
70 | return NULL; | 70 | return NULL; |
71 | } | 71 | } |
72 | 72 | ||
@@ -90,7 +90,7 @@ jbig2_arith_iaid_decode(Jbig2Ctx *ctx, Jbig2ArithIaidCtx *actx, Jbig2ArithState | |||
90 | for (i = 0; i < SBSYMCODELEN; i++) { | 90 | for (i = 0; i < SBSYMCODELEN; i++) { |
91 | D = jbig2_arith_decode(ctx, as, &IAIDx[PREV]); | 91 | D = jbig2_arith_decode(ctx, as, &IAIDx[PREV]); |
92 | if (D < 0) | 92 | if (D < 0) |
93 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to decode IAIDx code"); | 93 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to decode IAIDx code"); |
94 | #ifdef VERBOSE | 94 | #ifdef VERBOSE |
95 | fprintf(stderr, "IAID%x: D = %d\n", PREV, D); | 95 | fprintf(stderr, "IAID%x: D = %d\n", PREV, D); |
96 | #endif | 96 | #endif |
diff --git a/jbig2dec/jbig2_arith_int.c b/jbig2dec/jbig2_arith_int.c index 20b62dfcc..71024fa9d 100644 --- a/jbig2dec/jbig2_arith_int.c +++ b/jbig2dec/jbig2_arith_int.c | |||
@@ -42,7 +42,7 @@ jbig2_arith_int_ctx_new(Jbig2Ctx *ctx) | |||
42 | Jbig2ArithIntCtx *result = jbig2_new(ctx, Jbig2ArithIntCtx, 1); | 42 | Jbig2ArithIntCtx *result = jbig2_new(ctx, Jbig2ArithIntCtx, 1); |
43 | 43 | ||
44 | if (result == NULL) { | 44 | if (result == NULL) { |
45 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate arithmetic integer coding state"); | 45 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to allocate arithmetic integer coding state"); |
46 | return NULL; | 46 | return NULL; |
47 | } else { | 47 | } else { |
48 | memset(result->IAx, 0, sizeof(result->IAx)); | 48 | memset(result->IAx, 0, sizeof(result->IAx)); |
@@ -66,35 +66,35 @@ jbig2_arith_int_decode(Jbig2Ctx *ctx, Jbig2ArithIntCtx *actx, Jbig2ArithState *a | |||
66 | 66 | ||
67 | S = jbig2_arith_decode(ctx, as, &IAx[PREV]); | 67 | S = jbig2_arith_decode(ctx, as, &IAx[PREV]); |
68 | if (S < 0) | 68 | if (S < 0) |
69 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to decode IAx S"); | 69 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to decode IAx S"); |
70 | PREV = (PREV << 1) | S; | 70 | PREV = (PREV << 1) | S; |
71 | 71 | ||
72 | bit = jbig2_arith_decode(ctx, as, &IAx[PREV]); | 72 | bit = jbig2_arith_decode(ctx, as, &IAx[PREV]); |
73 | if (bit < 0) | 73 | if (bit < 0) |
74 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to decode IAx decision bit 0"); | 74 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to decode IAx decision bit 0"); |
75 | PREV = (PREV << 1) | bit; | 75 | PREV = (PREV << 1) | bit; |
76 | if (bit) { | 76 | if (bit) { |
77 | bit = jbig2_arith_decode(ctx, as, &IAx[PREV]); | 77 | bit = jbig2_arith_decode(ctx, as, &IAx[PREV]); |
78 | if (bit < 0) | 78 | if (bit < 0) |
79 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to decode IAx decision bit 1"); | 79 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to decode IAx decision bit 1"); |
80 | PREV = (PREV << 1) | bit; | 80 | PREV = (PREV << 1) | bit; |
81 | 81 | ||
82 | if (bit) { | 82 | if (bit) { |
83 | bit = jbig2_arith_decode(ctx, as, &IAx[PREV]); | 83 | bit = jbig2_arith_decode(ctx, as, &IAx[PREV]); |
84 | if (bit < 0) | 84 | if (bit < 0) |
85 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to decode IAx decision bit 2"); | 85 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to decode IAx decision bit 2"); |
86 | PREV = (PREV << 1) | bit; | 86 | PREV = (PREV << 1) | bit; |
87 | 87 | ||
88 | if (bit) { | 88 | if (bit) { |
89 | bit = jbig2_arith_decode(ctx, as, &IAx[PREV]); | 89 | bit = jbig2_arith_decode(ctx, as, &IAx[PREV]); |
90 | if (bit < 0) | 90 | if (bit < 0) |
91 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to decode IAx decision bit 3"); | 91 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to decode IAx decision bit 3"); |
92 | PREV = (PREV << 1) | bit; | 92 | PREV = (PREV << 1) | bit; |
93 | 93 | ||
94 | if (bit) { | 94 | if (bit) { |
95 | bit = jbig2_arith_decode(ctx, as, &IAx[PREV]); | 95 | bit = jbig2_arith_decode(ctx, as, &IAx[PREV]); |
96 | if (bit < 0) | 96 | if (bit < 0) |
97 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to decode IAx decision bit 4"); | 97 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to decode IAx decision bit 4"); |
98 | PREV = (PREV << 1) | bit; | 98 | PREV = (PREV << 1) | bit; |
99 | 99 | ||
100 | if (bit) { | 100 | if (bit) { |
@@ -125,7 +125,7 @@ jbig2_arith_int_decode(Jbig2Ctx *ctx, Jbig2ArithIntCtx *actx, Jbig2ArithState *a | |||
125 | for (i = 0; i < n_tail; i++) { | 125 | for (i = 0; i < n_tail; i++) { |
126 | bit = jbig2_arith_decode(ctx, as, &IAx[PREV]); | 126 | bit = jbig2_arith_decode(ctx, as, &IAx[PREV]); |
127 | if (bit < 0) | 127 | if (bit < 0) |
128 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to decode IAx V bit %d", i); | 128 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to decode IAx V bit %d", i); |
129 | PREV = ((PREV << 1) & 511) | (PREV & 256) | bit; | 129 | PREV = ((PREV << 1) & 511) | (PREV & 256) | bit; |
130 | V = (V << 1) | bit; | 130 | V = (V << 1) | bit; |
131 | } | 131 | } |
diff --git a/jbig2dec/jbig2_halftone.c b/jbig2dec/jbig2_halftone.c index b2b7bdbcb..c33f74b1d 100644 --- a/jbig2dec/jbig2_halftone.c +++ b/jbig2dec/jbig2_halftone.c | |||
@@ -51,7 +51,7 @@ jbig2_hd_new(Jbig2Ctx *ctx, const Jbig2PatternDictParams *params, Jbig2Image *im | |||
51 | 51 | ||
52 | if (N == 0) { | 52 | if (N == 0) { |
53 | /* We've wrapped. */ | 53 | /* We've wrapped. */ |
54 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "params->GRAYMAX out of range"); | 54 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "params->GRAYMAX out of range"); |
55 | return NULL; | 55 | return NULL; |
56 | } | 56 | } |
57 | 57 | ||
@@ -60,7 +60,7 @@ jbig2_hd_new(Jbig2Ctx *ctx, const Jbig2PatternDictParams *params, Jbig2Image *im | |||
60 | if (new != NULL) { | 60 | if (new != NULL) { |
61 | new->patterns = jbig2_new(ctx, Jbig2Image *, N); | 61 | new->patterns = jbig2_new(ctx, Jbig2Image *, N); |
62 | if (new->patterns == NULL) { | 62 | if (new->patterns == NULL) { |
63 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate pattern in collective bitmap dictionary"); | 63 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to allocate pattern in collective bitmap dictionary"); |
64 | jbig2_free(ctx->allocator, new); | 64 | jbig2_free(ctx->allocator, new); |
65 | return NULL; | 65 | return NULL; |
66 | } | 66 | } |
@@ -72,7 +72,7 @@ jbig2_hd_new(Jbig2Ctx *ctx, const Jbig2PatternDictParams *params, Jbig2Image *im | |||
72 | for (i = 0; i < N; i++) { | 72 | for (i = 0; i < N; i++) { |
73 | new->patterns[i] = jbig2_image_new(ctx, HPW, HPH); | 73 | new->patterns[i] = jbig2_image_new(ctx, HPW, HPH); |
74 | if (new->patterns[i] == NULL) { | 74 | if (new->patterns[i] == NULL) { |
75 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to allocate pattern element image"); | 75 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to allocate pattern element image"); |
76 | for (j = 0; j < i; j++) | 76 | for (j = 0; j < i; j++) |
77 | jbig2_free(ctx->allocator, new->patterns[j]); | 77 | jbig2_free(ctx->allocator, new->patterns[j]); |
78 | jbig2_free(ctx->allocator, new); | 78 | jbig2_free(ctx->allocator, new); |
@@ -83,7 +83,7 @@ jbig2_hd_new(Jbig2Ctx *ctx, const Jbig2PatternDictParams *params, Jbig2Image *im | |||
83 | proper sub image */ | 83 | proper sub image */ |
84 | code = jbig2_image_compose(ctx, new->patterns[i], image, -i * (int32_t) HPW, 0, JBIG2_COMPOSE_REPLACE); | 84 | code = jbig2_image_compose(ctx, new->patterns[i], image, -i * (int32_t) HPW, 0, JBIG2_COMPOSE_REPLACE); |
85 | if (code < 0) { | 85 | if (code < 0) { |
86 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to compose image into collective bitmap dictionary"); | 86 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to compose image into collective bitmap dictionary"); |
87 | for (j = 0; j < i; j++) | 87 | for (j = 0; j < i; j++) |
88 | jbig2_free(ctx->allocator, new->patterns[j]); | 88 | jbig2_free(ctx->allocator, new->patterns[j]); |
89 | jbig2_free(ctx->allocator, new); | 89 | jbig2_free(ctx->allocator, new); |
@@ -91,7 +91,7 @@ jbig2_hd_new(Jbig2Ctx *ctx, const Jbig2PatternDictParams *params, Jbig2Image *im | |||
91 | } | 91 | } |
92 | } | 92 | } |
93 | } else { | 93 | } else { |
94 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate collective bitmap dictionary"); | 94 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to allocate collective bitmap dictionary"); |
95 | } | 95 | } |
96 | 96 | ||
97 | return new; | 97 | return new; |
diff --git a/jbig2dec/jbig2_huffman.c b/jbig2dec/jbig2_huffman.c index f975b9fa8..aa38ed2d5 100644 --- a/jbig2dec/jbig2_huffman.c +++ b/jbig2dec/jbig2_huffman.c | |||
@@ -80,18 +80,18 @@ jbig2_huffman_new(Jbig2Ctx *ctx, Jbig2WordStream *ws) | |||
80 | result->ctx = ctx; | 80 | result->ctx = ctx; |
81 | code = huff_get_next_word(result, 0, &result->this_word); | 81 | code = huff_get_next_word(result, 0, &result->this_word); |
82 | if (code < 0) { | 82 | if (code < 0) { |
83 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to read first huffman word"); | 83 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to read first huffman word"); |
84 | jbig2_huffman_free(ctx, result); | 84 | jbig2_huffman_free(ctx, result); |
85 | return NULL; | 85 | return NULL; |
86 | } | 86 | } |
87 | code = huff_get_next_word(result, 4, &result->next_word); | 87 | code = huff_get_next_word(result, 4, &result->next_word); |
88 | if (code < 0) { | 88 | if (code < 0) { |
89 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to read second huffman word"); | 89 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to read second huffman word"); |
90 | jbig2_huffman_free(ctx, result); | 90 | jbig2_huffman_free(ctx, result); |
91 | return NULL; | 91 | return NULL; |
92 | } | 92 | } |
93 | } else { | 93 | } else { |
94 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate new huffman coding state"); | 94 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to allocate new huffman coding state"); |
95 | return NULL; | 95 | return NULL; |
96 | } | 96 | } |
97 | 97 | ||
@@ -192,7 +192,7 @@ jbig2_huffman_skip(Jbig2HuffmanState *hs) | |||
192 | hs->offset += 4; | 192 | hs->offset += 4; |
193 | code = huff_get_next_word(hs, hs->offset + 4, &hs->next_word); | 193 | code = huff_get_next_word(hs, hs->offset + 4, &hs->next_word); |
194 | if (code < 0) { | 194 | if (code < 0) { |
195 | return jbig2_error(hs->ctx, JBIG2_SEVERITY_WARNING, -1, "failed to read next huffman word when skipping"); | 195 | return jbig2_error(hs->ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to read next huffman word when skipping"); |
196 | } | 196 | } |
197 | hs->offset_bits -= 32; | 197 | hs->offset_bits -= 32; |
198 | if (hs->offset_bits) { | 198 | if (hs->offset_bits) { |
@@ -216,11 +216,11 @@ jbig2_huffman_advance(Jbig2HuffmanState *hs, size_t advance) | |||
216 | } | 216 | } |
217 | code = huff_get_next_word(hs, hs->offset, &hs->this_word); | 217 | code = huff_get_next_word(hs, hs->offset, &hs->this_word); |
218 | if (code < 0) { | 218 | if (code < 0) { |
219 | return jbig2_error(hs->ctx, JBIG2_SEVERITY_WARNING, -1, "failed to get first huffman word after advancing"); | 219 | return jbig2_error(hs->ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to get first huffman word after advancing"); |
220 | } | 220 | } |
221 | code = huff_get_next_word(hs, hs->offset + 4, &hs->next_word); | 221 | code = huff_get_next_word(hs, hs->offset + 4, &hs->next_word); |
222 | if (code < 0) { | 222 | if (code < 0) { |
223 | return jbig2_error(hs->ctx, JBIG2_SEVERITY_WARNING, -1, "failed to get second huffman word after advancing"); | 223 | return jbig2_error(hs->ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to get second huffman word after advancing"); |
224 | } | 224 | } |
225 | if (hs->offset_bits > 0) | 225 | if (hs->offset_bits > 0) |
226 | hs->this_word = (hs->this_word << hs->offset_bits) | (hs->next_word >> (32 - hs->offset_bits)); | 226 | hs->this_word = (hs->this_word << hs->offset_bits) | (hs->next_word >> (32 - hs->offset_bits)); |
@@ -248,7 +248,7 @@ jbig2_huffman_get_bits(Jbig2HuffmanState *hs, const int bits, int *err) | |||
248 | 248 | ||
249 | if (hs->offset_limit && hs->offset >= hs->offset_limit) { | 249 | if (hs->offset_limit && hs->offset >= hs->offset_limit) { |
250 | *err = -1; | 250 | *err = -1; |
251 | return jbig2_error(hs->ctx, JBIG2_SEVERITY_FATAL, -1, "end of jbig2 buffer reached at offset %d", hs->offset); | 251 | return jbig2_error(hs->ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "end of jbig2 buffer reached at offset %d", hs->offset); |
252 | } | 252 | } |
253 | 253 | ||
254 | result = this_word >> (32 - bits); | 254 | result = this_word >> (32 - bits); |
@@ -259,7 +259,7 @@ jbig2_huffman_get_bits(Jbig2HuffmanState *hs, const int bits, int *err) | |||
259 | hs->this_word = hs->next_word; | 259 | hs->this_word = hs->next_word; |
260 | code = huff_get_next_word(hs, hs->offset + 4, &hs->next_word); | 260 | code = huff_get_next_word(hs, hs->offset + 4, &hs->next_word); |
261 | if (code < 0) { | 261 | if (code < 0) { |
262 | return jbig2_error(hs->ctx, JBIG2_SEVERITY_WARNING, -1, "failed to get next huffman word"); | 262 | return jbig2_error(hs->ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to get next huffman word"); |
263 | } | 263 | } |
264 | if (hs->offset_bits) { | 264 | if (hs->offset_bits) { |
265 | hs->this_word = (hs->this_word << hs->offset_bits) | (hs->next_word >> (32 - hs->offset_bits)); | 265 | hs->this_word = (hs->this_word << hs->offset_bits) | (hs->next_word >> (32 - hs->offset_bits)); |
@@ -287,7 +287,7 @@ jbig2_huffman_get(Jbig2HuffmanState *hs, const Jbig2HuffmanTable *table, bool *o | |||
287 | if (hs->offset_limit && hs->offset >= hs->offset_limit) { | 287 | if (hs->offset_limit && hs->offset >= hs->offset_limit) { |
288 | if (oob) | 288 | if (oob) |
289 | *oob = -1; | 289 | *oob = -1; |
290 | return jbig2_error(hs->ctx, JBIG2_SEVERITY_FATAL, -1, "end of Jbig2WordStream reached at offset %d", hs->offset); | 290 | return jbig2_error(hs->ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "end of Jbig2WordStream reached at offset %d", hs->offset); |
291 | } | 291 | } |
292 | 292 | ||
293 | for (;;) { | 293 | for (;;) { |
@@ -302,7 +302,7 @@ jbig2_huffman_get(Jbig2HuffmanState *hs, const Jbig2HuffmanTable *table, bool *o | |||
302 | if (flags == (byte) -1 || PREFLEN == (byte) -1) { | 302 | if (flags == (byte) -1 || PREFLEN == (byte) -1) { |
303 | if (oob) | 303 | if (oob) |
304 | *oob = -1; | 304 | *oob = -1; |
305 | return jbig2_error(hs->ctx, JBIG2_SEVERITY_FATAL, -1, "encountered unpopulated huffman table entry"); | 305 | return jbig2_error(hs->ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "encountered unpopulated huffman table entry"); |
306 | } | 306 | } |
307 | 307 | ||
308 | next_word = hs->next_word; | 308 | next_word = hs->next_word; |
@@ -312,7 +312,7 @@ jbig2_huffman_get(Jbig2HuffmanState *hs, const Jbig2HuffmanTable *table, bool *o | |||
312 | hs->offset += 4; | 312 | hs->offset += 4; |
313 | code = huff_get_next_word(hs, hs->offset + 4, &next_word); | 313 | code = huff_get_next_word(hs, hs->offset + 4, &next_word); |
314 | if (code < 0) { | 314 | if (code < 0) { |
315 | return jbig2_error(hs->ctx, JBIG2_SEVERITY_WARNING, -1, "failed to get next huffman word"); | 315 | return jbig2_error(hs->ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to get next huffman word"); |
316 | } | 316 | } |
317 | offset_bits -= 32; | 317 | offset_bits -= 32; |
318 | hs->next_word = next_word; | 318 | hs->next_word = next_word; |
@@ -343,7 +343,7 @@ jbig2_huffman_get(Jbig2HuffmanState *hs, const Jbig2HuffmanTable *table, bool *o | |||
343 | hs->offset += 4; | 343 | hs->offset += 4; |
344 | code = huff_get_next_word(hs, hs->offset + 4, &next_word); | 344 | code = huff_get_next_word(hs, hs->offset + 4, &next_word); |
345 | if (code < 0) { | 345 | if (code < 0) { |
346 | return jbig2_error(hs->ctx, JBIG2_SEVERITY_WARNING, -1, "failed to get next huffman word"); | 346 | return jbig2_error(hs->ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to get next huffman word"); |
347 | } | 347 | } |
348 | offset_bits -= 32; | 348 | offset_bits -= 32; |
349 | hs->next_word = next_word; | 349 | hs->next_word = next_word; |
@@ -391,7 +391,7 @@ jbig2_build_huffman_table(Jbig2Ctx *ctx, const Jbig2HuffmanParams *params) | |||
391 | LENCOUNT = jbig2_new(ctx, int, lencountcount); | 391 | LENCOUNT = jbig2_new(ctx, int, lencountcount); |
392 | 392 | ||
393 | if (LENCOUNT == NULL) { | 393 | if (LENCOUNT == NULL) { |
394 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate huffman histogram"); | 394 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to allocate huffman histogram"); |
395 | return NULL; | 395 | return NULL; |
396 | } | 396 | } |
397 | memset(LENCOUNT, 0, sizeof(int) * lencountcount); | 397 | memset(LENCOUNT, 0, sizeof(int) * lencountcount); |
@@ -414,19 +414,19 @@ jbig2_build_huffman_table(Jbig2Ctx *ctx, const Jbig2HuffmanParams *params) | |||
414 | if (lts <= LOG_TABLE_SIZE_MAX && log_table_size < lts) | 414 | if (lts <= LOG_TABLE_SIZE_MAX && log_table_size < lts) |
415 | log_table_size = lts; | 415 | log_table_size = lts; |
416 | } | 416 | } |
417 | jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, -1, "constructing huffman table log size %d", log_table_size); | 417 | jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, JBIG2_UNKNOWN_SEGMENT_NUMBER, "constructing huffman table log size %d", log_table_size); |
418 | max_j = 1 << log_table_size; | 418 | max_j = 1 << log_table_size; |
419 | 419 | ||
420 | result = jbig2_new(ctx, Jbig2HuffmanTable, 1); | 420 | result = jbig2_new(ctx, Jbig2HuffmanTable, 1); |
421 | if (result == NULL) { | 421 | if (result == NULL) { |
422 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate result"); | 422 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to allocate result"); |
423 | jbig2_free(ctx->allocator, LENCOUNT); | 423 | jbig2_free(ctx->allocator, LENCOUNT); |
424 | return NULL; | 424 | return NULL; |
425 | } | 425 | } |
426 | result->log_table_size = log_table_size; | 426 | result->log_table_size = log_table_size; |
427 | entries = jbig2_new(ctx, Jbig2HuffmanEntry, max_j); | 427 | entries = jbig2_new(ctx, Jbig2HuffmanEntry, max_j); |
428 | if (entries == NULL) { | 428 | if (entries == NULL) { |
429 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate result entries"); | 429 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to allocate result entries"); |
430 | jbig2_free(ctx->allocator, result); | 430 | jbig2_free(ctx->allocator, result); |
431 | jbig2_free(ctx->allocator, LENCOUNT); | 431 | jbig2_free(ctx->allocator, LENCOUNT); |
432 | return NULL; | 432 | return NULL; |
@@ -455,7 +455,7 @@ jbig2_build_huffman_table(Jbig2Ctx *ctx, const Jbig2HuffmanParams *params) | |||
455 | byte eflags = 0; | 455 | byte eflags = 0; |
456 | 456 | ||
457 | if (end_j > max_j) { | 457 | if (end_j > max_j) { |
458 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "ran off the end of the entries table! (%d >= %d)", end_j, max_j); | 458 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "ran off the end of the entries table! (%d >= %d)", end_j, max_j); |
459 | jbig2_free(ctx->allocator, result->entries); | 459 | jbig2_free(ctx->allocator, result->entries); |
460 | jbig2_free(ctx->allocator, result); | 460 | jbig2_free(ctx->allocator, result); |
461 | jbig2_free(ctx->allocator, LENCOUNT); | 461 | jbig2_free(ctx->allocator, LENCOUNT); |
diff --git a/jbig2dec/jbig2_image.c b/jbig2dec/jbig2_image.c index 4f6f5163c..f814e7e75 100644 --- a/jbig2dec/jbig2_image.c +++ b/jbig2dec/jbig2_image.c | |||
@@ -38,13 +38,13 @@ jbig2_image_new(Jbig2Ctx *ctx, uint32_t width, uint32_t height) | |||
38 | uint32_t stride; | 38 | uint32_t stride; |
39 | 39 | ||
40 | if (width == 0 || height == 0) { | 40 | if (width == 0 || height == 0) { |
41 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to create zero sized image"); | 41 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to create zero sized image"); |
42 | return NULL; | 42 | return NULL; |
43 | } | 43 | } |
44 | 44 | ||
45 | image = jbig2_new(ctx, Jbig2Image, 1); | 45 | image = jbig2_new(ctx, Jbig2Image, 1); |
46 | if (image == NULL) { | 46 | if (image == NULL) { |
47 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate image"); | 47 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to allocate image"); |
48 | return NULL; | 48 | return NULL; |
49 | } | 49 | } |
50 | 50 | ||
@@ -52,13 +52,13 @@ jbig2_image_new(Jbig2Ctx *ctx, uint32_t width, uint32_t height) | |||
52 | 52 | ||
53 | /* check for integer multiplication overflow */ | 53 | /* check for integer multiplication overflow */ |
54 | if (height > (INT32_MAX / stride)) { | 54 | if (height > (INT32_MAX / stride)) { |
55 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "integer multiplication overflow (stride=%u, height=%u)", stride, height); | 55 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "integer multiplication overflow (stride=%u, height=%u)", stride, height); |
56 | jbig2_free(ctx->allocator, image); | 56 | jbig2_free(ctx->allocator, image); |
57 | return NULL; | 57 | return NULL; |
58 | } | 58 | } |
59 | image->data = jbig2_new(ctx, uint8_t, (size_t) height * stride); | 59 | image->data = jbig2_new(ctx, uint8_t, (size_t) height * stride); |
60 | if (image->data == NULL) { | 60 | if (image->data == NULL) { |
61 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate image data buffer (stride=%u, height=%u)", stride, height); | 61 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to allocate image data buffer (stride=%u, height=%u)", stride, height); |
62 | jbig2_free(ctx->allocator, image); | 62 | jbig2_free(ctx->allocator, image); |
63 | return NULL; | 63 | return NULL; |
64 | } | 64 | } |
@@ -110,13 +110,13 @@ jbig2_image_resize(Jbig2Ctx *ctx, Jbig2Image *image, uint32_t width, uint32_t he | |||
110 | 110 | ||
111 | /* check for integer multiplication overflow */ | 111 | /* check for integer multiplication overflow */ |
112 | if (image->height > (INT32_MAX / image->stride)) { | 112 | if (image->height > (INT32_MAX / image->stride)) { |
113 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "integer multiplication overflow during resize (stride=%u, height=%u)", image->stride, height); | 113 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "integer multiplication overflow during resize (stride=%u, height=%u)", image->stride, height); |
114 | return NULL; | 114 | return NULL; |
115 | } | 115 | } |
116 | /* use the same stride, just change the length */ | 116 | /* use the same stride, just change the length */ |
117 | data = jbig2_renew(ctx, image->data, uint8_t, (size_t) height * image->stride); | 117 | data = jbig2_renew(ctx, image->data, uint8_t, (size_t) height * image->stride); |
118 | if (data == NULL) { | 118 | if (data == NULL) { |
119 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to reallocate image"); | 119 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to reallocate image"); |
120 | return NULL; | 120 | return NULL; |
121 | } | 121 | } |
122 | image->data = data; | 122 | image->data = data; |
@@ -134,14 +134,14 @@ jbig2_image_resize(Jbig2Ctx *ctx, Jbig2Image *image, uint32_t width, uint32_t he | |||
134 | 134 | ||
135 | newimage = jbig2_image_new(ctx, width, height); | 135 | newimage = jbig2_image_new(ctx, width, height); |
136 | if (newimage == NULL) { | 136 | if (newimage == NULL) { |
137 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to allocate resized image"); | 137 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to allocate resized image"); |
138 | return NULL; | 138 | return NULL; |
139 | } | 139 | } |
140 | jbig2_image_clear(ctx, newimage, value); | 140 | jbig2_image_clear(ctx, newimage, value); |
141 | 141 | ||
142 | code = jbig2_image_compose(ctx, newimage, image, 0, 0, JBIG2_COMPOSE_REPLACE); | 142 | code = jbig2_image_compose(ctx, newimage, image, 0, 0, JBIG2_COMPOSE_REPLACE); |
143 | if (code < 0) { | 143 | if (code < 0) { |
144 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to compose image buffers when resizing"); | 144 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to compose image buffers when resizing"); |
145 | jbig2_image_release(ctx, newimage); | 145 | jbig2_image_release(ctx, newimage); |
146 | return NULL; | 146 | return NULL; |
147 | } | 147 | } |
@@ -351,7 +351,7 @@ jbig2_image_compose(Jbig2Ctx *ctx, Jbig2Image *dst, Jbig2Image *src, int x, int | |||
351 | (UINT32_MAX - src->height < (y > 0 ? y : -y))) | 351 | (UINT32_MAX - src->height < (y > 0 ? y : -y))) |
352 | { | 352 | { |
353 | #ifdef JBIG2_DEBUG | 353 | #ifdef JBIG2_DEBUG |
354 | jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, -1, "overflow in compose_image"); | 354 | jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, JBIG2_UNKNOWN_SEGMENT_NUMBER, "overflow in compose_image"); |
355 | #endif | 355 | #endif |
356 | return 0; | 356 | return 0; |
357 | } | 357 | } |
@@ -411,13 +411,13 @@ jbig2_image_compose(Jbig2Ctx *ctx, Jbig2Image *dst, Jbig2Image *src, int x, int | |||
411 | h = dst->height - y; | 411 | h = dst->height - y; |
412 | } | 412 | } |
413 | #ifdef JBIG2_DEBUG | 413 | #ifdef JBIG2_DEBUG |
414 | jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, -1, "compositing %dx%d at (%d, %d) after clipping", w, h, x, y); | 414 | jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, JBIG2_UNKNOWN_SEGMENT_NUMBER, "compositing %dx%d at (%d, %d) after clipping", w, h, x, y); |
415 | #endif | 415 | #endif |
416 | 416 | ||
417 | /* check for zero clipping region */ | 417 | /* check for zero clipping region */ |
418 | if ((w <= 0) || (h <= 0)) { | 418 | if ((w <= 0) || (h <= 0)) { |
419 | #ifdef JBIG2_DEBUG | 419 | #ifdef JBIG2_DEBUG |
420 | jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, -1, "zero clipping region"); | 420 | jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, JBIG2_UNKNOWN_SEGMENT_NUMBER, "zero clipping region"); |
421 | #endif | 421 | #endif |
422 | return 0; | 422 | return 0; |
423 | } | 423 | } |
diff --git a/jbig2dec/jbig2_mmr.c b/jbig2dec/jbig2_mmr.c index 5d15b138a..8029c8139 100644 --- a/jbig2dec/jbig2_mmr.c +++ b/jbig2dec/jbig2_mmr.c | |||
@@ -951,11 +951,11 @@ jbig2_decode_get_run(Jbig2Ctx *ctx, Jbig2MmrCtx *mmr, const mmr_table_node *tabl | |||
951 | do { | 951 | do { |
952 | val = jbig2_decode_get_code(mmr, table, initial_bits); | 952 | val = jbig2_decode_get_code(mmr, table, initial_bits); |
953 | if (val == ERROR) | 953 | if (val == ERROR) |
954 | return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "invalid code detected in MMR-coded data"); | 954 | return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "invalid code detected in MMR-coded data"); |
955 | else if (val == UNCOMPRESSED) | 955 | else if (val == UNCOMPRESSED) |
956 | return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "uncompressed code in MMR-coded data"); | 956 | return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "uncompressed code in MMR-coded data"); |
957 | else if (val == ZEROES) | 957 | else if (val == ZEROES) |
958 | return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "zeroes code in MMR-coded data"); | 958 | return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "zeroes code in MMR-coded data"); |
959 | result += val; | 959 | result += val; |
960 | } while (val >= 64); | 960 | } while (val >= 64); |
961 | 961 | ||
@@ -988,10 +988,10 @@ jbig2_decode_mmr_line(Jbig2Ctx *ctx, Jbig2MmrCtx *mmr, const byte *ref, byte *ds | |||
988 | if (c == 0) { | 988 | if (c == 0) { |
989 | white_run = jbig2_decode_get_run(ctx, mmr, jbig2_mmr_white_decode, 8); | 989 | white_run = jbig2_decode_get_run(ctx, mmr, jbig2_mmr_white_decode, 8); |
990 | if (white_run < 0) | 990 | if (white_run < 0) |
991 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to decode white H run"); | 991 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to decode white H run"); |
992 | black_run = jbig2_decode_get_run(ctx, mmr, jbig2_mmr_black_decode, 7); | 992 | black_run = jbig2_decode_get_run(ctx, mmr, jbig2_mmr_black_decode, 7); |
993 | if (black_run < 0) | 993 | if (black_run < 0) |
994 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to decode black H run"); | 994 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to decode black H run"); |
995 | /* printf ("H %d %d\n", white_run, black_run); */ | 995 | /* printf ("H %d %d\n", white_run, black_run); */ |
996 | a1 = a0 + white_run; | 996 | a1 = a0 + white_run; |
997 | a2 = a1 + black_run; | 997 | a2 = a1 + black_run; |
@@ -1000,7 +1000,7 @@ jbig2_decode_mmr_line(Jbig2Ctx *ctx, Jbig2MmrCtx *mmr, const byte *ref, byte *ds | |||
1000 | if (a2 > mmr->width) | 1000 | if (a2 > mmr->width) |
1001 | a2 = mmr->width; | 1001 | a2 = mmr->width; |
1002 | if (a2 < a1) { | 1002 | if (a2 < a1) { |
1003 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "ignoring negative black H run"); | 1003 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "ignoring negative black H run"); |
1004 | a2 = a1; | 1004 | a2 = a1; |
1005 | } | 1005 | } |
1006 | if (a1 < mmr->width) | 1006 | if (a1 < mmr->width) |
@@ -1009,10 +1009,10 @@ jbig2_decode_mmr_line(Jbig2Ctx *ctx, Jbig2MmrCtx *mmr, const byte *ref, byte *ds | |||
1009 | } else { | 1009 | } else { |
1010 | black_run = jbig2_decode_get_run(ctx, mmr, jbig2_mmr_black_decode, 7); | 1010 | black_run = jbig2_decode_get_run(ctx, mmr, jbig2_mmr_black_decode, 7); |
1011 | if (black_run < 0) | 1011 | if (black_run < 0) |
1012 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to decode black H run"); | 1012 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to decode black H run"); |
1013 | white_run = jbig2_decode_get_run(ctx, mmr, jbig2_mmr_white_decode, 8); | 1013 | white_run = jbig2_decode_get_run(ctx, mmr, jbig2_mmr_white_decode, 8); |
1014 | if (white_run < 0) | 1014 | if (white_run < 0) |
1015 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to decode white H run"); | 1015 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to decode white H run"); |
1016 | /* printf ("H %d %d\n", black_run, white_run); */ | 1016 | /* printf ("H %d %d\n", black_run, white_run); */ |
1017 | a1 = a0 + black_run; | 1017 | a1 = a0 + black_run; |
1018 | a2 = a1 + white_run; | 1018 | a2 = a1 + white_run; |
@@ -1021,7 +1021,7 @@ jbig2_decode_mmr_line(Jbig2Ctx *ctx, Jbig2MmrCtx *mmr, const byte *ref, byte *ds | |||
1021 | if (a2 > mmr->width) | 1021 | if (a2 > mmr->width) |
1022 | a2 = mmr->width; | 1022 | a2 = mmr->width; |
1023 | if (a1 < a0) { | 1023 | if (a1 < a0) { |
1024 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "ignoring negative white H run"); | 1024 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "ignoring negative white H run"); |
1025 | a1 = a0; | 1025 | a1 = a0; |
1026 | } | 1026 | } |
1027 | if (a0 < mmr->width) | 1027 | if (a0 < mmr->width) |
@@ -1037,7 +1037,7 @@ jbig2_decode_mmr_line(Jbig2Ctx *ctx, Jbig2MmrCtx *mmr, const byte *ref, byte *ds | |||
1037 | b2 = jbig2_find_changing_element(ref, b1, mmr->width); | 1037 | b2 = jbig2_find_changing_element(ref, b1, mmr->width); |
1038 | if (c) { | 1038 | if (c) { |
1039 | if (b2 < a0) { | 1039 | if (b2 < a0) { |
1040 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "ignoring negative P run"); | 1040 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "ignoring negative P run"); |
1041 | b2 = a0; | 1041 | b2 = a0; |
1042 | } | 1042 | } |
1043 | if (a0 < mmr->width) | 1043 | if (a0 < mmr->width) |
@@ -1052,7 +1052,7 @@ jbig2_decode_mmr_line(Jbig2Ctx *ctx, Jbig2MmrCtx *mmr, const byte *ref, byte *ds | |||
1052 | b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c); | 1052 | b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c); |
1053 | if (c) { | 1053 | if (c) { |
1054 | if (b1 < a0) { | 1054 | if (b1 < a0) { |
1055 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "ignoring negative V(0) run"); | 1055 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "ignoring negative V(0) run"); |
1056 | b1 = a0; | 1056 | b1 = a0; |
1057 | } | 1057 | } |
1058 | if (a0 < mmr->width) | 1058 | if (a0 < mmr->width) |
@@ -1070,7 +1070,7 @@ jbig2_decode_mmr_line(Jbig2Ctx *ctx, Jbig2MmrCtx *mmr, const byte *ref, byte *ds | |||
1070 | b1 += 1; | 1070 | b1 += 1; |
1071 | if (c) { | 1071 | if (c) { |
1072 | if (b1 < a0) { | 1072 | if (b1 < a0) { |
1073 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "ignoring negative VR(1) run"); | 1073 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "ignoring negative VR(1) run"); |
1074 | b1 = a0; | 1074 | b1 = a0; |
1075 | } | 1075 | } |
1076 | if (a0 < mmr->width) | 1076 | if (a0 < mmr->width) |
@@ -1088,7 +1088,7 @@ jbig2_decode_mmr_line(Jbig2Ctx *ctx, Jbig2MmrCtx *mmr, const byte *ref, byte *ds | |||
1088 | b1 += 2; | 1088 | b1 += 2; |
1089 | if (c) { | 1089 | if (c) { |
1090 | if (b1 < a0) { | 1090 | if (b1 < a0) { |
1091 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "ignoring negative VR(2) run"); | 1091 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "ignoring negative VR(2) run"); |
1092 | b1 = a0; | 1092 | b1 = a0; |
1093 | } | 1093 | } |
1094 | if (a0 < mmr->width) | 1094 | if (a0 < mmr->width) |
@@ -1106,7 +1106,7 @@ jbig2_decode_mmr_line(Jbig2Ctx *ctx, Jbig2MmrCtx *mmr, const byte *ref, byte *ds | |||
1106 | b1 += 3; | 1106 | b1 += 3; |
1107 | if (c) { | 1107 | if (c) { |
1108 | if (b1 < a0) { | 1108 | if (b1 < a0) { |
1109 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "ignoring negative VR(3) run"); | 1109 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "ignoring negative VR(3) run"); |
1110 | b1 = a0; | 1110 | b1 = a0; |
1111 | } | 1111 | } |
1112 | if (a0 < mmr->width) | 1112 | if (a0 < mmr->width) |
@@ -1124,7 +1124,7 @@ jbig2_decode_mmr_line(Jbig2Ctx *ctx, Jbig2MmrCtx *mmr, const byte *ref, byte *ds | |||
1124 | b1 -= 1; | 1124 | b1 -= 1; |
1125 | if (c) { | 1125 | if (c) { |
1126 | if (b1 < a0) { | 1126 | if (b1 < a0) { |
1127 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "ignoring negative VL(1) run"); | 1127 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "ignoring negative VL(1) run"); |
1128 | b1 = a0; | 1128 | b1 = a0; |
1129 | } | 1129 | } |
1130 | if (a0 < mmr->width) | 1130 | if (a0 < mmr->width) |
@@ -1142,7 +1142,7 @@ jbig2_decode_mmr_line(Jbig2Ctx *ctx, Jbig2MmrCtx *mmr, const byte *ref, byte *ds | |||
1142 | b1 -= 2; | 1142 | b1 -= 2; |
1143 | if (c) { | 1143 | if (c) { |
1144 | if (b1 < a0) { | 1144 | if (b1 < a0) { |
1145 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "ignoring negative VL(2) run"); | 1145 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "ignoring negative VL(2) run"); |
1146 | b1 = a0; | 1146 | b1 = a0; |
1147 | } | 1147 | } |
1148 | if (a0 < mmr->width) | 1148 | if (a0 < mmr->width) |
@@ -1160,7 +1160,7 @@ jbig2_decode_mmr_line(Jbig2Ctx *ctx, Jbig2MmrCtx *mmr, const byte *ref, byte *ds | |||
1160 | b1 -= 3; | 1160 | b1 -= 3; |
1161 | if (c) { | 1161 | if (c) { |
1162 | if (b1 < a0) { | 1162 | if (b1 < a0) { |
1163 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "ignoring negative VL(3) run"); | 1163 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "ignoring negative VL(3) run"); |
1164 | b1 = a0; | 1164 | b1 = a0; |
1165 | } | 1165 | } |
1166 | if (a0 < mmr->width) | 1166 | if (a0 < mmr->width) |
@@ -1245,7 +1245,7 @@ jbig2_decode_halftone_mmr(Jbig2Ctx *ctx, const Jbig2GenericRegionParams *params, | |||
1245 | memset(dst, 0, rowstride); | 1245 | memset(dst, 0, rowstride); |
1246 | code = jbig2_decode_mmr_line(ctx, &mmr, ref, dst, &eofb); | 1246 | code = jbig2_decode_mmr_line(ctx, &mmr, ref, dst, &eofb); |
1247 | if (code < 0) | 1247 | if (code < 0) |
1248 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to decode halftone mmr line"); | 1248 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to decode halftone mmr line"); |
1249 | ref = dst; | 1249 | ref = dst; |
1250 | dst += rowstride; | 1250 | dst += rowstride; |
1251 | } | 1251 | } |
diff --git a/jbig2dec/jbig2_page.c b/jbig2dec/jbig2_page.c index 7d3b656fa..21483e8fa 100644 --- a/jbig2dec/jbig2_page.c +++ b/jbig2dec/jbig2_page.c | |||
@@ -215,7 +215,7 @@ jbig2_complete_page(Jbig2Ctx *ctx) | |||
215 | 215 | ||
216 | /* ensure image exists before marking page as complete */ | 216 | /* ensure image exists before marking page as complete */ |
217 | if (ctx->pages[ctx->current_page].image == NULL) { | 217 | if (ctx->pages[ctx->current_page].image == NULL) { |
218 | return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "page has no image, cannot be completed"); | 218 | return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "page has no image, cannot be completed"); |
219 | } | 219 | } |
220 | 220 | ||
221 | ctx->pages[ctx->current_page].state = JBIG2_PAGE_COMPLETE; | 221 | ctx->pages[ctx->current_page].state = JBIG2_PAGE_COMPLETE; |
@@ -263,27 +263,27 @@ jbig2_page_add_result(Jbig2Ctx *ctx, Jbig2Page *page, Jbig2Image *image, uint32_ | |||
263 | int code; | 263 | int code; |
264 | 264 | ||
265 | if (x > INT32_MAX || y > INT32_MAX) | 265 | if (x > INT32_MAX || y > INT32_MAX) |
266 | return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "unsupported image coordinates"); | 266 | return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "unsupported image coordinates"); |
267 | 267 | ||
268 | /* ensure image exists first */ | 268 | /* ensure image exists first */ |
269 | if (page->image == NULL) | 269 | if (page->image == NULL) |
270 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "page info possibly missing, no image defined"); | 270 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "page info possibly missing, no image defined"); |
271 | 271 | ||
272 | /* grow the page to accommodate a new stripe if necessary */ | 272 | /* grow the page to accommodate a new stripe if necessary */ |
273 | if (page->striped && page->height == 0xFFFFFFFF) { | 273 | if (page->striped && page->height == 0xFFFFFFFF) { |
274 | uint32_t new_height; | 274 | uint32_t new_height; |
275 | 275 | ||
276 | if (y > UINT32_MAX - image->height) | 276 | if (y > UINT32_MAX - image->height) |
277 | return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "adding image at coordinate would grow page out of bounds"); | 277 | return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "adding image at coordinate would grow page out of bounds"); |
278 | new_height = y + image->height; | 278 | new_height = y + image->height; |
279 | 279 | ||
280 | if (page->image->height < new_height) { | 280 | if (page->image->height < new_height) { |
281 | Jbig2Image *resized_image = NULL; | 281 | Jbig2Image *resized_image = NULL; |
282 | 282 | ||
283 | jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, -1, "growing page buffer to %u rows to accommodate new stripe", new_height); | 283 | jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, JBIG2_UNKNOWN_SEGMENT_NUMBER, "growing page buffer to %u rows to accommodate new stripe", new_height); |
284 | resized_image = jbig2_image_resize(ctx, page->image, page->image->width, new_height, page->flags & 4); | 284 | resized_image = jbig2_image_resize(ctx, page->image, page->image->width, new_height, page->flags & 4); |
285 | if (resized_image == NULL) { | 285 | if (resized_image == NULL) { |
286 | return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "unable to resize image to accommodate new stripe"); | 286 | return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "unable to resize image to accommodate new stripe"); |
287 | } | 287 | } |
288 | page->image = resized_image; | 288 | page->image = resized_image; |
289 | } | 289 | } |
@@ -291,7 +291,7 @@ jbig2_page_add_result(Jbig2Ctx *ctx, Jbig2Page *page, Jbig2Image *image, uint32_ | |||
291 | 291 | ||
292 | code = jbig2_image_compose(ctx, page->image, image, x, y, op); | 292 | code = jbig2_image_compose(ctx, page->image, image, x, y, op); |
293 | if (code < 0) | 293 | if (code < 0) |
294 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to compose image with page"); | 294 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to compose image with page"); |
295 | 295 | ||
296 | return 0; | 296 | return 0; |
297 | } | 297 | } |
@@ -320,12 +320,12 @@ jbig2_page_out(Jbig2Ctx *ctx) | |||
320 | uint32_t page_number = ctx->pages[index].number; | 320 | uint32_t page_number = ctx->pages[index].number; |
321 | 321 | ||
322 | if (img == NULL) { | 322 | if (img == NULL) { |
323 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "page %d returned with no associated image", page_number); | 323 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "page %d returned with no associated image", page_number); |
324 | continue; | 324 | continue; |
325 | } | 325 | } |
326 | 326 | ||
327 | ctx->pages[index].state = JBIG2_PAGE_RETURNED; | 327 | ctx->pages[index].state = JBIG2_PAGE_RETURNED; |
328 | jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, -1, "page %d returned to the client", page_number); | 328 | jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, JBIG2_UNKNOWN_SEGMENT_NUMBER, "page %d returned to the client", page_number); |
329 | return jbig2_image_reference(ctx, img); | 329 | return jbig2_image_reference(ctx, img); |
330 | } | 330 | } |
331 | } | 331 | } |
@@ -350,11 +350,11 @@ jbig2_release_page(Jbig2Ctx *ctx, Jbig2Image *image) | |||
350 | if (ctx->pages[index].image == image) { | 350 | if (ctx->pages[index].image == image) { |
351 | jbig2_image_release(ctx, image); | 351 | jbig2_image_release(ctx, image); |
352 | ctx->pages[index].state = JBIG2_PAGE_RELEASED; | 352 | ctx->pages[index].state = JBIG2_PAGE_RELEASED; |
353 | jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, -1, "page %d released by the client", ctx->pages[index].number); | 353 | jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, JBIG2_UNKNOWN_SEGMENT_NUMBER, "page %d released by the client", ctx->pages[index].number); |
354 | return; | 354 | return; |
355 | } | 355 | } |
356 | } | 356 | } |
357 | 357 | ||
358 | /* no matching pages */ | 358 | /* no matching pages */ |
359 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to release unknown page"); | 359 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to release unknown page"); |
360 | } | 360 | } |
diff --git a/jbig2dec/jbig2_priv.h b/jbig2dec/jbig2_priv.h index 8031705e6..e5a1eb5be 100644 --- a/jbig2dec/jbig2_priv.h +++ b/jbig2dec/jbig2_priv.h | |||
@@ -125,7 +125,7 @@ void *jbig2_realloc(Jbig2Allocator *allocator, void *p, size_t size, size_t num) | |||
125 | 125 | ||
126 | #define jbig2_renew(ctx, p, t, size) ((t *)jbig2_realloc(ctx->allocator, (p), size, sizeof(t))) | 126 | #define jbig2_renew(ctx, p, t, size) ((t *)jbig2_realloc(ctx->allocator, (p), size, sizeof(t))) |
127 | 127 | ||
128 | int jbig2_error(Jbig2Ctx *ctx, Jbig2Severity severity, int32_t seg_idx, const char *fmt, ...) | 128 | int jbig2_error(Jbig2Ctx *ctx, Jbig2Severity severity, uint32_t seg_idx, const char *fmt, ...) |
129 | #ifdef __GNUC__ | 129 | #ifdef __GNUC__ |
130 | __attribute__ ((format (__printf__, 4, 5))) | 130 | __attribute__ ((format (__printf__, 4, 5))) |
131 | #endif | 131 | #endif |
diff --git a/jbig2dec/jbig2_refinement.c b/jbig2dec/jbig2_refinement.c index 34dc212f6..c47a28a1a 100644 --- a/jbig2dec/jbig2_refinement.c +++ b/jbig2dec/jbig2_refinement.c | |||
@@ -312,19 +312,19 @@ jbig2_decode_refinement_TPGRON(Jbig2Ctx *ctx, const Jbig2RefinementRegionParams | |||
312 | if (params->GRTEMPLATE == 0 && | 312 | if (params->GRTEMPLATE == 0 && |
313 | (pixel_outside_field(params->grat[0], params->grat[1]) || | 313 | (pixel_outside_field(params->grat[0], params->grat[1]) || |
314 | refpixel_outside_field(params->grat[2], params->grat[3]))) | 314 | refpixel_outside_field(params->grat[2], params->grat[3]))) |
315 | return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, | 315 | return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, |
316 | "adaptive template pixel is out of field"); | 316 | "adaptive template pixel is out of field"); |
317 | 317 | ||
318 | for (y = 0; y < GRH; y++) { | 318 | for (y = 0; y < GRH; y++) { |
319 | int bit = jbig2_arith_decode(ctx, as, &GR_stats[start_context]); | 319 | int bit = jbig2_arith_decode(ctx, as, &GR_stats[start_context]); |
320 | if (bit < 0) | 320 | if (bit < 0) |
321 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to decode arithmetic code when handling refinement TPGRON1"); | 321 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to decode arithmetic code when handling refinement TPGRON1"); |
322 | LTP ^= bit; | 322 | LTP ^= bit; |
323 | if (!LTP) { | 323 | if (!LTP) { |
324 | for (x = 0; x < GRW; x++) { | 324 | for (x = 0; x < GRW; x++) { |
325 | bit = jbig2_arith_decode(ctx, as, &GR_stats[mkctx(params, image, x, y)]); | 325 | bit = jbig2_arith_decode(ctx, as, &GR_stats[mkctx(params, image, x, y)]); |
326 | if (bit < 0) | 326 | if (bit < 0) |
327 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to decode arithmetic code when handling refinement TPGRON1"); | 327 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to decode arithmetic code when handling refinement TPGRON1"); |
328 | jbig2_image_set_pixel(image, x, y, bit); | 328 | jbig2_image_set_pixel(image, x, y, bit); |
329 | } | 329 | } |
330 | } else { | 330 | } else { |
@@ -333,7 +333,7 @@ jbig2_decode_refinement_TPGRON(Jbig2Ctx *ctx, const Jbig2RefinementRegionParams | |||
333 | if (iv < 0) { | 333 | if (iv < 0) { |
334 | int bit = jbig2_arith_decode(ctx, as, &GR_stats[mkctx(params, image, x, y)]); | 334 | int bit = jbig2_arith_decode(ctx, as, &GR_stats[mkctx(params, image, x, y)]); |
335 | if (bit < 0) | 335 | if (bit < 0) |
336 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to decode arithmetic code when handling refinement TPGRON1"); | 336 | return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to decode arithmetic code when handling refinement TPGRON1"); |
337 | jbig2_image_set_pixel(image, x, y, bit); | 337 | jbig2_image_set_pixel(image, x, y, bit); |
338 | } else | 338 | } else |
339 | jbig2_image_set_pixel(image, x, y, iv); | 339 | jbig2_image_set_pixel(image, x, y, iv); |
diff --git a/jbig2dec/jbig2_segment.c b/jbig2dec/jbig2_segment.c index 1ae3e2199..044238341 100644 --- a/jbig2dec/jbig2_segment.c +++ b/jbig2dec/jbig2_segment.c | |||
@@ -57,12 +57,17 @@ jbig2_parse_segment_header(Jbig2Ctx *ctx, uint8_t *buf, size_t buf_size, size_t | |||
57 | 57 | ||
58 | result = jbig2_new(ctx, Jbig2Segment, 1); | 58 | result = jbig2_new(ctx, Jbig2Segment, 1); |
59 | if (result == NULL) { | 59 | if (result == NULL) { |
60 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate segment"); | 60 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to allocate segment"); |
61 | return NULL; | 61 | return NULL; |
62 | } | 62 | } |
63 | 63 | ||
64 | /* 7.2.2 */ | 64 | /* 7.2.2 */ |
65 | result->number = jbig2_get_uint32(buf); | 65 | result->number = jbig2_get_uint32(buf); |
66 | if (result->number == JBIG2_UNKNOWN_SEGMENT_NUMBER) { | ||
67 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "segment number too large"); | ||
68 | jbig2_free(ctx->allocator, result); | ||
69 | return NULL; | ||
70 | } | ||
66 | 71 | ||
67 | /* 7.2.3 */ | 72 | /* 7.2.3 */ |
68 | result->flags = buf[4]; | 73 | result->flags = buf[4]; |
diff --git a/jbig2dec/jbig2_symbol_dict.c b/jbig2dec/jbig2_symbol_dict.c index f5022af3b..c586475b9 100644 --- a/jbig2dec/jbig2_symbol_dict.c +++ b/jbig2dec/jbig2_symbol_dict.c | |||
@@ -102,14 +102,14 @@ jbig2_sd_new(Jbig2Ctx *ctx, uint32_t n_symbols) | |||
102 | new_dict->glyphs = jbig2_new(ctx, Jbig2Image *, n_symbols); | 102 | new_dict->glyphs = jbig2_new(ctx, Jbig2Image *, n_symbols); |
103 | new_dict->n_symbols = n_symbols; | 103 | new_dict->n_symbols = n_symbols; |
104 | } else { | 104 | } else { |
105 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate new empty symbol dictionary"); | 105 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to allocate new empty symbol dictionary"); |
106 | return NULL; | 106 | return NULL; |
107 | } | 107 | } |
108 | 108 | ||
109 | if (new_dict->glyphs != NULL) { | 109 | if (new_dict->glyphs != NULL) { |
110 | memset(new_dict->glyphs, 0, n_symbols * sizeof(Jbig2Image *)); | 110 | memset(new_dict->glyphs, 0, n_symbols * sizeof(Jbig2Image *)); |
111 | } else if (new_dict->n_symbols > 0) { | 111 | } else if (new_dict->n_symbols > 0) { |
112 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "failed to allocate glyphs for new empty symbol dictionary"); | 112 | jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to allocate glyphs for new empty symbol dictionary"); |
113 | jbig2_free(ctx->allocator, new_dict); | 113 | jbig2_free(ctx->allocator, new_dict); |
114 | return NULL; | 114 | return NULL; |
115 | } | 115 | } |
@@ -215,7 +215,7 @@ jbig2_sd_cat(Jbig2Ctx *ctx, uint32_t n_dicts, Jbig2SymbolDict **dicts) | |||
215 | for (j = 0; j < dicts[i]->n_symbols; j++) | 215 | for (j = 0; j < dicts[i]->n_symbols; j++) |
216 | new_dict->glyphs[k++] = jbig2_image_reference(ctx, dicts[i]->glyphs[j]); | 216 | new_dict->glyphs[k++] = jbig2_image_reference(ctx, dicts[i]->glyphs[j]); |
217 | } else { | 217 | } else { |
218 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to allocate new symbol dictionary"); | 218 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to allocate new symbol dictionary"); |
219 | } | 219 | } |
220 | 220 | ||
221 | return new_dict; | 221 | return new_dict; |
diff --git a/jbig2dec/jbig2dec.c b/jbig2dec/jbig2dec.c index d7d0aef6d..8764581f2 100644 --- a/jbig2dec/jbig2dec.c +++ b/jbig2dec/jbig2dec.c | |||
@@ -113,7 +113,7 @@ static void *jbig2dec_alloc(Jbig2Allocator *allocator_, size_t size) | |||
113 | if (allocator->ctx) { | 113 | if (allocator->ctx) { |
114 | size_t limit_mb = allocator->memory_limit / MBYTE; | 114 | size_t limit_mb = allocator->memory_limit / MBYTE; |
115 | size_t peak_mb = allocator->memory_peak / MBYTE; | 115 | size_t peak_mb = allocator->memory_peak / MBYTE; |
116 | jbig2_error(allocator->ctx, JBIG2_SEVERITY_DEBUG, -1, "memory: limit: %lu Mbyte peak usage: %lu Mbyte", limit_mb, peak_mb); | 116 | jbig2_error(allocator->ctx, JBIG2_SEVERITY_DEBUG, JBIG2_UNKNOWN_SEGMENT_NUMBER, "memory: limit: %lu Mbyte peak usage: %lu Mbyte", limit_mb, peak_mb); |
117 | } | 117 | } |
118 | } | 118 | } |
119 | 119 | ||
@@ -181,7 +181,7 @@ static void *jbig2dec_realloc(Jbig2Allocator *allocator_, void *p, size_t size) | |||
181 | if (allocator->ctx) { | 181 | if (allocator->ctx) { |
182 | size_t limit_mb = allocator->memory_limit / MBYTE; | 182 | size_t limit_mb = allocator->memory_limit / MBYTE; |
183 | size_t peak_mb = allocator->memory_peak / MBYTE; | 183 | size_t peak_mb = allocator->memory_peak / MBYTE; |
184 | jbig2_error(allocator->ctx, JBIG2_SEVERITY_DEBUG, -1, "memory: limit: %lu Mbyte peak usage: %lu Mbyte", limit_mb, peak_mb); | 184 | jbig2_error(allocator->ctx, JBIG2_SEVERITY_DEBUG, JBIG2_UNKNOWN_SEGMENT_NUMBER, "memory: limit: %lu Mbyte peak usage: %lu Mbyte", limit_mb, peak_mb); |
185 | } | 185 | } |
186 | } | 186 | } |
187 | 187 | ||
@@ -372,7 +372,7 @@ print_usage(void) | |||
372 | } | 372 | } |
373 | 373 | ||
374 | static void | 374 | static void |
375 | error_callback(void *error_callback_data, const char *buf, Jbig2Severity severity, int32_t seg_idx) | 375 | error_callback(void *error_callback_data, const char *buf, Jbig2Severity severity, uint32_t seg_idx) |
376 | { | 376 | { |
377 | jbig2dec_error_callback_state_t *state = (jbig2dec_error_callback_state_t *) error_callback_data; | 377 | jbig2dec_error_callback_state_t *state = (jbig2dec_error_callback_state_t *) error_callback_data; |
378 | char *type; | 378 | char *type; |
@@ -407,7 +407,7 @@ error_callback(void *error_callback_data, const char *buf, Jbig2Severity severit | |||
407 | strlen("jbig2dec ") + | 407 | strlen("jbig2dec ") + |
408 | strlen(type) + strlen(" ") + | 408 | strlen(type) + strlen(" ") + |
409 | strlen(buf) + strlen(" ") + | 409 | strlen(buf) + strlen(" ") + |
410 | strlen("(segment 0x") + strlen("2147483648") + strlen(")") + | 410 | strlen("(segment 0x") + strlen("4294967296") + strlen(")") + |
411 | 1 for trailing NUL. The constant parts amount to 45 bytes. */ | 411 | 1 for trailing NUL. The constant parts amount to 45 bytes. */ |
412 | len = 45; | 412 | len = 45; |
413 | len += strlen(type); | 413 | len += strlen(type); |
@@ -417,7 +417,7 @@ error_callback(void *error_callback_data, const char *buf, Jbig2Severity severit | |||
417 | if (message == NULL) { | 417 | if (message == NULL) { |
418 | return; | 418 | return; |
419 | } | 419 | } |
420 | if (seg_idx == -1) | 420 | if (seg_idx == JBIG2_UNKNOWN_SEGMENT_NUMBER) |
421 | snprintf(message, len + 1, "jbig2dec %s %s", type, buf); | 421 | snprintf(message, len + 1, "jbig2dec %s %s", type, buf); |
422 | else | 422 | else |
423 | snprintf(message, len + 1, "jbig2dec %s %s (segment 0x%02x)", type, buf, seg_idx); | 423 | snprintf(message, len + 1, "jbig2dec %s %s (segment 0x%02x)", type, buf, seg_idx); |
@@ -683,7 +683,7 @@ main(int argc, char **argv) | |||
683 | with parse errors. */ | 683 | with parse errors. */ |
684 | code = jbig2_complete_page(ctx); | 684 | code = jbig2_complete_page(ctx); |
685 | if (code < 0) { | 685 | if (code < 0) { |
686 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "unable to complete page"); | 686 | jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "unable to complete page"); |
687 | goto cleanup; | 687 | goto cleanup; |
688 | } | 688 | } |
689 | 689 | ||
@@ -739,7 +739,7 @@ main(int argc, char **argv) | |||
739 | if (allocator != NULL && allocator->ctx != NULL) { | 739 | if (allocator != NULL && allocator->ctx != NULL) { |
740 | size_t limit_mb = allocator->memory_limit / MBYTE; | 740 | size_t limit_mb = allocator->memory_limit / MBYTE; |
741 | size_t peak_mb = allocator->memory_peak / MBYTE; | 741 | size_t peak_mb = allocator->memory_peak / MBYTE; |
742 | jbig2_error(allocator->ctx, JBIG2_SEVERITY_DEBUG, -1, "memory: limit: %lu Mbyte peak usage: %lu Mbyte", limit_mb, peak_mb); | 742 | jbig2_error(allocator->ctx, JBIG2_SEVERITY_DEBUG, JBIG2_UNKNOWN_SEGMENT_NUMBER, "memory: limit: %lu Mbyte peak usage: %lu Mbyte", limit_mb, peak_mb); |
743 | } | 743 | } |
744 | 744 | ||
745 | /* fin */ | 745 | /* fin */ |