| 811 | } |
| 812 | |
| 813 | pdf_val_t *pdf_parse_value(pdf_doc_t *d, const unsigned char *data, size_t len, size_t *pos, |
| 814 | const pdf_tok_t *t, int depth) { |
| 815 | if (depth > PDF_MAX_NESTING || d->nomem) { |
| 816 | return NULL; |
| 817 | } |
| 818 | switch (t->kind) { |
| 819 | case PT_NUM: |
| 820 | if (t->is_int) { |
| 821 | size_t p2 = *pos; |
| 822 | pdf_tok_t t2; |
| 823 | lex_peek(d, data, len, &p2, &t2); |
| 824 | if (t2.kind == PT_NUM && t2.is_int) { |
| 825 | pdf_tok_t t3; |
| 826 | lex_peek(d, data, len, &p2, &t3); |
| 827 | if (pdf_kw_is(&t3, "R")) { |
| 828 | pdf_val_t *r = new_val(d, PV_REF); |
| 829 | if (r) { |
| 830 | r->ref_num = t->inum; |
| 831 | r->ref_gen = t2.inum; |
| 832 | *pos = p2; |
| 833 | } |
| 834 | return r; |
| 835 | } |
| 836 | } |
| 837 | } |
| 838 | return val_from_tok(d, t); |
| 839 | case PT_NAME: |
| 840 | case PT_STR: |
| 841 | return val_from_tok(d, t); |
| 842 | case PT_AS: { |
| 843 | val_list_t l = {0}; |
| 844 | for (;;) { |
| 845 | pdf_tok_t a; |
| 846 | pdf_lex(d, data, len, pos, &a); |
| 847 | if (a.kind == PT_AE || a.kind == PT_EOF) { |
| 848 | break; |
| 849 | } |
| 850 | if (a.kind == PT_DE || a.kind == PT_BE || a.kind == PT_BS) { |
| 851 | continue; |
| 852 | } |
| 853 | if (a.kind == PT_KW && kw_ends_value(&a)) { |
| 854 | break; |
| 855 | } |
| 856 | pdf_val_t *x = pdf_parse_value(d, data, len, pos, &a, depth + 1); |
| 857 | if (!x) { |
| 858 | cbm_free(CBM_MEM_CLASS_EXTRACT, (void *)l.v); |
| 859 | return NULL; |
| 860 | } |
| 861 | vl_push(&l, x); |
| 862 | } |
| 863 | return vl_finish_array(d, &l); |
| 864 | } |
| 865 | case PT_DS: { |
| 866 | kv_list_t l = {0}; |
| 867 | for (;;) { |
| 868 | size_t save = *pos; |
| 869 | pdf_tok_t k; |
| 870 | pdf_lex(d, data, len, pos, &k); |
no test coverage detected