Fix bug with xref stream with no index.

Fix bug with pdfiOStreamPeek not appending new stream data to buffer.

Add more debug printfs for values.
This commit is contained in:
Michael R Sweet 2021-08-24 13:49:43 -04:00
parent 4ec19545f3
commit 6745f785b7
No known key found for this signature in database
GPG Key ID: BE67C75EC81F3244
3 changed files with 24 additions and 15 deletions

View File

@ -1229,7 +1229,7 @@ load_xref(pdfio_file_t *pdf, // I - PDF file
if ((index_array = pdfioDictGetArray(trailer.value.dict, "Index")) != NULL) if ((index_array = pdfioDictGetArray(trailer.value.dict, "Index")) != NULL)
index_count = index_array->num_values; index_count = index_array->num_values;
else else
index_count = 0; index_count = 1;
if ((w_array = pdfioDictGetArray(trailer.value.dict, "W")) == NULL) if ((w_array = pdfioDictGetArray(trailer.value.dict, "W")) == NULL)
{ {

View File

@ -514,7 +514,7 @@ pdfioStreamPeek(pdfio_stream_t *st, // I - Stream
st->bufptr = st->buffer; st->bufptr = st->buffer;
st->bufend = st->buffer + remaining; st->bufend = st->buffer + remaining;
if ((rbytes = stream_read(st, st->bufptr, sizeof(st->buffer) - remaining)) > 0) if ((rbytes = stream_read(st, st->bufend, sizeof(st->buffer) - remaining)) > 0)
{ {
st->bufend += rbytes; st->bufend += rbytes;
remaining += (size_t)rbytes; remaining += (size_t)rbytes;

View File

@ -359,7 +359,18 @@ _pdfioValueRead(pdfio_file_t *pdf, // I - PDF file
// Integer or object ref... // Integer or object ref...
unsigned char *tempptr; // Pointer into buffer unsigned char *tempptr; // Pointer into buffer
PDFIO_DEBUG("_pdfioValueRead: %d bytes left in buffer.\n", (int)(tb->bufend - tb->bufptr)); #ifdef DEBUG
PDFIO_DEBUG("_pdfioValueRead: %d bytes left in buffer: '", (int)(tb->bufend - tb->bufptr));
for (tempptr = tb->bufptr; tempptr < tb->bufend; tempptr ++)
{
if (*tempptr < ' ' || *tempptr == 0x7f)
PDFIO_DEBUG("\\%03o", *tempptr);
else
PDFIO_DEBUG("%c", *tempptr);
}
PDFIO_DEBUG("'.\n");
#endif // DEBUG
if ((tb->bufend - tb->bufptr) < 10) if ((tb->bufend - tb->bufptr) < 10)
{ {
// Fill up buffer... // Fill up buffer...
@ -370,20 +381,18 @@ _pdfioValueRead(pdfio_file_t *pdf, // I - PDF file
if ((bytes = (tb->peek_cb)(tb->cb_data, tb->buffer, sizeof(tb->buffer))) > 0) if ((bytes = (tb->peek_cb)(tb->cb_data, tb->buffer, sizeof(tb->buffer))) > 0)
tb->bufend = tb->buffer + bytes; tb->bufend = tb->buffer + bytes;
PDFIO_DEBUG("_pdfioValueRead: %d bytes now left in buffer.\n", (int)(tb->bufend - tb->bufptr));
}
#ifdef DEBUG #ifdef DEBUG
PDFIO_DEBUG("_pdfioValueRead: Bytes are '"); PDFIO_DEBUG("_pdfioValueRead: %d bytes now in buffer: '", (int)(tb->bufend - tb->bufptr));
for (tempptr = tb->bufptr; tempptr < tb->bufend; tempptr ++) for (tempptr = tb->bufptr; tempptr < tb->bufend; tempptr ++)
{ {
if (*tempptr < ' ' || *tempptr == 0x7f) if (*tempptr < ' ' || *tempptr == 0x7f)
PDFIO_DEBUG("\\%03o", *tempptr); PDFIO_DEBUG("\\%03o", *tempptr);
else else
PDFIO_DEBUG("%c", *tempptr); PDFIO_DEBUG("%c", *tempptr);
} }
PDFIO_DEBUG("'.\n"); PDFIO_DEBUG("'.\n");
#endif // DEBUG #endif // DEBUG
}
tempptr = tb->bufptr; tempptr = tb->bufptr;