From 3844abdf92d3869a3145dbfb84e8a2ecf1518432 Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Mon, 21 Jun 2021 16:18:06 -0400 Subject: [PATCH] Fix reading of streams with indirect lengths. --- pdfio-stream.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pdfio-stream.c b/pdfio-stream.c index 23944ec..e3b03a5 100644 --- a/pdfio-stream.c +++ b/pdfio-stream.c @@ -325,6 +325,8 @@ _pdfioStreamOpen(pdfio_obj_t *obj, // I - Object // Object dictionary + PDFIO_DEBUG("_pdfioStreamOpen(obj=%p(%u), decode=%s)\n", obj, (unsigned)obj->number, decode ? "true" : "false"); + // Allocate a new stream object... if ((st = (pdfio_stream_t *)calloc(1, sizeof(pdfio_stream_t))) == NULL) { @@ -335,13 +337,13 @@ _pdfioStreamOpen(pdfio_obj_t *obj, // I - Object st->pdf = obj->pdf; st->obj = obj; - if (_pdfioFileSeek(st->pdf, obj->stream_offset, SEEK_SET) != obj->stream_offset) + if ((st->remaining = pdfioObjGetLength(obj)) == 0) { free(st); return (NULL); } - if ((st->remaining = pdfioObjGetLength(obj)) == 0) + if (_pdfioFileSeek(st->pdf, obj->stream_offset, SEEK_SET) != obj->stream_offset) { free(st); return (NULL); @@ -448,7 +450,7 @@ _pdfioStreamOpen(pdfio_obj_t *obj, // I - Object st->flate.next_in = (Bytef *)st->cbuffer; st->flate.avail_in = (uInt)_pdfioFileRead(st->pdf, st->cbuffer, sizeof(st->cbuffer)); - PDFIO_DEBUG("_pdfioStreamOpen: avail_in=%u\n", st->flate.avail_in); + PDFIO_DEBUG("_pdfioStreamOpen: avail_in=%u, cbuffer=<%02X%02X%02X%02X%02X%02X%02X%02X...>\n", st->flate.avail_in, st->cbuffer[0], st->cbuffer[1], st->cbuffer[2], st->cbuffer[3], st->cbuffer[4], st->cbuffer[5], st->cbuffer[6], st->cbuffer[7]); if (inflateInit(&(st->flate)) != Z_OK) {