mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Ensure that saveDocument
works if there's no /ID-entry in the PDF document (issue 13279) (#13280)
First of all, while it should be very unlikely that the /ID-entry is an *indirect* object, note how we're using `Dict.get` when parsing it e.g. in `PDFDocument.fingerprint`. Hence we definitely should be consistent here, since if the /ID-entry is an *indirect* object the existing code in `src/core/writer.js` would already fail. Secondly, to fix the referenced issue, we also need to check that the /ID-entry actually is an Array before attempting to access its contents in `src/core/writer.js`. *Drive-by change:* In the `xrefInfo` object passed to the `incrementalUpdate` function, re-name the `encrypt` property to `encryptRef` since its data is fetched using `Dict.getRaw` (given the names of the other properties fetched similarly).
This commit is contained in:
parent
8538cdf845
commit
57a1ea840f
3 changed files with 40 additions and 6 deletions
|
@ -633,11 +633,11 @@ class WorkerMessageHandler {
|
|||
|
||||
newXrefInfo = {
|
||||
rootRef: xref.trailer.getRaw("Root") || null,
|
||||
encrypt: xref.trailer.getRaw("Encrypt") || null,
|
||||
encryptRef: xref.trailer.getRaw("Encrypt") || null,
|
||||
newRef: xref.getNewRef(),
|
||||
infoRef: xref.trailer.getRaw("Info") || null,
|
||||
info: infoObj,
|
||||
fileIds: xref.trailer.getRaw("ID") || null,
|
||||
fileIds: xref.trailer.get("ID") || null,
|
||||
startXRef,
|
||||
filename,
|
||||
};
|
||||
|
|
|
@ -201,8 +201,8 @@ function incrementalUpdate({
|
|||
if (xrefInfo.infoRef !== null) {
|
||||
newXref.set("Info", xrefInfo.infoRef);
|
||||
}
|
||||
if (xrefInfo.encrypt !== null) {
|
||||
newXref.set("Encrypt", xrefInfo.encrypt);
|
||||
if (xrefInfo.encryptRef !== null) {
|
||||
newXref.set("Encrypt", xrefInfo.encryptRef);
|
||||
}
|
||||
|
||||
// Add a ref for the new xref and sort them
|
||||
|
@ -226,7 +226,7 @@ function incrementalUpdate({
|
|||
|
||||
newXref.set("Index", indexes);
|
||||
|
||||
if (xrefInfo.fileIds.length !== 0) {
|
||||
if (Array.isArray(xrefInfo.fileIds) && xrefInfo.fileIds.length > 0) {
|
||||
const md5 = computeMD5(baseOffset, xrefInfo);
|
||||
newXref.set("ID", [xrefInfo.fileIds[0], md5]);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue