summaryrefslogtreecommitdiff
path: root/source/fitz/filter-predict.c
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2018-03-28 15:17:27 +0200
committerTor Andersson <tor.andersson@artifex.com>2018-04-03 21:21:44 +0200
commitef3cfb2a49b5be82d56d783f505319754dc65cb8 (patch)
treef299436312d6230c08289b61e9bad51a4dd31681 /source/fitz/filter-predict.c
parentd9f0fdfe1ac986816a3376ee0271f84fb549b0bf (diff)
downloadmupdf-ef3cfb2a49b5be82d56d783f505319754dc65cb8.tar.xz
Don't implicitly drop in fz_open_* chained filters.
Diffstat (limited to 'source/fitz/filter-predict.c')
-rw-r--r--source/fitz/filter-predict.c52
1 files changed, 22 insertions, 30 deletions
diff --git a/source/fitz/filter-predict.c b/source/fitz/filter-predict.c
index 24007bfe..e00e07fd 100644
--- a/source/fitz/filter-predict.c
+++ b/source/fitz/filter-predict.c
@@ -226,9 +226,7 @@ close_predict(fz_context *ctx, void *state_)
fz_stream *
fz_open_predict(fz_context *ctx, fz_stream *chain, int predictor, int columns, int colors, int bpc)
{
- fz_predict *state = NULL;
-
- fz_var(state);
+ fz_predict *state;
if (predictor < 1)
predictor = 1;
@@ -239,34 +237,30 @@ fz_open_predict(fz_context *ctx, fz_stream *chain, int predictor, int columns, i
if (bpc < 1)
bpc = 8;
- fz_try(ctx)
+ if (bpc != 1 && bpc != 2 && bpc != 4 && bpc != 8 && bpc != 16)
+ fz_throw(ctx, FZ_ERROR_GENERIC, "invalid number of bits per component: %d", bpc);
+ if (colors > FZ_MAX_COLORS)
+ fz_throw(ctx, FZ_ERROR_GENERIC, "too many color components (%d > %d)", colors, FZ_MAX_COLORS);
+ if (columns >= INT_MAX / (bpc * colors))
+ fz_throw(ctx, FZ_ERROR_GENERIC, "too many columns lead to an integer overflow (%d)", columns);
+
+ if (predictor != 1 && predictor != 2 &&
+ predictor != 10 && predictor != 11 &&
+ predictor != 12 && predictor != 13 &&
+ predictor != 14 && predictor != 15)
{
- if (bpc != 1 && bpc != 2 && bpc != 4 && bpc != 8 && bpc != 16)
- fz_throw(ctx, FZ_ERROR_GENERIC, "invalid number of bits per component: %d", bpc);
- if (colors > FZ_MAX_COLORS)
- fz_throw(ctx, FZ_ERROR_GENERIC, "too many color components (%d > %d)", colors, FZ_MAX_COLORS);
- if (columns >= INT_MAX / (bpc * colors))
- fz_throw(ctx, FZ_ERROR_GENERIC, "too many columns lead to an integer overflow (%d)", columns);
-
- state = fz_malloc_struct(ctx, fz_predict);
- state->in = NULL;
- state->out = NULL;
- state->chain = chain;
+ fz_warn(ctx, "invalid predictor: %d", predictor);
+ predictor = 1;
+ }
+ state = fz_malloc_struct(ctx, fz_predict);
+ fz_try(ctx)
+ {
state->predictor = predictor;
state->columns = columns;
state->colors = colors;
state->bpc = bpc;
- if (state->predictor != 1 && state->predictor != 2 &&
- state->predictor != 10 && state->predictor != 11 &&
- state->predictor != 12 && state->predictor != 13 &&
- state->predictor != 14 && state->predictor != 15)
- {
- fz_warn(ctx, "invalid predictor: %d", state->predictor);
- state->predictor = 1;
- }
-
state->stride = (state->bpc * state->colors * state->columns + 7) / 8;
state->bpp = (state->bpc * state->colors + 7) / 8;
@@ -277,16 +271,14 @@ fz_open_predict(fz_context *ctx, fz_stream *chain, int predictor, int columns, i
state->wp = state->out;
memset(state->ref, 0, state->stride);
+
+ state->chain = fz_keep_stream(ctx, chain);
}
fz_catch(ctx)
{
- if (state)
- {
- fz_free(ctx, state->in);
- fz_free(ctx, state->out);
- }
+ fz_free(ctx, state->in);
+ fz_free(ctx, state->out);
fz_free(ctx, state);
- fz_drop_stream(ctx, chain);
fz_rethrow(ctx);
}