MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / reconstruct

Function reconstruct

internal/cbm/pdf/pdf_obj.c:2006–2124  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2004}
2005
2006static void reconstruct(pdf_doc_t *d) {
2007 d->reconstructed = true;
2008 d->counts->xref_reconstructed++;
2009 xref_free(&d->xref);
2010 if (!build_hdrs(d)) {
2011 return;
2012 }
2013 for (int i = 0; i < d->nhdrs; i++) {
2014 const pdf_hdr_t *h = &d->hdrs[i];
2015 if (h->num_digits > 10 || h->gen_digits > 5 || h->reg_after) {
2016 continue;
2017 }
2018 bool fresh;
2019 pdf_xent_t *e = xref_slot(d, &d->xref, h->num, &fresh);
2020 if (!e) {
2021 return;
2022 }
2023 e->type = 1;
2024 e->a = (int64_t)h->off;
2025 e->b = h->gen;
2026 }
2027 /* every "trailer[ws]*<<" dict, the later overriding */
2028 const unsigned char *s = d->data;
2029 size_t len = d->len;
2030 kv_list_t trail = {0};
2031 size_t from = 0;
2032 while (from + 7 <= len) {
2033 const unsigned char *x = cbm_memmem(s + from, len - from, "trailer", 7);
2034 if (!x) {
2035 break;
2036 }
2037 size_t q = (size_t)(x - s) + 7;
2038 from = q;
2039 q = skip_ws(d, q);
2040 if (!starts_with(d, q, "<<")) {
2041 continue;
2042 }
2043 size_t p = q;
2044 pdf_tok_t t;
2045 /* read up to the next "trailer": scanned trailers do not overlap either */
2046 const unsigned char *nx = cbm_memmem(s + q, len - q, "trailer", 7);
2047 size_t tlen = nx ? (size_t)(nx - s) : len;
2048 pdf_lex(d, s, tlen, &p, &t);
2049 pdf_val_t *v = pdf_parse_value(d, s, tlen, &p, &t, 0);
2050 if (v && v->kind == PV_DICT) {
2051 for (int k = 0; k < v->nkv; k++) {
2052 kl_push(&trail, v->kv[k].key, v->kv[k].klen, v->kv[k].val);
2053 }
2054 }
2055 from = q + 2 > from ? q + 2 : from;
2056 }
2057 pdf_val_t *tr = kl_finish_dict(d, &trail, true);
2058 static const char *const xkeys[] = {"Root", "Info", "ID", "Encrypt"};
2059 bool taken[4] = {false, false, false, false};
2060 kv_list_t extra = {0};
2061 int n = 0;
2062 int64_t *nums = xref_sorted_nums(d, &n);
2063 for (int i = 0; i < n; i++) {

Callers 1

pdf_doc_openFunction · 0.85

Calls 15

xref_freeFunction · 0.85
build_hdrsFunction · 0.85
xref_slotFunction · 0.85
cbm_memmemFunction · 0.85
pdf_lexFunction · 0.85
pdf_parse_valueFunction · 0.85
kl_pushFunction · 0.85
kl_finish_dictFunction · 0.85
xref_sorted_numsFunction · 0.85
pdf_getFunction · 0.85
pdf_dget_rawFunction · 0.85
pdf_is_nameFunction · 0.85

Tested by

no test coverage detected