Call repairTrailer() after parse(), not before write()

This commit is contained in:
Grégory Soutadé 2022-03-15 19:58:42 +01:00
parent 27b9d8ec3e
commit e4e6160a6b

View File

@ -787,6 +787,8 @@ namespace uPDFParser
} }
} }
repairTrailer();
// close(fd); // close(fd);
} }
@ -814,7 +816,7 @@ namespace uPDFParser
static const char* keys[] = {"Root", "Info", "Encrypt", "ID"}; static const char* keys[] = {"Root", "Info", "Encrypt", "ID"};
for (int i=0; i<sizeof(keys)/sizeof(keys[0]); i++) for (int i=0; i<(int)(sizeof(keys)/sizeof(keys[0])); i++)
{ {
if (!trailer.hasKey(keys[i]) && xrefObject->hasKey(keys[i])) if (!trailer.hasKey(keys[i]) && xrefObject->hasKey(keys[i]))
trailer.dictionary().addData(keys[i], (*xrefObject)[keys[i]]->clone()); trailer.dictionary().addData(keys[i], (*xrefObject)[keys[i]]->clone());
@ -884,8 +886,6 @@ namespace uPDFParser
if (xrefOffset != (off_t)-1) if (xrefOffset != (off_t)-1)
trailer.dictionary().addData("Prev", new Integer((int)xrefOffset)); trailer.dictionary().addData("Prev", new Integer((int)xrefOffset));
repairTrailer();
std::string trailerStr = trailer.dictionary().str(); std::string trailerStr = trailer.dictionary().str();
::write(newFd, "trailer\n", 8); ::write(newFd, "trailer\n", 8);
::write(newFd, trailerStr.c_str(), trailerStr.size()); ::write(newFd, trailerStr.c_str(), trailerStr.size());
@ -968,8 +968,6 @@ namespace uPDFParser
if (xrefStmOffset != 0) if (xrefStmOffset != 0)
trailer.dictionary().addData("XRefStm", new Integer(xrefStmOffset)); trailer.dictionary().addData("XRefStm", new Integer(xrefStmOffset));
repairTrailer();
std::string trailerStr = trailer.dictionary().str(); std::string trailerStr = trailer.dictionary().str();
::write(newFd, "trailer\n", 8); ::write(newFd, "trailer\n", 8);
::write(newFd, trailerStr.c_str(), trailerStr.size()); ::write(newFd, trailerStr.c_str(), trailerStr.size());