Make object reader handle object headers that don't conform to any of the PDF

standards.
This commit is contained in:
Michael R Sweet 2021-08-23 19:52:01 -04:00
parent a3de05cf0e
commit 6e5cfc1a5f
No known key found for this signature in database
GPG Key ID: BE67C75EC81F3244

View File

@ -340,8 +340,9 @@ pdfioObjGetType(pdfio_obj_t *obj) // I - Object
bool // O - `true` on success, `false` otherwise bool // O - `true` on success, `false` otherwise
_pdfioObjLoad(pdfio_obj_t *obj) // I - Object _pdfioObjLoad(pdfio_obj_t *obj) // I - Object
{ {
char line[1024], // Line from file char line[64], // Line from file
*ptr; // Pointer into line *ptr; // Pointer into line
ssize_t bytes; // Bytes read
_pdfio_token_t tb; // Token buffer/stack _pdfio_token_t tb; // Token buffer/stack
@ -354,12 +355,14 @@ _pdfioObjLoad(pdfio_obj_t *obj) // I - Object
return (false); return (false);
} }
if (!_pdfioFileGets(obj->pdf, line, sizeof(line))) if ((bytes = _pdfioFilePeek(obj->pdf, line, sizeof(line) - 1)) < 0)
{ {
_pdfioFileError(obj->pdf, "Unable to read header for object %lu.", (unsigned long)obj->number); _pdfioFileError(obj->pdf, "Unable to read header for object %lu.", (unsigned long)obj->number);
return (false); return (false);
} }
line[bytes] = '\0';
PDFIO_DEBUG("_pdfioObjLoad: Header is '%s'.\n", line); PDFIO_DEBUG("_pdfioObjLoad: Header is '%s'.\n", line);
if (strtoimax(line, &ptr, 10) != (intmax_t)obj->number) if (strtoimax(line, &ptr, 10) != (intmax_t)obj->number)
@ -377,12 +380,15 @@ _pdfioObjLoad(pdfio_obj_t *obj) // I - Object
while (isspace(*ptr & 255)) while (isspace(*ptr & 255))
ptr ++; ptr ++;
if (strcmp(ptr, "obj")) if (strncmp(ptr, "obj", 3) || (ptr[3] && ptr[3] != '<' && ptr[3] != '[' && !isspace(ptr[3] & 255)))
{ {
_pdfioFileError(obj->pdf, "Bad header for object %lu.", (unsigned long)obj->number); _pdfioFileError(obj->pdf, "Bad header for object %lu.", (unsigned long)obj->number);
return (false); return (false);
} }
ptr += 3;
_pdfioFileConsume(obj->pdf, (size_t)(ptr - line));
// Then grab the object value... // Then grab the object value...
_pdfioTokenInit(&tb, obj->pdf, (_pdfio_tconsume_cb_t)_pdfioFileConsume, (_pdfio_tpeek_cb_t)_pdfioFilePeek, obj->pdf); _pdfioTokenInit(&tb, obj->pdf, (_pdfio_tconsume_cb_t)_pdfioFileConsume, (_pdfio_tpeek_cb_t)_pdfioFilePeek, obj->pdf);