Commit f57cbe32 authored by Albert Astals Cid's avatar Albert Astals Cid
Browse files

If when looking for an object we get objSomeNumberAfter assume it was an int of SomeNumberAfter

Fixes bug 17568 and i don't see how it can break existing things because it's already on an error path
parent 1a852064
......@@ -34,6 +34,7 @@
#include <stddef.h>
#include <string.h>
#include <ctype.h>
#include <limits.h>
#include "goo/gmem.h"
#include "Object.h"
#include "Stream.h"
......@@ -922,6 +923,30 @@ Object *XRef::fetch(int num, int gen, Object *obj) {
if (!obj1.isInt() || obj1.getInt() != num ||
!obj2.isInt() || obj2.getInt() != gen ||
!obj3.isCmd("obj")) {
// some buggy pdf have obj1234 for ints that represent 1234
// try to recover here
if (obj1.isInt() && obj1.getInt() == num &&
obj2.isInt() && obj2.getInt() == gen &&
obj3.isCmd()) {
char *cmd = obj3.getCmd();
if (strlen(cmd) > 3 &&
cmd[0] == 'o' &&
cmd[1] == 'b' &&
cmd[2] == 'j') {
char *end_ptr;
long longNumber = strtol(cmd + 3, &end_ptr, 0);
if (longNumber <= INT_MAX && longNumber >= INT_MIN && *end_ptr == '\0') {
int number = longNumber;
error(-1, "Cmd was not obj but %s, assuming the creator meant obj %d", cmd, number);
obj->initInt(number);
obj1.free();
obj2.free();
obj3.free();
delete parser;
break;
}
}
}
obj1.free();
obj2.free();
obj3.free();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment