aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2009-02-21 03:31:32 +0100
committerJay Berkenbilt <ejb@ql.org>2009-02-21 03:31:32 +0100
commit4499e04b5714747eb954420f8133e650a5137d45 (patch)
treef7fba2f5f901ccb6081469af84285714b62fd7a6 /libqpdf
parent35d72c822e07017feac2c6be02c1d402f4992728 (diff)
downloadqpdf-4499e04b5714747eb954420f8133e650a5137d45.tar.zst
better recovery for appended files with damaged cross-reference tables
git-svn-id: svn+q:///qpdf/trunk@649 71b93d88-0707-0410-a8cf-f5a4172ac649
Diffstat (limited to 'libqpdf')
-rw-r--r--libqpdf/QPDF.cc22
1 files changed, 17 insertions, 5 deletions
diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc
index 6f51fa2c..a90cddc2 100644
--- a/libqpdf/QPDF.cc
+++ b/libqpdf/QPDF.cc
@@ -435,7 +435,7 @@ QPDF::reconstruct_xref(QPDFExc& e)
int obj = atoi(m.getMatch(1).c_str());
int gen = atoi(m.getMatch(2).c_str());
int offset = this->file.getLastOffset();
- insertXrefEntry(obj, 1, offset, gen);
+ insertXrefEntry(obj, 1, offset, gen, true);
}
else if ((! this->trailer.isInitialized()) &&
trailer_re.match(line.c_str()))
@@ -865,11 +865,15 @@ QPDF::processXRefStream(off_t xref_offset, QPDFObjectHandle& xref_obj)
}
void
-QPDF::insertXrefEntry(int obj, int f0, int f1, int f2)
+QPDF::insertXrefEntry(int obj, int f0, int f1, int f2, bool overwrite)
{
// Populate the xref table in such a way that the first reference
// to an object that we see, which is the one in the latest xref
- // table in which it appears, is the one that gets stored.
+ // table in which it appears, is the one that gets stored. This
+ // works because we are reading more recent appends before older
+ // ones. Exception: if overwrite is true, then replace any
+ // existing object. This is used in xref recovery mode, which
+ // reads the file from beginning to end.
// If there is already an entry for this object and generation in
// the table, it means that a later xref table has registered this
@@ -879,8 +883,16 @@ QPDF::insertXrefEntry(int obj, int f0, int f1, int f2)
ObjGen og(obj, gen);
if (this->xref_table.count(og))
{
- QTC::TC("qpdf", "QPDF xref reused object");
- return;
+ if (overwrite)
+ {
+ QTC::TC("qpdf", "QPDF xref overwrite object");
+ this->xref_table.erase(og);
+ }
+ else
+ {
+ QTC::TC("qpdf", "QPDF xref reused object");
+ return;
+ }
}
if (this->deleted_objects.count(obj))
{