| 1421 | } |
| 1422 | |
| 1423 | pdf_val_t *pdf_get(pdf_doc_t *d, int64_t num) { |
| 1424 | int64_t idx = pdf_map_get(&d->xref.by_num, (uint64_t)num); |
| 1425 | if (idx < 0) { |
| 1426 | return NULL; |
| 1427 | } |
| 1428 | pdf_xent_t *e = &d->xref.v[idx]; |
| 1429 | if (e->cached) { |
| 1430 | return e->obj; |
| 1431 | } |
| 1432 | if (e->loading) { |
| 1433 | return NULL; |
| 1434 | } |
| 1435 | if (e->type == 2 && d->objstm_opening > 0) { |
| 1436 | /* The objects that open an object stream (its /Length, its filters) are |
| 1437 | * no objects of an object stream (ISO 32000-1, 7.5.7): one that is would |
| 1438 | * open the next stream inside this one, one nested call per stream of a |
| 1439 | * chain. */ |
| 1440 | d->counts->objstm_nested++; |
| 1441 | return NULL; |
| 1442 | } |
| 1443 | e->loading = true; |
| 1444 | uint8_t type = e->type; |
| 1445 | int64_t a = e->a; |
| 1446 | int64_t b = e->b; |
| 1447 | pdf_val_t *obj = NULL; |
| 1448 | if (type == 1) { |
| 1449 | bool ok; |
| 1450 | obj = parse_indirect_at(d, a, true, num, &ok); |
| 1451 | if (!ok && !d->reconstructed) { |
| 1452 | int64_t off = hdr_first_exact(d, num, b); |
| 1453 | if (off >= 0) { |
| 1454 | obj = parse_indirect_at(d, off, true, num, &ok); |
| 1455 | } |
| 1456 | } |
| 1457 | if (!ok) { |
| 1458 | obj = NULL; |
| 1459 | } |
| 1460 | } else if (type == 2) { |
| 1461 | pdf_objstm_t *sm = objstm(d, a); |
| 1462 | if (sm) { |
| 1463 | int64_t off = objstm_find(d, sm, num, b); |
| 1464 | int64_t at = off == INT64_MIN ? -1 : pdf_sat_add(sm->first, off); |
| 1465 | if (at >= 0 && (uint64_t)at <= (uint64_t)sm->len) { |
| 1466 | size_t p = (size_t)at; |
| 1467 | size_t end = member_end(d, sm, (size_t)at); |
| 1468 | pdf_tok_t t; |
| 1469 | pdf_lex(d, sm->data, end, &p, &t); |
| 1470 | obj = pdf_parse_value(d, sm->data, end, &p, &t, 0); |
| 1471 | } |
| 1472 | } |
| 1473 | } |
| 1474 | e = &d->xref.v[idx]; |
| 1475 | e->loading = false; |
| 1476 | e->cached = true; |
| 1477 | e->obj = obj; |
| 1478 | return obj; |
| 1479 | } |
| 1480 |
no test coverage detected