diff options
author | Robin Watts <robin.watts@artifex.com> | 2011-12-16 19:15:43 +0000 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2011-12-16 19:15:43 +0000 |
commit | 42cb763c9ce52e671c681a9321a5e1b5741c9caf (patch) | |
tree | 7956292ef432abe4ca1c9bc0e5653370f093321c | |
parent | 40ba2101c5b3c49379dd6997ceccf9256a7efe69 (diff) | |
download | mupdf-42cb763c9ce52e671c681a9321a5e1b5741c9caf.tar.xz |
More MemSqueezing fixes.
-rw-r--r-- | pdf/pdf_colorspace.c | 53 | ||||
-rw-r--r-- | pdf/pdf_function.c | 4 | ||||
-rw-r--r-- | pdf/pdf_shade.c | 7 |
3 files changed, 45 insertions, 19 deletions
diff --git a/pdf/pdf_colorspace.c b/pdf/pdf_colorspace.c index 0efcd13a..4ebf7826 100644 --- a/pdf/pdf_colorspace.c +++ b/pdf/pdf_colorspace.c @@ -94,15 +94,18 @@ static fz_colorspace * load_separation(pdf_xref *xref, fz_obj *array) { fz_colorspace *cs; - struct separation *sep; + struct separation *sep = NULL; fz_context *ctx = xref->ctx; fz_obj *nameobj = fz_array_get(array, 1); fz_obj *baseobj = fz_array_get(array, 2); fz_obj *tintobj = fz_array_get(array, 3); fz_colorspace *base; - pdf_function *tint; + pdf_function *tint = NULL; int n; + fz_var(tint); + fz_var(sep); + if (fz_is_array(nameobj)) n = fz_array_len(nameobj); else @@ -114,19 +117,29 @@ load_separation(pdf_xref *xref, fz_obj *array) base = pdf_load_colorspace(xref, baseobj); /* RJW: "cannot load base colorspace (%d %d R)", fz_to_num(baseobj), fz_to_gen(baseobj) */ - tint = pdf_load_function(xref, tintobj); - /* RJW: fz_drop_colorspace(ctx, base); - * "cannot load tint function (%d %d R)", fz_to_num(tintobj), fz_to_gen(tintobj) */ - - sep = fz_malloc_struct(ctx, struct separation); - sep->base = base; - sep->tint = tint; - - cs = fz_new_colorspace(ctx, n == 1 ? "Separation" : "DeviceN", n); - cs->to_rgb = separation_to_rgb; - cs->free_data = free_separation; - cs->data = sep; - cs->size += sizeof(struct separation) + (base ? base->size : 0) + pdf_function_size(tint); + fz_try(ctx) + { + tint = pdf_load_function(xref, tintobj); + /* RJW: fz_drop_colorspace(ctx, base); + * "cannot load tint function (%d %d R)", fz_to_num(tintobj), fz_to_gen(tintobj) */ + + sep = fz_malloc_struct(ctx, struct separation); + sep->base = base; + sep->tint = tint; + + cs = fz_new_colorspace(ctx, n == 1 ? "Separation" : "DeviceN", n); + cs->to_rgb = separation_to_rgb; + cs->free_data = free_separation; + cs->data = sep; + cs->size += sizeof(struct separation) + (base ? base->size : 0) + pdf_function_size(tint); + } + fz_catch(ctx) + { + fz_drop_colorspace(ctx, base); + pdf_drop_function(ctx, tint); + fz_free(ctx, sep); + fz_rethrow(ctx); + } return cs; } @@ -371,7 +384,15 @@ pdf_load_colorspace(pdf_xref *xref, fz_obj *obj) cs = pdf_load_colorspace_imp(xref, obj); /* RJW: "cannot load colorspace (%d %d R)", fz_to_num(obj), fz_to_gen(obj) */ - fz_store_item(ctx, obj, cs, cs->size); + fz_try(ctx) + { + fz_store_item(ctx, obj, cs, cs->size); + } + fz_catch(ctx) + { + fz_drop_colorspace(ctx, cs); + fz_rethrow(ctx); + } return cs; } diff --git a/pdf/pdf_function.c b/pdf/pdf_function.c index 347c8db2..942023e7 100644 --- a/pdf/pdf_function.c +++ b/pdf/pdf_function.c @@ -1417,6 +1417,8 @@ pdf_load_function(pdf_xref *xref, fz_obj *dict) fz_free(ctx, func); fz_throw(ctx, "unknown function type (%d %d R)", fz_to_num(dict), fz_to_gen(dict)); } + + fz_store_item(ctx, dict, func, func->size); } fz_catch(ctx) { @@ -1429,8 +1431,6 @@ pdf_load_function(pdf_xref *xref, fz_obj *dict) "unknown")))), fz_to_num(dict), fz_to_gen(dict)); } - fz_store_item(ctx, dict, func, func->size); - return func; } diff --git a/pdf/pdf_shade.c b/pdf/pdf_shade.c index a2f0e945..6b26d6b1 100644 --- a/pdf/pdf_shade.c +++ b/pdf/pdf_shade.c @@ -1022,7 +1022,8 @@ pdf_load_shading_dict(pdf_xref *xref, fz_obj *dict, fz_matrix transform) funcs = 1; func[0] = pdf_load_function(xref, obj); - /* RJW: "cannot load shading function (%d %d R)", fz_to_num(obj), fz_to_gen(obj) */ + if (!func[0]) + fz_throw(ctx, "cannot load shading function (%d %d R)", fz_to_num(obj), fz_to_gen(obj)); } else if (fz_is_array(obj)) { @@ -1037,6 +1038,10 @@ pdf_load_shading_dict(pdf_xref *xref, fz_obj *dict, fz_matrix transform) fz_throw(ctx, "cannot load shading function (%d %d R)", fz_to_num(obj), fz_to_gen(obj)); } } + else + { + fz_throw(ctx, "cannot load shading function (%d %d R)", fz_to_num(obj), fz_to_gen(obj)); + } if (type >= 4 && type <= 7) { |