Every "N G obj" header in file order (the reconstruction and the fallback * for objects missing at their offset both read it). */
| 1263 | /* Every "N G obj" header in file order (the reconstruction and the fallback |
| 1264 | * for objects missing at their offset both read it). */ |
| 1265 | static bool build_hdrs(pdf_doc_t *d) { |
| 1266 | if (d->hdrs_built) { |
| 1267 | return true; |
| 1268 | } |
| 1269 | d->hdrs_built = true; |
| 1270 | const unsigned char *s = d->data; |
| 1271 | size_t len = d->len; |
| 1272 | int cap = 0; |
| 1273 | size_t from = 0; |
| 1274 | while (from + 3 <= len) { |
| 1275 | const unsigned char *o = cbm_memmem(s + from, len - from, "obj", 3); |
| 1276 | if (!o) { |
| 1277 | break; |
| 1278 | } |
| 1279 | size_t q = (size_t)(o - s); |
| 1280 | from = q + 3; |
| 1281 | size_t p = q; |
| 1282 | while (p > 0 && is_ws(s[p - 1])) { |
| 1283 | p--; |
| 1284 | } |
| 1285 | if (p == q) { |
| 1286 | continue; |
| 1287 | } |
| 1288 | size_t ge = p; |
| 1289 | while (p > 0 && is_digit(s[p - 1])) { |
| 1290 | p--; |
| 1291 | } |
| 1292 | size_t gs = p; |
| 1293 | if (gs == ge) { |
| 1294 | continue; |
| 1295 | } |
| 1296 | size_t w = p; |
| 1297 | while (p > 0 && is_ws(s[p - 1])) { |
| 1298 | p--; |
| 1299 | } |
| 1300 | if (p == w) { |
| 1301 | continue; |
| 1302 | } |
| 1303 | size_t ne = p; |
| 1304 | while (p > 0 && is_digit(s[p - 1])) { |
| 1305 | p--; |
| 1306 | } |
| 1307 | size_t ns = p; |
| 1308 | if (ns == ne) { |
| 1309 | continue; |
| 1310 | } |
| 1311 | if (d->nhdrs == cap) { |
| 1312 | int ncap = cap ? cap * 2 : PDF_MAP_MIN; |
| 1313 | pdf_hdr_t *g = |
| 1314 | (pdf_hdr_t *)cbm_realloc(CBM_MEM_CLASS_EXTRACT, d->hdrs, (size_t)ncap * sizeof(*g)); |
| 1315 | if (!g) { |
| 1316 | d->nomem = true; |
| 1317 | return false; |
| 1318 | } |
| 1319 | d->hdrs = g; |
| 1320 | cap = ncap; |
| 1321 | } |
| 1322 | pdf_hdr_t *h = &d->hdrs[d->nhdrs++]; |
no test coverage detected