... | ... |
@@ -1306,56 +1306,47 @@ static void pdf_parseobj(struct pdf_struct *pdf, struct pdf_obj *obj) |
1306 | 1306 |
q = dict; |
1307 | 1307 |
blockopens++; |
1308 | 1308 |
bytesleft = objsize - (q - start); |
1309 |
+ enddict = q + bytesleft - 1; |
|
1309 | 1310 |
|
1310 | 1311 |
/* find end of dictionary block */ |
1311 |
- do { |
|
1312 |
- /* find end of object within bytesleft */ |
|
1313 |
- nextobj = pdf_nextobject(q, bytesleft); |
|
1314 |
- if (!nextobj) |
|
1315 |
- return; |
|
1316 |
- bytesleft -= nextobj - q; |
|
1317 |
- if (bytesleft < 0) { |
|
1318 |
- return; |
|
1319 |
- } |
|
1320 |
- |
|
1321 |
- /* while still looking ... */ |
|
1322 |
- while ((q+1 < nextobj) && (blockopens > 0)) { |
|
1323 |
- /* find next close */ |
|
1324 |
- nextclose = memchr(q-1, '>', nextobj-q+1); |
|
1325 |
- if (nextclose && (nextclose[1] == '>')) { |
|
1326 |
- /* check for nested open */ |
|
1327 |
- while (nextopen = memchr(q-1, '<', nextclose-q+1)) { |
|
1328 |
- if (nextopen[1] == '<') { |
|
1329 |
- /* nested open */ |
|
1330 |
- blockopens++; |
|
1331 |
- q = nextopen + 2; |
|
1332 |
- } |
|
1333 |
- else { |
|
1334 |
- /* unmatched < */ |
|
1335 |
- q = nextopen + 2; |
|
1336 |
- } |
|
1312 |
+ if (bytesleft < 0) { |
|
1313 |
+ return; |
|
1314 |
+ } |
|
1315 |
+ |
|
1316 |
+ /* while still looking ... */ |
|
1317 |
+ while ((q < enddict-1) && (blockopens > 0)) { |
|
1318 |
+ /* find next close */ |
|
1319 |
+ nextclose = memchr(q, '>', enddict-q+1); |
|
1320 |
+ if (nextclose && (nextclose[1] == '>')) { |
|
1321 |
+ /* check for nested open */ |
|
1322 |
+ while (nextopen = memchr(q-1, '<', nextclose-q+1)) { |
|
1323 |
+ if (nextopen[1] == '<') { |
|
1324 |
+ /* nested open */ |
|
1325 |
+ blockopens++; |
|
1326 |
+ q = nextopen + 2; |
|
1337 | 1327 |
} |
1338 |
- /* close block */ |
|
1339 |
- blockopens--; |
|
1340 |
- q = nextclose + 2; |
|
1341 |
- } |
|
1342 |
- else { |
|
1343 |
- /* unmatched > */ |
|
1344 |
- if (nextclose) |
|
1345 |
- q = nextclose + 2; |
|
1346 | 1328 |
else { |
1347 |
- break; |
|
1329 |
+ /* unmatched < before next close */ |
|
1330 |
+ q = nextopen + 2; |
|
1348 | 1331 |
} |
1349 | 1332 |
} |
1333 |
+ /* close block */ |
|
1334 |
+ blockopens--; |
|
1335 |
+ q = nextclose + 2; |
|
1350 | 1336 |
} |
1337 |
+ else if (nextclose) { |
|
1338 |
+ /* found one > but not two */ |
|
1339 |
+ q = nextclose + 2; |
|
1340 |
+ } |
|
1341 |
+ else { |
|
1342 |
+ /* next closing not found */ |
|
1343 |
+ return; |
|
1344 |
+ } |
|
1345 |
+ } |
|
1351 | 1346 |
|
1352 |
- /* prepare for next object check */ |
|
1353 |
- nextobj++; |
|
1354 |
- bytesleft--; |
|
1355 |
- q = nextobj; |
|
1356 |
- } while (blockopens > 0); |
|
1357 |
- |
|
1358 |
- /* End of dictionary found, would have early returned otherwise */ |
|
1347 |
+ /* Was end of dictionary found? */ |
|
1348 |
+ if (blockopens) |
|
1349 |
+ return; |
|
1359 | 1350 |
enddict = nextclose; |
1360 | 1351 |
obj->flags |= 1 << OBJ_DICT; |
1361 | 1352 |
full_dict_length = dict_length = enddict - dict; |
... | ... |
@@ -1364,7 +1355,12 @@ static void pdf_parseobj(struct pdf_struct *pdf, struct pdf_obj *obj) |
1364 | 1364 |
{ |
1365 | 1365 |
char * dictionary = malloc(dict_length + 1); |
1366 | 1366 |
if (dictionary) { |
1367 |
- strncpy(dictionary, dict, dict_length); |
|
1367 |
+ for (i = 0; i < dict_length; i++) { |
|
1368 |
+ if (isprint(dict[i]) || isspace(dict[i])) |
|
1369 |
+ dictionary[i] = dict[i]; |
|
1370 |
+ else |
|
1371 |
+ dictionary[i] = '*'; |
|
1372 |
+ } |
|
1368 | 1373 |
dictionary[dict_length] = '\0'; |
1369 | 1374 |
cli_dbgmsg("cli_pdf: dictionary is <<%s>>\n", dictionary); |
1370 | 1375 |
free(dictionary); |
... | ... |
@@ -1483,6 +1479,9 @@ static const char *pdf_getdict(const char *q0, int* len, const char *key) |
1483 | 1483 |
cli_dbgmsg("cli_pdf: bad length %d\n", *len); |
1484 | 1484 |
return NULL; |
1485 | 1485 |
} |
1486 |
+ if (!q0) { |
|
1487 |
+ return NULL; |
|
1488 |
+ } |
|
1486 | 1489 |
q = cli_memstr(q0, *len, key, strlen(key)); |
1487 | 1490 |
if (!q) { |
1488 | 1491 |
cli_dbgmsg("cli_pdf: %s not found in dict\n", key); |