omitly-mcp 5.3.0 → 5.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,587 @@
1
+ /**
2
+ * omitly#1841 phase B: facts about a loaded document and the signature removal
3
+ * the four writers share. pdf-lib only; no I/O, no network.
4
+ *
5
+ * Every function tolerates hostile structure: loops are guarded by visited sets
6
+ * and depth caps, and a value of the wrong type is skipped rather than thrown.
7
+ */
8
+ import { EncryptedPDFError, PDFArray, PDFBool, PDFContentStream, PDFDict, PDFName, PDFNumber, PDFPageLeaf, PDFPageTree, PDFRawStream, PDFRef, PDFStream, PDFString } from "pdf-lib";
9
+ const MAX_FIELD_NODES = 200_000;
10
+ const MAX_PARENT_DEPTH = 64;
11
+ /** Deeper than this a document is REFUSED (`failed`), never passed through unscanned. */
12
+ const MAX_SIG_WALK_DEPTH = 64;
13
+ /** pdf-lib's EncryptedPDFError is compiled to ES5, so `instanceof` is false for the
14
+ * error it actually throws (measured: constructor.name === "Error"). Match the class
15
+ * AND the message `PDFDocument.load` gives ("... is encrypted."). */
16
+ export function isEncryptedError(e) {
17
+ return e instanceof EncryptedPDFError || (e instanceof Error && /\bis encrypted\b/i.test(e.message));
18
+ }
19
+ const N = (s) => PDFName.of(s);
20
+ /** `lookupMaybe` THROWS when the value is the wrong type (a field's /V is a string, not a
21
+ * dictionary), which would fail a perfectly valid document. These return undefined instead. */
22
+ function lookupAs(doc, v, cls) {
23
+ if (v === undefined)
24
+ return undefined;
25
+ const o = doc.context.lookup(v);
26
+ return o instanceof cls ? o : undefined;
27
+ }
28
+ function dictOf(doc, v) {
29
+ return lookupAs(doc, v, PDFDict);
30
+ }
31
+ /** The value of `key` on `dict` with an indirect reference resolved: `/Type 5 0 R` where object 5
32
+ * is the name `/Sig` is a signature dictionary all the same. Raw `get()` would miss it. */
33
+ function val(doc, dict, key) {
34
+ const v = dict.get(N(key));
35
+ return v === undefined ? undefined : doc.context.lookup(v);
36
+ }
37
+ function acroFormOf(doc) {
38
+ return dictOf(doc, doc.catalog.get(N("AcroForm")));
39
+ }
40
+ /** Visit `dict` and then each ancestor reached by `/Parent` (a cycle ends the walk). The walk is
41
+ * bounded, and going over the bound THROWS (the worker maps it to `failed`): returning "not found"
42
+ * would let a signature field 65 levels down keep its appearance and certificate. `visit` returns
43
+ * true to stop early. */
44
+ export function walkParents(doc, dict, visit) {
45
+ let cur = dict;
46
+ const seen = new Set();
47
+ for (let depth = 0; cur; depth++) {
48
+ if (depth > MAX_PARENT_DEPTH)
49
+ throw new Error("field hierarchy too deep to inspect");
50
+ if (seen.has(cur))
51
+ return;
52
+ seen.add(cur);
53
+ if (visit(cur) === true)
54
+ return;
55
+ cur = dictOf(doc, cur.get(N("Parent")));
56
+ }
57
+ }
58
+ /** The first value of `key` found on `dict` or an ancestor reached by `/Parent`. */
59
+ function inherited(doc, dict, key) {
60
+ let found;
61
+ walkParents(doc, dict, (cur) => {
62
+ const v = cur.get(key);
63
+ if (v === undefined)
64
+ return false;
65
+ found = doc.context.lookup(v);
66
+ return true;
67
+ });
68
+ return found;
69
+ }
70
+ function isSigField(doc, dict) {
71
+ if (inherited(doc, dict, N("FT")) === N("Sig"))
72
+ return true;
73
+ // A signature value filed under a field that does not say it is one.
74
+ const v = dictOf(doc, dict.get(N("V")));
75
+ return v !== undefined && (val(doc, v, "Type") === N("Sig") || v.get(N("ByteRange")) !== undefined);
76
+ }
77
+ /** Visit every node of the AcroForm field tree once. */
78
+ function walkFieldTree(doc, visit) {
79
+ const fields = lookupAs(doc, acroFormOf(doc)?.get(N("Fields")), PDFArray);
80
+ if (!fields)
81
+ return;
82
+ const seen = new Set();
83
+ let budget = MAX_FIELD_NODES;
84
+ const stack = [];
85
+ for (let i = 0; i < fields.size(); i++)
86
+ stack.push(fields.get(i));
87
+ while (stack.length > 0 && budget > 0) {
88
+ const ref = stack.pop();
89
+ const dict = dictOf(doc, ref);
90
+ if (!dict || seen.has(dict))
91
+ continue;
92
+ seen.add(dict);
93
+ budget--;
94
+ const kids = lookupAs(doc, dict.get(N("Kids")), PDFArray);
95
+ let hasFieldKid = false;
96
+ if (kids) {
97
+ for (let i = 0; i < kids.size(); i++) {
98
+ const kid = dictOf(doc, kids.get(i));
99
+ // A kid with a partial name is a child FIELD; one without is a widget
100
+ // of this field (visited by the callers that need widgets).
101
+ if (kid?.get(N("T")) !== undefined) {
102
+ hasFieldKid = true;
103
+ stack.push(kids.get(i));
104
+ }
105
+ }
106
+ }
107
+ visit(dict, !hasFieldKid);
108
+ }
109
+ }
110
+ /** Every widget annotation on every page, once. */
111
+ function forEachPageAnnot(doc, visit) {
112
+ const seen = new Set();
113
+ for (const page of doc.getPages()) {
114
+ const annots = page.node.Annots();
115
+ if (!annots)
116
+ continue;
117
+ for (let i = 0; i < annots.size(); i++) {
118
+ const a = dictOf(doc, annots.get(i));
119
+ if (!a || seen.has(a))
120
+ continue;
121
+ seen.add(a);
122
+ visit(a);
123
+ }
124
+ }
125
+ }
126
+ /** Terminal fields: field nodes with no child field. */
127
+ export function formFieldCount(doc) {
128
+ let n = 0;
129
+ walkFieldTree(doc, (_dict, terminal) => {
130
+ if (terminal)
131
+ n++;
132
+ });
133
+ return n;
134
+ }
135
+ export function hasSignatureField(doc) {
136
+ let found = false;
137
+ walkFieldTree(doc, (dict) => {
138
+ if (inherited(doc, dict, N("FT")) === N("Sig"))
139
+ found = true;
140
+ });
141
+ // The same detection the writers use: a signature dictionary anywhere counts too (a /DocTimeStamp,
142
+ // a value no field points at), so pdf_info and the writers' warning agree.
143
+ return found || findSignatureDictionaries(doc).length > 0;
144
+ }
145
+ /** Any annotation whose subtype is not Widget, Link or Popup. */
146
+ export function hasComments(doc) {
147
+ let found = false;
148
+ forEachPageAnnot(doc, (a) => {
149
+ const st = val(doc, a, "Subtype");
150
+ if (st !== N("Widget") && st !== N("Link") && st !== N("Popup"))
151
+ found = true;
152
+ });
153
+ return found;
154
+ }
155
+ export function xfaKind(doc) {
156
+ const acro = acroFormOf(doc);
157
+ if (!acro || acro.get(N("XFA")) === undefined)
158
+ return "none";
159
+ const needs = (d) => lookupAs(doc, d?.get(N("NeedsRendering")), PDFBool)?.asBoolean() === true;
160
+ return needs(doc.catalog) || needs(acro) ? "dynamic" : "static";
161
+ }
162
+ export function hasLayers(doc) {
163
+ return doc.catalog.get(N("OCProperties")) !== undefined;
164
+ }
165
+ export function sourceFacts(doc) {
166
+ return {
167
+ outlines: doc.catalog.get(N("Outlines")) !== undefined,
168
+ info: doc.context.trailerInfo.Info !== undefined,
169
+ pageLabels: doc.catalog.get(N("PageLabels")) !== undefined,
170
+ layers: hasLayers(doc),
171
+ xfa: xfaKind(doc),
172
+ };
173
+ }
174
+ function clearOne(doc, dict) {
175
+ let removed = false;
176
+ // /V lives on the field; with a widget kid the field is an ancestor.
177
+ walkParents(doc, dict, (cur) => {
178
+ if (cur.get(N("V")) !== undefined) {
179
+ cur.delete(N("V"));
180
+ removed = true;
181
+ }
182
+ // Seed value (names a signer certificate) and lock dictionary: not part of the output.
183
+ if (cur.get(N("SV")) !== undefined)
184
+ cur.delete(N("SV"));
185
+ if (cur.get(N("Lock")) !== undefined)
186
+ cur.delete(N("Lock"));
187
+ });
188
+ // The appearance draws the visible signature: the field itself when it is a
189
+ // merged field/widget, and every widget kid (a kid without a partial name).
190
+ if (dict.get(N("AP")) !== undefined)
191
+ dict.delete(N("AP"));
192
+ const kids = lookupAs(doc, dict.get(N("Kids")), PDFArray);
193
+ if (kids) {
194
+ for (let i = 0; i < kids.size(); i++) {
195
+ const kid = dictOf(doc, kids.get(i));
196
+ if (kid && kid.get(N("T")) === undefined && kid.get(N("AP")) !== undefined)
197
+ kid.delete(N("AP"));
198
+ }
199
+ }
200
+ return removed;
201
+ }
202
+ /** Signature material by what it IS, wherever it hangs: `/Type /Sig`, `/Type /DocTimeStamp`,
203
+ * `/Type /SV` (seed value), any dictionary holding a `/Cert`, or `/Contents` together with one of
204
+ * `/ByteRange`, `/Filter`, `/SubFilter`. `/Type` is resolved if it is an indirect reference. */
205
+ function isSignatureDictionary(doc, d) {
206
+ const type = val(doc, d, "Type");
207
+ if (type === N("Sig") || type === N("DocTimeStamp") || type === N("SV"))
208
+ return true;
209
+ // A seed value (/SV) names the certificate a signer must use, and a /Cert-bearing
210
+ // dictionary is certificate material whatever it is called.
211
+ if (d.get(N("Cert")) !== undefined)
212
+ return true;
213
+ if (d.get(N("Contents")) === undefined)
214
+ return false;
215
+ // /Contents with a signature-shaped sibling. (A page or annotation has /Contents but none of these.)
216
+ return ["ByteRange", "Filter", "SubFilter", "Cert"].some((k) => d.get(N(k)) !== undefined);
217
+ }
218
+ /**
219
+ * Defence in depth, independent of route: empty EVERY signature dictionary in the source.
220
+ * Deleting a field's `/V` only cuts one route to the dictionary; an outline item, a page
221
+ * key, a non-widget annotation or any other copied object that also references it would
222
+ * carry the dictionary, with its `/Contents` (the signer's certificate), into the output
223
+ * through the copier. So each such dictionary loses every key (`/Contents`, `/Cert`,
224
+ * `/ByteRange`, `/Reference`, `/Changes`, `/Name`, `/Location`, `/Reason`, `/ContactInfo`,
225
+ * `/M`, `/Prop_Build`, `/SubFilter`, `/Filter`, and anything else). Orphans included.
226
+ * Also reaches signature dictionaries held DIRECTLY inside other objects (nested dicts and
227
+ * arrays, to depth 64; deeper is refused as `failed`, not skipped) and in a direct trailer
228
+ * `/Info`. Returns true if any dictionary was emptied.
229
+ */
230
+ export function emptySignatureDictionaries(src) {
231
+ const found = findSignatureMaterial(src);
232
+ for (const { dict, stream } of found) {
233
+ // A value held as an INDIRECT object (`/Contents 10 0 R`) is overwritten too: emptying the
234
+ // dictionary alone would leave that object, and anything else that points at it, carrying
235
+ // the certificate. (Done once per source, so there is nothing to journal.)
236
+ const seen = new Set();
237
+ const blank = (v, empty, depth) => {
238
+ if (v === undefined)
239
+ return;
240
+ if (depth > MAX_SIG_WALK_DEPTH)
241
+ throw new Error("signature value nesting too deep to inspect");
242
+ if (v instanceof PDFRef) {
243
+ if (seen.has(v))
244
+ return;
245
+ seen.add(v);
246
+ // What an indirect array or dictionary points at is blanked too (`/Cert 10 0 R` -> `[11 0 R]`).
247
+ blank(src.context.lookup(v), () => PDFString.of(""), depth + 1);
248
+ src.context.assign(v, empty());
249
+ }
250
+ else if (v instanceof PDFArray) {
251
+ v.asArray().forEach((e) => blank(e, () => PDFString.of(""), depth + 1));
252
+ }
253
+ else if (v instanceof PDFStream) {
254
+ for (const [, e] of v.dict.entries())
255
+ blank(e, () => PDFString.of(""), depth + 1);
256
+ }
257
+ else if (v instanceof PDFDict) {
258
+ for (const [, e] of v.entries())
259
+ blank(e, () => PDFString.of(""), depth + 1);
260
+ }
261
+ };
262
+ blank(dict.get(N("Contents")), () => PDFString.of(""), 0);
263
+ blank(dict.get(N("Cert")), () => PDFString.of(""), 0);
264
+ blank(dict.get(N("ByteRange")), () => PDFArray.withContext(src.context), 0);
265
+ for (const [key] of [...dict.entries()])
266
+ dict.delete(key);
267
+ // A signature STREAM's BODY is signature material too (certificate or timestamp bytes): empty it, and
268
+ // leave the stream well-formed with no filter to decode an empty body with (omitly#1852).
269
+ if (stream) {
270
+ if (stream instanceof PDFRawStream)
271
+ stream.contents = new Uint8Array(0);
272
+ else if (stream instanceof PDFContentStream) {
273
+ // pdf-lib builds a content stream's bytes from `operators` on first use and CACHES them: emptying the
274
+ // operators alone leaves a body that was read earlier (getContents / getContentsSize) to be written out.
275
+ // The dictionary lost its /Filter above, so the empty body must not be deflated either (omitly#1852).
276
+ const cs = stream;
277
+ cs.operators = [];
278
+ cs.encode = false;
279
+ cs.contentsCache.invalidate();
280
+ }
281
+ dict.set(N("Length"), PDFNumber.of(0));
282
+ }
283
+ }
284
+ return found.length > 0;
285
+ }
286
+ /**
287
+ * Every signature dictionary in `doc`, wherever it hangs: in an indirect object or held DIRECTLY
288
+ * inside another (nested dicts and arrays, to depth 64; deeper THROWS), including a direct trailer
289
+ * `/Info`. A stream's OWN dictionary is one only when it says `/Type /Sig`, `/DocTimeStamp` or `/SV`,
290
+ * or carries a `/Cert` (an XObject that merely carries `/Contents` and `/Filter` must not be emptied); direct
291
+ * dictionaries nested inside a stream's dictionary are always searched. Read-only.
292
+ */
293
+ export function findSignatureDictionaries(doc) {
294
+ return findSignatureMaterial(doc).map((m) => m.dict);
295
+ }
296
+ /** As above, saying for each hit whether it is a STREAM's own dictionary. */
297
+ function findSignatureMaterial(doc) {
298
+ const found = [];
299
+ // Walk into DIRECT values only (a PDFRef is covered by the enumeration itself).
300
+ const walk = (v, depth) => {
301
+ if (v === undefined)
302
+ return;
303
+ if (depth > MAX_SIG_WALK_DEPTH)
304
+ throw new Error("object nesting too deep to inspect for signatures");
305
+ if (v instanceof PDFStream) {
306
+ // A stream is exempt (an image XObject may carry /Contents and /Filter) UNLESS its own dictionary
307
+ // says it is a signature: /Type /Sig, /DocTimeStamp or /SV (seed value), or a /Cert (certificate
308
+ // material whatever it is called). /Contents with /Filter is NOT enough here, unlike a plain dictionary.
309
+ const type = val(doc, v.dict, "Type");
310
+ if (type === N("Sig") || type === N("DocTimeStamp") || type === N("SV") || v.dict.get(N("Cert")) !== undefined) {
311
+ found.push({ dict: v.dict, stream: v });
312
+ }
313
+ for (const [, child] of v.dict.entries())
314
+ walk(child, depth + 1);
315
+ }
316
+ else if (v instanceof PDFDict) {
317
+ if (isSignatureDictionary(doc, v)) {
318
+ found.push({ dict: v });
319
+ return;
320
+ }
321
+ for (const [, child] of v.entries())
322
+ walk(child, depth + 1);
323
+ }
324
+ else if (v instanceof PDFArray) {
325
+ for (const child of v.asArray())
326
+ walk(child, depth + 1);
327
+ }
328
+ };
329
+ for (const [, obj] of doc.context.enumerateIndirectObjects())
330
+ walk(obj, 0);
331
+ // The trailer's /Info is copied by preserveCatalog; a direct dictionary there is not an indirect object.
332
+ walk(doc.context.trailerInfo.Info, 0);
333
+ return found;
334
+ }
335
+ /**
336
+ * Remove every digital signature from the SOURCE document, before anything is
337
+ * copied (design 4.3): for every signature field (`/FT /Sig`, resolved through
338
+ * `/Parent` inheritance) delete its `/V` (the PKCS#7 blob, which contains the
339
+ * signer's certificate) and delete `/AP` from its widgets. Covers the AcroForm
340
+ * field tree and every page's widget annotations, so a widget the tree does not
341
+ * list is still cleaned. Returns true if any signature VALUE was removed.
342
+ */
343
+ export function stripSignaturesFromSource(src) {
344
+ let removedValue = false;
345
+ walkFieldTree(src, (dict) => {
346
+ if (isSigField(src, dict) && clearOne(src, dict))
347
+ removedValue = true;
348
+ });
349
+ forEachPageAnnot(src, (a) => {
350
+ if (val(src, a, "Subtype") !== N("Widget") || !isSigField(src, a))
351
+ return;
352
+ if (clearOne(src, a))
353
+ removedValue = true;
354
+ });
355
+ // Last, so the field passes above can still recognise a field by the dictionary it holds.
356
+ if (emptySignatureDictionaries(src))
357
+ removedValue = true;
358
+ return removedValue;
359
+ }
360
+ /** Clear `/SigFlags` on the destination so a viewer does not announce a signed document. */
361
+ export function clearSigFlags(dst) {
362
+ const acro = acroFormOf(dst);
363
+ if (acro?.get(N("SigFlags")) !== undefined)
364
+ acro.delete(N("SigFlags"));
365
+ }
366
+ /** Evidence of a field VALUE (as opposed to a name that merely appears in many dictionaries). */
367
+ const FIELD_VALUE_KEYS = ["FT", "V", "DV", "RV"].map(N);
368
+ /** /Type values of dictionaries that are never fields, however many `/T` or `/Parent` they carry. */
369
+ const NON_FIELD_TYPES = ["Action", "Bead", "Thread", "Filespec", "EmbeddedFile", "Font", "FontDescriptor", "ExtGState", "Pattern", "Shading", "XObject", "OCG", "OCMD", "StructElem", "StructTreeRoot"].map(N);
370
+ /**
371
+ * Dictionaries whose `/T` (or `/Parent`) names something else: an ACTION (`/S`: Hide, Movie, Rendition,
372
+ * SubmitForm, ResetForm, GoTo, Named, JavaScript...; its `/T` and `/Fields` name targets and hold no
373
+ * field value), a bead or thread, a file specification, a font, a graphics-state, pattern, shading,
374
+ * XObject or optional-content dictionary, and an annotation that is not a widget. These are field
375
+ * material only through `/FT` or `/Subtype /Widget`: never through `/T`, `/Parent` or a value key
376
+ * (`/V` is a file spec's volatile flag and an article bead's previous-bead link).
377
+ * They are still searched INSIDE (a ResetForm `/Fields` array may hold a direct field dictionary).
378
+ */
379
+ function isNonFieldKind(doc, d) {
380
+ if (d.get(N("S")) !== undefined)
381
+ return true;
382
+ const type = val(doc, d, "Type");
383
+ if (type !== undefined && NON_FIELD_TYPES.includes(type))
384
+ return true;
385
+ return type === N("Annot") && val(doc, d, "Subtype") !== N("Widget");
386
+ }
387
+ const VALUE_KEYS = ["V", "DV", "RV"].map(N);
388
+ const FIELD_LINK_KEYS = ["Parent", "T", "Kids"].map(N);
389
+ /**
390
+ * A dictionary's OWN evidence that it is a form field: (a) `/Subtype /Widget`, or (b) `/FT`, or
391
+ * (c) a value key (`/V`, `/DV`, `/RV`) together with a field link (`/Parent`, `/T`, `/Kids`).
392
+ * `/T`, `/TM`, `/TU`, `/Opt` and `/MaxLen` ALONE are never evidence: they are used outside forms
393
+ * (a rectilinear `/Measure` has a `/T` array of angle formats, a 3D animation style has `/TM`).
394
+ */
395
+ function ownFieldEvidence(doc, d) {
396
+ if (val(doc, d, "Subtype") === N("Widget") || d.get(N("FT")) !== undefined)
397
+ return true;
398
+ // `/V` means other things outside forms (a file spec's volatile flag, an article bead's previous bead).
399
+ if (isNonFieldKind(doc, d))
400
+ return false;
401
+ return VALUE_KEYS.some((k) => d.get(k) !== undefined) && FIELD_LINK_KEYS.some((k) => d.get(k) !== undefined);
402
+ }
403
+ /**
404
+ * Does any `/Parent` ancestor of the EXEMPT dictionary `d` (a page node or outline item) have field evidence of
405
+ * its own? Unlike `walkParents` this walks the WHOLE chain and never throws on depth: a genuine outline or page
406
+ * tree can be hundreds of levels deep and must not fail a writer, and answering "no field ancestor" at a cap
407
+ * would let a dressed-up dictionary below a deep field keep its /DA, /TU, /Opt and /AP (omitly#1852). It ends at
408
+ * a genuine root (no /Parent), at a cycle (nothing new to find), or at an already-answered ancestor. `memo` holds,
409
+ * per dictionary, "it or an ancestor has field evidence", so every node of a chain is walked once per scrub, however
410
+ * many dictionaries hang below it. An exempt dictionary has no field evidence of its own (no /Widget, /FT or value
411
+ * key), so its answer is exactly its parent's, and it is memoised too.
412
+ */
413
+ function hasFieldAncestor(doc, d, memo) {
414
+ const path = [d];
415
+ const onPath = new Set(path);
416
+ let result = false;
417
+ for (let cur = dictOf(doc, d.get(N("Parent"))); cur; cur = dictOf(doc, cur.get(N("Parent")))) {
418
+ const known = memo.get(cur);
419
+ if (known !== undefined) {
420
+ result = known;
421
+ break;
422
+ }
423
+ if (onPath.has(cur))
424
+ break; // a cycle: everything on it was already looked at
425
+ onPath.add(cur);
426
+ path.push(cur);
427
+ if (ownFieldEvidence(doc, cur)) {
428
+ result = true;
429
+ break;
430
+ }
431
+ }
432
+ // Every dictionary on the path inherits the answer: none of the ones above the stopping point had evidence
433
+ // (or the walk would have stopped there), and `d` has none by construction.
434
+ for (const node of path)
435
+ memo.set(node, result);
436
+ return result;
437
+ }
438
+ /**
439
+ * "Field material": a dictionary that is, or is part of, a form field. It is one if it has field
440
+ * evidence of its own (above), OR any `/Parent` ancestor does: a field with no `/T` and an inherited
441
+ * `/FT` is still a field, and that ancestor link alone is enough. Page-tree nodes, outline items
442
+ * and signature dictionaries are not (signatures have their own scrub); an outline item (`/Title`
443
+ * with a `/Parent`) is exempt only while it has no widget subtype, no `/FT` and no value key. The
444
+ * ancestor walk is bounded and THROWS past the bound; the exempt kinds' walk (hasFieldAncestor) is not bounded.
445
+ */
446
+ function isFieldMaterial(doc, d, ancestorMemo) {
447
+ const type = val(doc, d, "Type");
448
+ const hasValue = FIELD_VALUE_KEYS.some((k) => d.get(k) !== undefined);
449
+ // A page-tree node (by class or /Type; pdf-lib's parser turns `/Type /Page` into a page object) or an
450
+ // outline item (/Title with /Parent) is exempt only while it has no widget subtype, no /FT and no
451
+ // value key: a field mislabelled `/Type /Page` is still a field.
452
+ const pageNode = d instanceof PDFPageLeaf || d instanceof PDFPageTree || type === N("Page") || type === N("Pages");
453
+ const exempt = (pageNode && !hasValue && val(doc, d, "Subtype") !== N("Widget")) ||
454
+ (d.get(N("Title")) !== undefined && d.get(N("Parent")) !== undefined && !hasValue && val(doc, d, "Subtype") !== N("Widget"));
455
+ // The exemption covers a genuine page or outline item, not a dictionary that merely wears the label: one
456
+ // whose /Parent chain reaches a field is part of that field (its /DA, /TU, /Opt, /AP...), so only an exempt
457
+ // dictionary with NO field ancestor is left alone (omitly#1852). Walked in full (hasFieldAncestor), not capped.
458
+ if (exempt)
459
+ return hasFieldAncestor(doc, d, ancestorMemo);
460
+ if (isSignatureDictionary(doc, d))
461
+ return false;
462
+ // Never through a value key or an ancestor, only through /FT or /Subtype /Widget.
463
+ if (isNonFieldKind(doc, d))
464
+ return d.get(N("FT")) !== undefined || val(doc, d, "Subtype") === N("Widget");
465
+ let material = false;
466
+ walkParents(doc, d, (cur) => {
467
+ if (!ownFieldEvidence(doc, cur))
468
+ return false;
469
+ material = true;
470
+ return true;
471
+ });
472
+ return material;
473
+ }
474
+ /**
475
+ * Empty every piece of field material that is not KEPT, where kept means: the very object (an
476
+ * indirect object, or for a direct dictionary the exact instance) listed in a kept page's
477
+ * `/Annots`, or a `/Parent` ancestor of one. VALUE-CENTRIC and RECURSIVE, like the signature
478
+ * detector: every indirect object is searched, and direct dictionaries and arrays inside them at
479
+ * any depth (a stream's own dictionary never; the dictionaries nested in it yes; deeper than 64
480
+ * THROWS). So it does not matter how a field is reached (/Kids, /Fields, a ResetForm or SubmitForm
481
+ * action, /AA, an outline item, a custom key) or whether it is indirect, direct, untitled or has its
482
+ * `/FT` only on an ancestor: whatever is field material and not kept is empty before it can be
483
+ * copied (source) or written (destination). Emptied dictionaries are also removed from the `/Kids`
484
+ * of fields that stay. A kept page's non-widget annotations (which carry a `/T`, the author) are
485
+ * exempt because they are listed there. Returns how many dictionaries were emptied.
486
+ */
487
+ export function scrubFieldsOutsideKept(doc, keptPages, journal) {
488
+ // KEPT: every annotation listed on a kept page, plus the /Parent chain of each kept WIDGET. A
489
+ // non-widget annotation (a Link, a Popup) does NOT keep its /Parent: that would let a page-1 Link
490
+ // point at a page-2 field and keep it. A Popup's parent markup annotation is kept because it is
491
+ // itself listed on the kept page, not because of the /Parent link.
492
+ const kept = new Set();
493
+ for (const page of keptPages) {
494
+ const annots = lookupAs(doc, page.node.get(N("Annots")), PDFArray);
495
+ if (!annots)
496
+ continue;
497
+ for (let i = 0; i < annots.size(); i++) {
498
+ const a = dictOf(doc, annots.get(i));
499
+ if (!a)
500
+ continue;
501
+ if (val(doc, a, "Subtype") === N("Widget")) {
502
+ walkParents(doc, a, (anc) => {
503
+ kept.add(anc);
504
+ return false;
505
+ });
506
+ }
507
+ else
508
+ kept.add(a);
509
+ }
510
+ }
511
+ const emptied = new Set();
512
+ const seen = new Set();
513
+ const ancestorMemo = new Map();
514
+ const walk = (v, depth) => {
515
+ if (v === undefined)
516
+ return;
517
+ if (depth > MAX_SIG_WALK_DEPTH)
518
+ throw new Error("object nesting too deep to inspect for fields");
519
+ if (v instanceof PDFStream) {
520
+ // Its own dictionary is never a field; the dictionaries nested in it are searched.
521
+ for (const [, child] of v.dict.entries())
522
+ walk(child, depth + 1);
523
+ }
524
+ else if (v instanceof PDFDict) {
525
+ if (seen.has(v))
526
+ return;
527
+ seen.add(v);
528
+ // Decide first, empty afterwards: emptying an ancestor would erase the evidence that makes its
529
+ // untitled descendants field material (the answer must not depend on traversal order).
530
+ if (!kept.has(v) && isFieldMaterial(doc, v, ancestorMemo))
531
+ emptied.add(v);
532
+ for (const [, child] of v.entries())
533
+ walk(child, depth + 1);
534
+ }
535
+ else if (v instanceof PDFArray) {
536
+ for (const child of v.asArray())
537
+ walk(child, depth + 1);
538
+ }
539
+ };
540
+ for (const [, obj] of doc.context.enumerateIndirectObjects())
541
+ walk(obj, 0);
542
+ // A direct trailer /Info (copied by preserveCatalog) is not an indirect object either.
543
+ walk(doc.context.trailerInfo.Info, 0);
544
+ if (emptied.size === 0)
545
+ return 0;
546
+ for (const v of emptied) {
547
+ journal?.dict(v);
548
+ for (const [key] of [...v.entries()])
549
+ v.delete(key);
550
+ }
551
+ // Detach: a field that stays must not list a dictionary that is now empty.
552
+ for (const d of kept) {
553
+ const kids = lookupAs(doc, d.get(N("Kids")), PDFArray);
554
+ if (!kids)
555
+ continue;
556
+ for (let i = kids.size() - 1; i >= 0; i--) {
557
+ const kid = dictOf(doc, kids.get(i));
558
+ if (kid && emptied.has(kid)) {
559
+ journal?.array(kids);
560
+ kids.remove(i);
561
+ }
562
+ }
563
+ }
564
+ return emptied.size;
565
+ }
566
+ /**
567
+ * BACKSTOP on the DESTINATION, run just before a writer saves: the same detector as the
568
+ * source scrub, over every object of the document about to be written. The source scrub is
569
+ * the primary defence; this catches any route to a signature dictionary nobody thought of.
570
+ * Returns true if it found and emptied one (the writer then adds the signature warning).
571
+ */
572
+ export function scrubDestinationSignatures(dst) {
573
+ return emptySignatureDictionaries(dst);
574
+ }
575
+ /**
576
+ * BACKSTOP on the DESTINATION for fields (extract, split, edit; NOT merge, which keeps every field,
577
+ * including ones with no widget): any field material (see isFieldMaterial) that is not an annotation
578
+ * on an output page, or an ancestor of one, is emptied just before the save.
579
+ */
580
+ export function scrubDestinationFields(dst) {
581
+ return scrubFieldsOutsideKept(dst, dst.getPages());
582
+ }
583
+ export const SIGNATURE_WARNING = "The original's digital signature was removed; the output is a new, unsigned document.";
584
+ export const LAYERS_WARNING = "The original had optional-content layers; hidden layers may now show.";
585
+ export const FONT_RENAME_WARNING = "Two forms used the same font name for different fonts; some form fields could not be switched to their own font and may render in the wrong one.";
586
+ export const RENAME_WARNING = "Some form fields were renamed because two files used the same field name; a calculation that refers to the old name may no longer work.";
587
+ //# sourceMappingURL=docFacts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"docFacts.js","sourceRoot":"","sources":["../../src/pdf-edit/docFacts.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAA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