From ddd984215a2a9258682e4413b5911c4b135802ce Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Wed, 15 Nov 2023 08:38:47 -0500 Subject: [PATCH] Save work (debug printfs, etc.) --- pdfio-common.c | 4 ++-- pdfio-file.c | 15 +++++++++++++-- pdfio-stream.c | 2 ++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/pdfio-common.c b/pdfio-common.c index bc23fd0..62a7190 100644 --- a/pdfio-common.c +++ b/pdfio-common.c @@ -375,9 +375,9 @@ _pdfioFileSeek(pdfio_file_t *pdf, // I - PDF file if (whence != SEEK_END && offset >= pdf->bufpos && offset < (pdf->bufpos + pdf->bufend - pdf->buffer)) { // Yes, seek within existing buffer... - pdf->bufptr = pdf->buffer + offset - pdf->bufpos; + pdf->bufptr = pdf->buffer + (offset - pdf->bufpos); PDFIO_DEBUG("_pdfioFileSeek: Seek within buffer, bufpos=%ld.\n", (long)pdf->bufpos); - PDFIO_DEBUG("_pdfioFileSeek: buffer=%p, bufptr=%p, bufend=%p\n", pdf->buffer, pdf->bufptr, pdf->bufend); + PDFIO_DEBUG("_pdfioFileSeek: buffer=%p, bufptr=%p(<%02X%02X...>), bufend=%p\n", pdf->buffer, pdf->bufptr, pdf->bufptr[0] & 255, pdf->bufptr[1] & 255, pdf->bufend); return (offset); } diff --git a/pdfio-file.c b/pdfio-file.c index 55d9710..08c740e 100644 --- a/pdfio-file.c +++ b/pdfio-file.c @@ -1514,6 +1514,7 @@ load_obj_stream(pdfio_obj_t *obj) // I - Object to load // Skip offset _pdfioTokenGet(&tb, buffer, sizeof(buffer)); + PDFIO_DEBUG("load_obj_stream: %ld at offset %s\n", (long)number, buffer); } if (!buffer[0]) @@ -1865,8 +1866,18 @@ load_xref( break; } - if (i >= num_sobjs && num_sobjs < (sizeof(sobjs) / sizeof(sobjs[0]))) - sobjs[num_sobjs ++] = (size_t)offset; + if (i >= num_sobjs) + { + if (num_sobjs < (sizeof(sobjs) / sizeof(sobjs[0]))) + { + sobjs[num_sobjs ++] = (size_t)offset; + } + else + { + _pdfioFileError(pdf, "Too many object streams."); + return (false); + } + } } else if (!current) { diff --git a/pdfio-stream.c b/pdfio-stream.c index 15cced7..b62e237 100644 --- a/pdfio-stream.c +++ b/pdfio-stream.c @@ -452,6 +452,7 @@ _pdfioStreamOpen(pdfio_obj_t *obj, // I - Object return (NULL); } + PDFIO_DEBUG("_pdfioStreamOpen: ivlen=%d\n", (int)ivlen); if (ivlen > 0) _pdfioFileConsume(st->pdf, ivlen); @@ -567,6 +568,7 @@ _pdfioStreamOpen(pdfio_obj_t *obj, // I - Object else st->predictor = _PDFIO_PREDICTOR_NONE; + PDFIO_DEBUG("_pdfioStreamOpen: pos=%ld\n", (long)_pdfioFileTell(st->pdf)); if (sizeof(st->cbuffer) > st->remaining) rbytes = _pdfioFileRead(st->pdf, st->cbuffer, st->remaining); else