From 9196b5c2b80d606f09cde523b1931d6c9c921692 Mon Sep 17 00:00:00 2001 From: "Sven M. Hallberg" <pesco@khjk.org> Date: Thu, 30 Mar 2023 13:40:42 +0000 Subject: [PATCH] drop use of h_seek in parse_xrefs Now that we are validating the offset ourselves, we no longer need h_seek() to do our bounds checking. But add a defensive assert just in case. --- pdf.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pdf.c b/pdf.c index 4e159a3..c1652fb 100644 --- a/pdf.c +++ b/pdf.c @@ -4986,10 +4986,8 @@ parse_xrefs(const uint8_t *input, size_t sz, size_t *nxrefs) // XXX try formulating this loop as one parser using h_seek and h_bind for (;;) { - //res = h_parse(p_xref, input + offset, sz - offset); - HParser *p = h_right(h_seek(offset * 8, SEEK_SET), p_xref); - // XXX ^ creating any number of parsers we never free - res = h_parse(p, input, sz); + assert(offset <= sz); + res = h_parse(p_xref, input + offset, sz - offset); if (res == NULL || res->ast == NULL || H_INDEX_TOKEN(res->ast, 0) == NULL) { log_message(5, "VIOLATION[5]: error parsing xref section at " "position %zu (%#zx)\n", offset, offset); -- GitLab