/* * Build a filter for reading raw stream data. * This is a null filter to constrain reading to the * stream length, followed by a decryption filter. */ static fz_stream * pdf_open_raw_filter(fz_stream *chain, pdf_document *xref, pdf_obj *stmobj, int num, int gen) { int hascrypt; int len; fz_context *ctx = chain->ctx; /* don't close chain when we close this filter */ fz_keep_stream(chain); len = pdf_to_int(pdf_dict_gets(stmobj, "Length")); chain = fz_open_null(chain, len); fz_try(ctx) { hascrypt = pdf_stream_has_crypt(ctx, stmobj); if (xref->crypt && !hascrypt) chain = pdf_open_crypt(chain, xref->crypt, num, gen); } fz_catch(ctx) { fz_close(chain); fz_rethrow(ctx); } return chain; }
/* * Build a filter for reading raw stream data. * This is a null filter to constrain reading to the stream length (and to * allow for other people accessing the file), followed by a decryption * filter. * * orig_num and orig_gen are used purely to seed the encryption. */ static fz_stream * pdf_open_raw_filter(fz_context *ctx, fz_stream *chain, pdf_document *doc, pdf_obj *stmobj, int num, int orig_num, int orig_gen, int offset) { int hascrypt; int len; if (num > 0 && num < pdf_xref_len(ctx, doc)) { pdf_xref_entry *entry = pdf_get_xref_entry(ctx, doc, num); if (entry->stm_buf) return fz_open_buffer(ctx, entry->stm_buf); } /* don't close chain when we close this filter */ fz_keep_stream(ctx, chain); len = pdf_to_int(ctx, pdf_dict_get(ctx, stmobj, PDF_NAME_Length)); chain = fz_open_null(ctx, chain, len, offset); hascrypt = pdf_stream_has_crypt(ctx, stmobj); if (doc->crypt && !hascrypt) chain = pdf_open_crypt(ctx, chain, doc->crypt, orig_num, orig_gen); return chain; }
/* * Build a filter for reading raw stream data. * This is a null filter to constrain reading to the stream length (and to * allow for other people accessing the file), followed by a decryption * filter. * * orig_num and orig_gen are used purely to seed the encryption. */ static fz_stream * pdf_open_raw_filter(fz_context *ctx, fz_stream *chain, pdf_document *doc, pdf_obj *stmobj, int num, int *orig_num, int *orig_gen, fz_off_t offset) { pdf_xref_entry *x = NULL; int hascrypt; int len; if (num > 0 && num < pdf_xref_len(ctx, doc)) { x = pdf_get_xref_entry(ctx, doc, num); *orig_num = x->num; *orig_gen = x->gen; if (x->stm_buf) return fz_open_buffer(ctx, x->stm_buf); } else { /* We only end up here when called from pdf_open_stream_with_offset to parse new format XRef sections. */ /* New style XRef sections must have generation number 0. */ *orig_num = num; *orig_gen = 0; } /* don't close chain when we close this filter */ fz_keep_stream(ctx, chain); len = pdf_to_int(ctx, pdf_dict_get(ctx, stmobj, PDF_NAME_Length)); chain = fz_open_null(ctx, chain, len, offset); hascrypt = pdf_stream_has_crypt(ctx, stmobj); if (doc->crypt && !hascrypt) chain = pdf_open_crypt(ctx, chain, doc->crypt, *orig_num, *orig_gen); return chain; }
/* * Build a filter for reading raw stream data. * This is a null filter to constrain reading to the * stream length, followed by a decryption filter. */ static fz_stream * pdf_open_raw_filter(fz_stream *chain, pdf_xref *xref, fz_obj *stmobj, int num, int gen) { int hascrypt; int len; /* don't close chain when we close this filter */ fz_keep_stream(chain); len = fz_to_int(fz_dict_gets(stmobj, "Length")); chain = fz_open_null(chain, len); hascrypt = pdf_stream_has_crypt(stmobj); if (xref->crypt && !hascrypt) chain = pdf_open_crypt(chain, xref->crypt, num, gen); return chain; }
/* * Construct a filter to decode a stream, without * constraining to stream length, and without decryption. */ fz_stream * pdf_open_inline_stream(pdf_document *xref, pdf_obj *stmobj, int length, fz_stream *chain, pdf_image_params *imparams) { pdf_obj *filters; pdf_obj *params; filters = pdf_dict_getsa(stmobj, "Filter", "F"); params = pdf_dict_getsa(stmobj, "DecodeParms", "DP"); /* don't close chain when we close this filter */ fz_keep_stream(chain); if (pdf_is_name(filters)) return build_filter(chain, xref, filters, params, 0, 0, imparams); if (pdf_array_len(filters) > 0) return build_filter_chain(chain, xref, filters, params, 0, 0, imparams); return fz_open_null(chain, length); }
/* * Construct a filter to decode a stream, without * constraining to stream length, and without decryption. */ fz_stream * pdf_open_inline_stream(fz_stream *chain, pdf_xref *xref, fz_obj *stmobj, int length) { fz_obj *filters; fz_obj *params; filters = fz_dict_getsa(stmobj, "Filter", "F"); params = fz_dict_getsa(stmobj, "DecodeParms", "DP"); /* don't close chain when we close this filter */ fz_keep_stream(chain); if (fz_is_name(filters)) return build_filter(chain, xref, filters, params, 0, 0); if (fz_array_len(filters) > 0) return build_filter_chain(chain, xref, filters, params, 0, 0); return fz_open_null(chain, length); }
/* * Construct a filter to decode a stream, without * constraining to stream length, and without decryption. */ fz_stream * pdf_open_inline_stream(fz_context *ctx, pdf_document *doc, pdf_obj *stmobj, int length, fz_stream *chain, fz_compression_params *imparams) { pdf_obj *filters; pdf_obj *params; filters = pdf_dict_geta(ctx, stmobj, PDF_NAME_Filter, PDF_NAME_F); params = pdf_dict_geta(ctx, stmobj, PDF_NAME_DecodeParms, PDF_NAME_DP); /* don't close chain when we close this filter */ fz_keep_stream(ctx, chain); if (pdf_is_name(ctx, filters)) return build_filter(ctx, chain, doc, filters, params, 0, 0, imparams); if (pdf_array_len(ctx, filters) > 0) return build_filter_chain(ctx, chain, doc, filters, params, 0, 0, imparams); if (imparams) imparams->type = FZ_IMAGE_RAW; return fz_open_null(ctx, chain, length, fz_tell(ctx, chain)); }