| ... | ... |
@@ -345,6 +345,13 @@ int pdf_findobj_in_objstm(struct pdf_struct *pdf, struct objstm_struct *objstm, |
| 345 | 345 |
goto done; |
| 346 | 346 |
} |
| 347 | 347 |
|
| 348 |
+ if ((size_t)objstm->first + (size_t)objoff > objstm->streambuf_len) {
|
|
| 349 |
+ /* Alleged obj location is further than the length of the stream */ |
|
| 350 |
+ cli_dbgmsg("pdf_findobj_in_objstm: obj offset found is greater than the length of the stream.\n");
|
|
| 351 |
+ status = CL_EPARSE; |
|
| 352 |
+ goto done; |
|
| 353 |
+ } |
|
| 354 |
+ |
|
| 348 | 355 |
objstm->current = objstm->first + objoff; |
| 349 | 356 |
|
| 350 | 357 |
obj->id = (objid << 8) | (0 & 0xff); |
| ... | ... |
@@ -2030,16 +2037,32 @@ void pdf_parseobj(struct pdf_struct *pdf, struct pdf_obj *obj) |
| 2030 | 2030 |
json_object *pdfobj = NULL, *jsonobj = NULL; |
| 2031 | 2031 |
#endif |
| 2032 | 2032 |
|
| 2033 |
- q = (obj->objstm) ? (const char *)(obj->start + obj->objstm->streambuf) |
|
| 2034 |
- : (const char *)(obj->start + pdf->map); |
|
| 2033 |
+ if (obj->objstm) {
|
|
| 2034 |
+ if ((size_t)obj->start > obj->objstm->streambuf_len) {
|
|
| 2035 |
+ cli_dbgmsg("pdf_parseobj: %u %u obj: obj start (%u) is greater than size of object stream (%zu).\n",
|
|
| 2036 |
+ obj->id >> 8, obj->id & 0xff, obj->start, obj->objstm->streambuf_len); |
|
| 2037 |
+ return; |
|
| 2038 |
+ } |
|
| 2039 |
+ q = (const char *)(obj->start + obj->objstm->streambuf); |
|
| 2040 |
+ } else {
|
|
| 2041 |
+ if ((size_t)obj->start > pdf->size) {
|
|
| 2042 |
+ cli_dbgmsg("pdf_parseobj: %u %u obj: obj start (%u) is greater than size of PDF (%lld).\n",
|
|
| 2043 |
+ obj->id >> 8, obj->id & 0xff, obj->start, (long long)pdf->size); |
|
| 2044 |
+ return; |
|
| 2045 |
+ } |
|
| 2046 |
+ q = (const char *)(obj->start + pdf->map); |
|
| 2047 |
+ } |
|
| 2048 |
+ start = q; |
|
| 2035 | 2049 |
|
| 2036 | 2050 |
objsize = obj_size(pdf, obj, 1); |
| 2037 |
- |
|
| 2038 | 2051 |
if (objsize < 0) |
| 2039 | 2052 |
return; |
| 2040 | 2053 |
|
| 2041 |
- start = q; |
|
| 2042 |
- bytesleft = objsize; |
|
| 2054 |
+ if (obj->objstm) {
|
|
| 2055 |
+ bytesleft = MIN(objsize, obj->objstm->streambuf_len - obj->start); |
|
| 2056 |
+ } else {
|
|
| 2057 |
+ bytesleft = MIN(objsize, pdf->size - obj->start); |
|
| 2058 |
+ } |
|
| 2043 | 2059 |
|
| 2044 | 2060 |
/* find start of dictionary */ |
| 2045 | 2061 |
do {
|