summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorPaul Gardiner <paul.gardiner@artifex.com>2018-01-22 16:48:33 +0000
committerPaul Gardiner <paul.gardiner@artifex.com>2018-02-02 12:36:13 +0000
commit8ac8d47f25b2868d464be71ed3b9ed04b71cb524 (patch)
treed4acf63922f608b0710127ed98e8406824090eca /source
parent37e3d2aac1a3493171b28aa5c7344833aa5a8303 (diff)
downloadmupdf-8ac8d47f25b2868d464be71ed3b9ed04b71cb524.tar.xz
Generalise the null filter to handle more than a single range.
This is needed to simplify the way the bytes for hashing are passed to pkcs7 functions.
Diffstat (limited to 'source')
-rw-r--r--source/fitz/filter-basic.c40
1 files changed, 35 insertions, 5 deletions
diff --git a/source/fitz/filter-basic.c b/source/fitz/filter-basic.c
index b64d8b66..e5d7a4e4 100644
--- a/source/fitz/filter-basic.c
+++ b/source/fitz/filter-basic.c
@@ -15,6 +15,9 @@ fz_open_copy(fz_context *ctx, fz_stream *chain)
struct null_filter
{
fz_stream *chain;
+ fz_range *ranges;
+ int nranges;
+ int next_range;
size_t remain;
int64_t offset;
unsigned char buffer[4096];
@@ -26,6 +29,13 @@ next_null(fz_context *ctx, fz_stream *stm, size_t max)
struct null_filter *state = stm->state;
size_t n;
+ while (state->remain == 0 && state->next_range < state->nranges)
+ {
+ fz_range *range = &state->ranges[state->next_range++];
+ state->remain = range->len;
+ state->offset = range->offset;
+ }
+
if (state->remain == 0)
return EOF;
fz_seek(ctx, state->chain, state->offset, 0);
@@ -51,26 +61,32 @@ close_null(fz_context *ctx, void *state_)
{
struct null_filter *state = (struct null_filter *)state_;
fz_stream *chain = state->chain;
+ fz_free(ctx, state->ranges);
fz_free(ctx, state);
fz_drop_stream(ctx, chain);
}
fz_stream *
-fz_open_null(fz_context *ctx, fz_stream *chain, int len, int64_t offset)
+fz_open_null_n(fz_context *ctx, fz_stream *chain, fz_range *ranges, int nranges)
{
struct null_filter *state = NULL;
- if (len < 0)
- len = 0;
+ fz_var(state);
fz_try(ctx)
{
state = fz_malloc_struct(ctx, struct null_filter);
+ state->ranges = fz_calloc(ctx, nranges, sizeof(*ranges));
+ memcpy(state->ranges, ranges, nranges * sizeof(*ranges));
+ state->nranges = nranges;
+ state->next_range = 1;
state->chain = chain;
- state->remain = len;
- state->offset = offset;
+ state->remain = nranges ? ranges[0].len : 0;
+ state->offset = nranges ? ranges[0].offset : 0;
}
fz_catch(ctx)
{
+ fz_free(ctx, state->ranges);
+ fz_free(ctx, state);
fz_drop_stream(ctx, chain);
fz_rethrow(ctx);
}
@@ -78,6 +94,20 @@ fz_open_null(fz_context *ctx, fz_stream *chain, int len, int64_t offset)
return fz_new_stream(ctx, state, next_null, close_null);
}
+fz_stream *
+fz_open_null(fz_context *ctx, fz_stream *chain, int len, int64_t offset)
+{
+ fz_range range;
+
+ if (len < 0)
+ len = 0;
+
+ range.offset = offset;
+ range.len = len;
+ return fz_open_null_n(ctx, chain, &range, 1);
+}
+
+
/* Concat filter concatenates several streams into one */
struct concat_filter