From 2b2dcf4ccf401ed210f03c858b304994749fd2b3 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Fri, 6 Apr 2018 00:41:01 +0800 Subject: jbig2dec: Improve error handling. Some functions detected errors but would not return these to the caller. These functions may now indicate errors: jbig2_arith_decode(), jbig2_image_resize() Errors detected by following functions were not always handled, but they are now handled properly: jbig2_arith_decode(), jbig2_arith_iaid_decode() jbig2_arith_int_ctx_new(), jbig2_build_huffman_table() jbig2_complete_page(), jbig2_image_compose() jbig2_decode_refinement_region(), jbig2_ctx_new() jbig2_image_resize(), jbig2_image_write_pbm() jbig2_image_write_pbm_file(), jbig2_image_write_png() jbig2_image_write_png_file(), jbig2_metadata_add() jbig2_page_add_result(), jbig2_renew() jbig2_strndup() Some functions detected errors but did not fail early enough: jbig2_decode_pattern_dict(), jbig2_decode_halftone_region() jbig2_decode_mmr_line() detected errors but did not produce suitable error messages. This has been rectified. Finally, if a subfunction indicates an error by returning an error code, the calling function will report a warning and return, indicating failure. --- jbig2dec/jbig2_arith.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'jbig2dec/jbig2_arith.c') diff --git a/jbig2dec/jbig2_arith.c b/jbig2dec/jbig2_arith.c index 7567ba1e8..52cc3dbbd 100644 --- a/jbig2dec/jbig2_arith.c +++ b/jbig2dec/jbig2_arith.c @@ -263,7 +263,7 @@ jbig2_arith_renormd(Jbig2ArithState *as) } bool -jbig2_arith_decode(Jbig2ArithState *as, Jbig2ArithCx *pcx) +jbig2_arith_decode(Jbig2ArithState *as, Jbig2ArithCx *pcx, int *code) { Jbig2ArithCx cx = *pcx; const Jbig2ArithQe *pqe; @@ -271,7 +271,8 @@ jbig2_arith_decode(Jbig2ArithState *as, Jbig2ArithCx *pcx) bool D; if (index >= MAX_QE_ARRAY_SIZE) { - return -1; + *code = -1; + return 0; } else { pqe = &jbig2_arith_Qe[index]; } @@ -354,6 +355,7 @@ main(int argc, char **argv) Jbig2ArithState *as; int i; Jbig2ArithCx cx = 0; + int code; ctx = jbig2_ctx_new(NULL, 0, NULL, NULL, NULL); @@ -369,7 +371,7 @@ main(int argc, char **argv) #else (void) #endif - jbig2_arith_decode(as, &cx); + jbig2_arith_decode(as, &cx, &code); #ifdef JBIG2_DEBUG_ARITH fprintf(stderr, "%3d: D = %d, ", i, D); -- cgit v1.2.1