| 2739 | } |
| 2740 | |
| 2741 | const unsigned char *pdf_stream_decode(pdf_doc_t *d, pdf_stream_t *st, size_t *len) { |
| 2742 | if (st->done) { |
| 2743 | *len = st->dec_len; |
| 2744 | return st->decoded; |
| 2745 | } |
| 2746 | st->done = true; |
| 2747 | st->decoded = NULL; |
| 2748 | st->dec_len = 0; |
| 2749 | *len = 0; |
| 2750 | pdf_buf_t held = {0}; |
| 2751 | size_t cur_len; |
| 2752 | const unsigned char *cur = decode_filters(d, st, &cur_len, &held); |
| 2753 | if (!cur) { |
| 2754 | return NULL; |
| 2755 | } |
| 2756 | if (held.p) { |
| 2757 | unsigned char *fit = |
| 2758 | (unsigned char *)cbm_realloc(CBM_MEM_CLASS_EXTRACT, held.p, held.n ? held.n : 1); |
| 2759 | if (fit) { |
| 2760 | held.p = fit; |
| 2761 | } |
| 2762 | if (!pdf_own(d, held.p)) { |
| 2763 | return NULL; |
| 2764 | } |
| 2765 | cur = held.p; |
| 2766 | } |
| 2767 | st->decoded = cur; |
| 2768 | st->dec_len = cur_len; |
| 2769 | *len = cur_len; |
| 2770 | return cur; |
| 2771 | } |
no test coverage detected