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

Function xref_stream_at

internal/cbm/pdf/pdf_obj.c:1755–1805  ·  view source on GitHub ↗

A cross-reference stream at off into sec. Its decoded bytes are freed once * read: a stream parsed here is no cached object, and keeping them made every * section that names one stream add a copy until the document closed. */

Source from the content-addressed store, hash-verified

1753 * read: a stream parsed here is no cached object, and keeping them made every
1754 * section that names one stream add a copy until the document closed. */
1755static bool xref_stream_at(pdf_doc_t *d, int64_t off, pdf_xref_t *sec, pdf_val_t **tr) {
1756 bool ok;
1757 pdf_val_t *v = parse_indirect_at(d, off, false, 0, &ok);
1758 if (!v || v->kind != PV_STREAM) {
1759 return false;
1760 }
1761 pdf_val_t *dict = v->stream->dict;
1762 pdf_val_t *W = pdf_dget_raw(dict, "W");
1763 if (!W || W->kind != PV_ARR || W->count != 3) {
1764 return false;
1765 }
1766 int64_t w[3];
1767 for (int i = 0; i < 3; i++) {
1768 if (!num_to_int(W->items[i], &w[i]) || w[i] < 0 || w[i] > PDF_MAX_FIELD) {
1769 return false;
1770 }
1771 }
1772 pdf_val_t *size = pdf_dget_raw(dict, "Size");
1773 pdf_val_t *index = pdf_dget_raw(dict, "Index");
1774 bool dflt = !index || (index->kind == PV_ARR && index->count == 0) ||
1775 (index->kind == PV_NUM && index->num == 0.0) ||
1776 (index->kind == PV_BOOL && !index->b);
1777 int64_t pairs[2] = {0, 0}; /* read only on the default /Index (no items) */
1778 pdf_val_t **items = NULL;
1779 int nitems = 0;
1780 if (dflt) {
1781 if (size && !num_to_int(size, &pairs[1])) {
1782 return false;
1783 }
1784 nitems = 2;
1785 } else if (index->kind == PV_ARR) {
1786 items = index->items;
1787 nitems = index->count;
1788 } else {
1789 return false;
1790 }
1791 size_t rlen = 0;
1792 pdf_buf_t held = {0};
1793 const unsigned char *raw = decode_filters(d, v->stream, &rlen, &held);
1794 if (!raw) {
1795 return false;
1796 }
1797 d->counts->xref_streams++;
1798 bool rows_ok = xref_rows(d, sec, raw, rlen, w, items, nitems, pairs);
1799 buf_free(&held);
1800 if (!rows_ok) {
1801 return false;
1802 }
1803 *tr = dict;
1804 return true;
1805}
1806
1807static size_t skip_ws(const pdf_doc_t *d, size_t p) {
1808 while (p < d->len && is_ws(d->data[p])) {

Callers 1

load_xrefFunction · 0.85

Calls 6

parse_indirect_atFunction · 0.85
pdf_dget_rawFunction · 0.85
num_to_intFunction · 0.85
decode_filtersFunction · 0.85
xref_rowsFunction · 0.85
buf_freeFunction · 0.85

Tested by

no test coverage detected