@file-viewer/renderer-pdf 3.3.3 → 3.3.5

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,387 @@
1
+ export const pdfAnnotationLayerStyle = String.raw `.annotationLayer{
2
+ --csstools-color-scheme--light:initial;
3
+ color-scheme:only light;
4
+
5
+ --annotation-unfocused-field-background:url("data:image/svg+xml;charset=UTF-8,<svg width='1px' height='1px' xmlns='http://www.w3.org/2000/svg'><rect width='100%' height='100%' style='fill:rgba(0, 54, 255, 0.13);'/></svg>");
6
+ --input-focus-border-color:Highlight;
7
+ --input-focus-outline:1px solid Canvas;
8
+ --input-unfocused-border-color:transparent;
9
+ --input-disabled-border-color:transparent;
10
+ --input-hover-border-color:black;
11
+ --link-outline:none;
12
+ }
13
+
14
+ @media screen and (forced-colors: active){
15
+
16
+ .annotationLayer{
17
+ --input-focus-border-color:CanvasText;
18
+ --input-unfocused-border-color:ActiveText;
19
+ --input-disabled-border-color:GrayText;
20
+ --input-hover-border-color:Highlight;
21
+ --link-outline:1.5px solid LinkText;
22
+ }
23
+
24
+ .annotationLayer .textWidgetAnnotation :is(input,textarea):required,.annotationLayer .choiceWidgetAnnotation select:required,.annotationLayer .buttonWidgetAnnotation:is(.checkBox,.radioButton) input:required{
25
+ outline:1.5px solid selectedItem;
26
+ }
27
+
28
+ .annotationLayer .linkAnnotation{
29
+ outline:var(--link-outline);
30
+ }
31
+
32
+ :is(.annotationLayer .linkAnnotation):hover{
33
+ -webkit-backdrop-filter:var(--hcm-highlight-filter);
34
+ backdrop-filter:var(--hcm-highlight-filter);
35
+ }
36
+
37
+ :is(.annotationLayer .linkAnnotation) > a:hover{
38
+ opacity:0 !important;
39
+ background:none !important;
40
+ box-shadow:none;
41
+ }
42
+
43
+ .annotationLayer .popupAnnotation .popup{
44
+ outline:calc(1.5px * var(--total-scale-factor)) solid CanvasText !important;
45
+ background-color:ButtonFace !important;
46
+ color:ButtonText !important;
47
+ }
48
+
49
+ .annotationLayer .highlightArea:hover::after{
50
+ position:absolute;
51
+ top:0;
52
+ left:0;
53
+ width:100%;
54
+ height:100%;
55
+ -webkit-backdrop-filter:var(--hcm-highlight-filter);
56
+ backdrop-filter:var(--hcm-highlight-filter);
57
+ content:"";
58
+ pointer-events:none;
59
+ }
60
+
61
+ .annotationLayer .popupAnnotation.focused .popup{
62
+ outline:calc(3px * var(--total-scale-factor)) solid Highlight !important;
63
+ }
64
+ }
65
+
66
+ .annotationLayer{
67
+
68
+ position:absolute;
69
+ top:0;
70
+ left:0;
71
+ pointer-events:none;
72
+ transform-origin:0 0;
73
+ }
74
+
75
+ .annotationLayer[data-main-rotation="90"] .norotate{
76
+ transform:rotate(270deg) translateX(-100%);
77
+ }
78
+
79
+ .annotationLayer[data-main-rotation="180"] .norotate{
80
+ transform:rotate(180deg) translate(-100%, -100%);
81
+ }
82
+
83
+ .annotationLayer[data-main-rotation="270"] .norotate{
84
+ transform:rotate(90deg) translateY(-100%);
85
+ }
86
+
87
+ .annotationLayer.disabled section,.annotationLayer.disabled .popup{
88
+ pointer-events:none;
89
+ }
90
+
91
+ .annotationLayer .annotationContent{
92
+ position:absolute;
93
+ width:100%;
94
+ height:100%;
95
+ pointer-events:none;
96
+ }
97
+
98
+ .freetext:is(.annotationLayer .annotationContent){
99
+ background:transparent;
100
+ border:none;
101
+ inset:0;
102
+ overflow:visible;
103
+ white-space:nowrap;
104
+ font:10px sans-serif;
105
+ line-height:1.35;
106
+ }
107
+
108
+ .annotationLayer section{
109
+ position:absolute;
110
+ text-align:initial;
111
+ pointer-events:auto;
112
+ box-sizing:border-box;
113
+ transform-origin:0 0;
114
+ -webkit-user-select:none;
115
+ -moz-user-select:none;
116
+ user-select:none;
117
+ }
118
+
119
+ :is(.annotationLayer section):has(div.annotationContent) canvas.annotationContent{
120
+ display:none;
121
+ }
122
+
123
+ :is(.annotationLayer section) .overlaidText{
124
+ position:absolute;
125
+ top:0;
126
+ left:0;
127
+ width:0;
128
+ height:0;
129
+ display:inline-block;
130
+ overflow:hidden;
131
+ }
132
+
133
+ .textLayer.selecting ~ .annotationLayer section{
134
+ pointer-events:none;
135
+ }
136
+
137
+ .annotationLayer :is(.linkAnnotation,.buttonWidgetAnnotation.pushButton) > a{
138
+ position:absolute;
139
+ font-size:1em;
140
+ top:0;
141
+ left:0;
142
+ width:100%;
143
+ height:100%;
144
+ }
145
+
146
+ .annotationLayer :is(.linkAnnotation,.buttonWidgetAnnotation.pushButton):not(.hasBorder) > a:hover{
147
+ opacity:0.2;
148
+ background-color:rgb(255 255 0);
149
+ }
150
+
151
+ .annotationLayer .linkAnnotation.hasBorder:hover{
152
+ background-color:rgb(255 255 0 / 0.2);
153
+ }
154
+
155
+ .annotationLayer .hasBorder{
156
+ background-size:100% 100%;
157
+ }
158
+
159
+ .annotationLayer .textAnnotation img{
160
+ position:absolute;
161
+ cursor:pointer;
162
+ width:100%;
163
+ height:100%;
164
+ top:0;
165
+ left:0;
166
+ }
167
+
168
+ .annotationLayer .textWidgetAnnotation :is(input,textarea),.annotationLayer .choiceWidgetAnnotation select,.annotationLayer .buttonWidgetAnnotation:is(.checkBox,.radioButton) input{
169
+ background-image:var(--annotation-unfocused-field-background);
170
+ border:2px solid var(--input-unfocused-border-color);
171
+ box-sizing:border-box;
172
+ font:calc(9px * var(--total-scale-factor)) sans-serif;
173
+ height:100%;
174
+ margin:0;
175
+ vertical-align:top;
176
+ width:100%;
177
+ }
178
+
179
+ .annotationLayer .textWidgetAnnotation :is(input,textarea):required,.annotationLayer .choiceWidgetAnnotation select:required,.annotationLayer .buttonWidgetAnnotation:is(.checkBox,.radioButton) input:required{
180
+ outline:1.5px solid red;
181
+ }
182
+
183
+ .annotationLayer .choiceWidgetAnnotation select option{
184
+ padding:0;
185
+ }
186
+
187
+ .annotationLayer .buttonWidgetAnnotation.radioButton input{
188
+ border-radius:50%;
189
+ }
190
+
191
+ .annotationLayer .textWidgetAnnotation textarea{
192
+ resize:none;
193
+ }
194
+
195
+ .annotationLayer .textWidgetAnnotation [disabled]:is(input,textarea),.annotationLayer .choiceWidgetAnnotation select[disabled],.annotationLayer .buttonWidgetAnnotation:is(.checkBox,.radioButton) input[disabled]{
196
+ background:none;
197
+ border:2px solid var(--input-disabled-border-color);
198
+ cursor:not-allowed;
199
+ }
200
+
201
+ .annotationLayer .textWidgetAnnotation :is(input,textarea):hover,.annotationLayer .choiceWidgetAnnotation select:hover,.annotationLayer .buttonWidgetAnnotation:is(.checkBox,.radioButton) input:hover{
202
+ border:2px solid var(--input-hover-border-color);
203
+ }
204
+
205
+ .annotationLayer .textWidgetAnnotation :is(input,textarea):hover,.annotationLayer .choiceWidgetAnnotation select:hover,.annotationLayer .buttonWidgetAnnotation.checkBox input:hover{
206
+ border-radius:2px;
207
+ }
208
+
209
+ .annotationLayer .textWidgetAnnotation :is(input,textarea):focus,.annotationLayer .choiceWidgetAnnotation select:focus{
210
+ background:none;
211
+ border:2px solid var(--input-focus-border-color);
212
+ border-radius:2px;
213
+ outline:var(--input-focus-outline);
214
+ }
215
+
216
+ .annotationLayer .buttonWidgetAnnotation:is(.checkBox,.radioButton) :focus{
217
+ background-image:none;
218
+ background-color:transparent;
219
+ }
220
+
221
+ .annotationLayer .buttonWidgetAnnotation.checkBox :focus{
222
+ border:2px solid var(--input-focus-border-color);
223
+ border-radius:2px;
224
+ outline:var(--input-focus-outline);
225
+ }
226
+
227
+ .annotationLayer .buttonWidgetAnnotation.radioButton :focus{
228
+ border:2px solid var(--input-focus-border-color);
229
+ outline:var(--input-focus-outline);
230
+ }
231
+
232
+ .annotationLayer .buttonWidgetAnnotation.checkBox input:checked::before,.annotationLayer .buttonWidgetAnnotation.checkBox input:checked::after,.annotationLayer .buttonWidgetAnnotation.radioButton input:checked::before{
233
+ background-color:CanvasText;
234
+ content:"";
235
+ display:block;
236
+ position:absolute;
237
+ }
238
+
239
+ .annotationLayer .buttonWidgetAnnotation.checkBox input:checked::before,.annotationLayer .buttonWidgetAnnotation.checkBox input:checked::after{
240
+ height:80%;
241
+ left:45%;
242
+ width:1px;
243
+ }
244
+
245
+ .annotationLayer .buttonWidgetAnnotation.checkBox input:checked::before{
246
+ transform:rotate(45deg);
247
+ }
248
+
249
+ .annotationLayer .buttonWidgetAnnotation.checkBox input:checked::after{
250
+ transform:rotate(-45deg);
251
+ }
252
+
253
+ .annotationLayer .buttonWidgetAnnotation.radioButton input:checked::before{
254
+ border-radius:50%;
255
+ height:50%;
256
+ left:25%;
257
+ top:25%;
258
+ width:50%;
259
+ }
260
+
261
+ .annotationLayer .textWidgetAnnotation input.comb{
262
+ font-family:monospace;
263
+ padding-left:2px;
264
+ padding-right:0;
265
+ }
266
+
267
+ .annotationLayer .textWidgetAnnotation input.comb:focus{
268
+ width:103%;
269
+ }
270
+
271
+ .annotationLayer .buttonWidgetAnnotation:is(.checkBox,.radioButton) input{
272
+ -webkit-appearance:none;
273
+ -moz-appearance:none;
274
+ appearance:none;
275
+ }
276
+
277
+ .annotationLayer .fileAttachmentAnnotation .popupTriggerArea{
278
+ height:100%;
279
+ width:100%;
280
+ }
281
+
282
+ .annotationLayer .popupAnnotation{
283
+ position:absolute;
284
+ font-size:calc(9px * var(--total-scale-factor));
285
+ pointer-events:none;
286
+ width:-moz-max-content;
287
+ width:max-content;
288
+ max-width:45%;
289
+ height:auto;
290
+ }
291
+
292
+ .annotationLayer .popup{
293
+ background-color:rgb(255 255 153);
294
+ color:black;
295
+ box-shadow:0 calc(2px * var(--total-scale-factor)) calc(5px * var(--total-scale-factor)) rgb(136 136 136);
296
+ border-radius:calc(2px * var(--total-scale-factor));
297
+ outline:1.5px solid rgb(255 255 74);
298
+ padding:calc(6px * var(--total-scale-factor));
299
+ cursor:pointer;
300
+ font:message-box;
301
+ white-space:normal;
302
+ word-wrap:break-word;
303
+ pointer-events:auto;
304
+ -webkit-user-select:text;
305
+ -moz-user-select:text;
306
+ user-select:text;
307
+ }
308
+
309
+ .annotationLayer .popupAnnotation.focused .popup{
310
+ outline-width:3px;
311
+ }
312
+
313
+ .annotationLayer .popup *{
314
+ font-size:calc(9px * var(--total-scale-factor));
315
+ }
316
+
317
+ .annotationLayer .popup > .header{
318
+ display:inline-block;
319
+ }
320
+
321
+ .annotationLayer .popup > .header > .title{
322
+ display:inline;
323
+ font-weight:bold;
324
+ }
325
+
326
+ .annotationLayer .popup > .header .popupDate{
327
+ display:inline-block;
328
+ margin-left:calc(5px * var(--total-scale-factor));
329
+ width:-moz-fit-content;
330
+ width:fit-content;
331
+ }
332
+
333
+ .annotationLayer .popupContent{
334
+ border-top:1px solid rgb(51 51 51);
335
+ margin-top:calc(2px * var(--total-scale-factor));
336
+ padding-top:calc(2px * var(--total-scale-factor));
337
+ }
338
+
339
+ .annotationLayer .richText > *{
340
+ white-space:pre-wrap;
341
+ font-size:calc(9px * var(--total-scale-factor));
342
+ }
343
+
344
+ .annotationLayer .popupTriggerArea{
345
+ cursor:pointer;
346
+ }
347
+
348
+ :is(.annotationLayer .popupTriggerArea):hover{
349
+ -webkit-backdrop-filter:var(--hcm-highlight-filter);
350
+ backdrop-filter:var(--hcm-highlight-filter);
351
+ }
352
+
353
+ .annotationLayer section svg{
354
+ position:absolute;
355
+ width:100%;
356
+ height:100%;
357
+ top:0;
358
+ left:0;
359
+ }
360
+
361
+ .annotationLayer .annotationTextContent{
362
+ position:absolute;
363
+ width:100%;
364
+ height:100%;
365
+ opacity:0;
366
+ color:transparent;
367
+ -webkit-user-select:none;
368
+ -moz-user-select:none;
369
+ user-select:none;
370
+ pointer-events:none;
371
+ }
372
+
373
+ :is(.annotationLayer .annotationTextContent) span{
374
+ width:100%;
375
+ display:inline-block;
376
+ }
377
+
378
+ .annotationLayer svg.quadrilateralsContainer{
379
+ contain:strict;
380
+ width:0;
381
+ height:0;
382
+ position:absolute;
383
+ top:0;
384
+ left:0;
385
+ z-index:-1;
386
+ }
387
+ `;
@@ -0,0 +1,6 @@
1
+ import { type FileViewerPdfSignatureDictionary } from '@file-viewer/core';
2
+ export declare const enableFileViewerPdfSignatureInspection: () => () => void;
3
+ export declare const readPdfSignatureDictionaries: (bytes: Uint8Array, signal: AbortSignal) => Promise<{
4
+ signatures: FileViewerPdfSignatureDictionary[];
5
+ warnings: string[];
6
+ }>;
@@ -0,0 +1,228 @@
1
+ import { registerFileViewerPdfSignatureReader } from '@file-viewer/core';
2
+ import { PDFArray, PDFContext, PDFDict, PDFHexString, PDFName, PDFNumber, PDFObjectParser, PDFParser, PDFRawStream, PDFRef, PDFString, decodePDFRawStream } from 'pdf-lib';
3
+ const MAX_INPUT = 64 * 1024 * 1024;
4
+ const MAX_STREAM = 4 * 1024 * 1024;
5
+ const MAX_DECODED = 16 * 1024 * 1024;
6
+ const MAX_OBJECTS = 50000;
7
+ const MAX_NODES = 200000;
8
+ const MAX_DEPTH = 64;
9
+ const MAX_SIGNATURES = 64;
10
+ const name = (key) => PDFName.of(key);
11
+ const cursor = (parser) => parser.bytes.offset();
12
+ export const enableFileViewerPdfSignatureInspection = () => registerFileViewerPdfSignatureReader(readPdfSignatureDictionaries);
13
+ export const readPdfSignatureDictionaries = async (bytes, signal) => {
14
+ if (!bytes.length || bytes.length > MAX_INPUT)
15
+ throw new Error('PDF signature inspection input exceeds its boundary.');
16
+ const deadline = Date.now() + 20000;
17
+ let objects = 0, nodes = 0, decodedBytes = 0;
18
+ const guard = () => {
19
+ if (signal.aborted)
20
+ throw signal.reason || new Error('PDF metadata inspection cancelled.');
21
+ if (Date.now() > deadline)
22
+ throw new Error('PDF metadata inspection timed out.');
23
+ if (objects > MAX_OBJECTS || nodes > MAX_NODES)
24
+ throw new Error('PDF metadata object/node limit exceeded.');
25
+ };
26
+ const candidates = [];
27
+ const captured = new WeakMap();
28
+ const capture = (dictionary, ref) => {
29
+ if (!dictionary.has(name('ByteRange')) && dictionary.get(name('Type')) !== name('Sig'))
30
+ return;
31
+ const previous = captured.get(dictionary);
32
+ if (previous) {
33
+ if (ref)
34
+ previous.ref = ref.toString();
35
+ return;
36
+ }
37
+ if (candidates.length >= MAX_SIGNATURES)
38
+ throw new Error('PDF signature dictionary count exceeds its limit.');
39
+ const candidate = { ref: (ref === null || ref === void 0 ? void 0 : ref.toString()) || 'direct dictionary', dictionary, sequence: candidates.length + 1 };
40
+ captured.set(dictionary, candidate);
41
+ candidates.push(candidate);
42
+ };
43
+ const parser = PDFParser.forBytesWithOptions(bytes, 25, true);
44
+ const context = parser.context;
45
+ const assign = context.assign.bind(context);
46
+ context.assign = (ref, object) => {
47
+ objects++;
48
+ guard();
49
+ if (object instanceof PDFDict)
50
+ capture(object, ref);
51
+ assign(ref, object);
52
+ };
53
+ const number = (object, max) => {
54
+ if (!(object instanceof PDFNumber))
55
+ throw new Error('Unsupported indirect or non-numeric PDF metadata parameter.');
56
+ const value = object.asNumber();
57
+ if (!Number.isSafeInteger(value) || value < 0 || value > max)
58
+ throw new Error('PDF metadata numeric parameter exceeds its boundary.');
59
+ return value;
60
+ };
61
+ const trailingWhitespace = (source, offset) => {
62
+ while (offset < source.length) {
63
+ const value = source[offset++];
64
+ if ([0, 9, 10, 12, 13, 32].includes(value))
65
+ continue;
66
+ if (value === 37) {
67
+ while (offset < source.length && source[offset] !== 10 && source[offset] !== 13)
68
+ offset++;
69
+ continue;
70
+ }
71
+ throw new Error('Unsupported trailing tokens in a PDF object stream.');
72
+ }
73
+ };
74
+ const decodedStream = (stream) => {
75
+ const filter = stream.dict.get(name('Filter'));
76
+ if (filter && (!(filter instanceof PDFName) || !['FlateDecode', 'Fl'].includes(filter.decodeText())))
77
+ throw new Error('PDF metadata supports only a single bounded FlateDecode structural stream filter.');
78
+ const decoded = decodePDFRawStream(stream);
79
+ if (decoded.ensureBuffer) {
80
+ const ensure = decoded.ensureBuffer.bind(decoded);
81
+ decoded.ensureBuffer = length => {
82
+ guard();
83
+ if (length > MAX_STREAM + 1)
84
+ throw new Error('Decoded PDF structural stream exceeds its limit.');
85
+ return ensure(length);
86
+ };
87
+ }
88
+ const output = decoded.getBytes(MAX_STREAM + 1);
89
+ decodedBytes += output.length;
90
+ if (output.length > MAX_STREAM || decodedBytes > MAX_DECODED || output.length > Math.max(1, stream.contents.length) * 200)
91
+ throw new Error('PDF structural stream expansion exceeds its boundary.');
92
+ return new Uint8Array(output.buffer, output.byteOffset, output.byteLength);
93
+ };
94
+ const boundedParser = (reader, allowStreams) => {
95
+ const parse = reader.parseObject.bind(reader);
96
+ let depth = 0;
97
+ reader.parseObject = () => {
98
+ var _a, _b;
99
+ nodes++;
100
+ guard();
101
+ if (++depth > MAX_DEPTH) {
102
+ depth--;
103
+ throw new Error('PDF metadata nesting limit exceeded.');
104
+ }
105
+ try {
106
+ const object = parse();
107
+ if (object instanceof PDFDict)
108
+ capture(object);
109
+ if (!(object instanceof PDFRawStream))
110
+ return object;
111
+ if (!allowStreams)
112
+ throw new Error('Nested streams in a PDF object stream are unsupported.');
113
+ const type = object.dict.get(name('Type'));
114
+ if (type instanceof PDFRef)
115
+ throw new Error('Indirect PDF stream Type is unsupported for bounded metadata inspection.');
116
+ if (type !== name('ObjStm') && type !== name('XRef'))
117
+ return object;
118
+ if (type === name('XRef')) {
119
+ for (const key of ['Root', 'Encrypt', 'Info', 'ID']) {
120
+ const value = object.dict.get(name(key));
121
+ if (value)
122
+ context.trailerInfo[key] = value;
123
+ }
124
+ return object.dict;
125
+ }
126
+ const decoded = decodedStream(object);
127
+ if (type === name('ObjStm')) {
128
+ const count = number(object.dict.get(name('N')), 1024);
129
+ const first = number(object.dict.get(name('First')), decoded.length);
130
+ const header = boundedParser(PDFObjectParser.forBytes(decoded.subarray(0, first), context), false);
131
+ const entries = [];
132
+ const seen = new Set();
133
+ for (let index = 0; index < count; index++) {
134
+ const objectNumber = number(header.parseObject(), 0x7fffffff);
135
+ const offset = number(header.parseObject(), decoded.length - first);
136
+ if (!objectNumber || seen.has(objectNumber) || (index && offset < entries[index - 1].offset))
137
+ throw new Error('Unsupported duplicate or unordered PDF object-stream entries.');
138
+ seen.add(objectNumber);
139
+ entries.push({ number: objectNumber, offset });
140
+ }
141
+ trailingWhitespace(decoded.subarray(0, first), cursor(header));
142
+ for (let index = 0; index < entries.length; index++) {
143
+ guard();
144
+ const entry = entries[index];
145
+ const part = decoded.subarray(first + entry.offset, first + ((_b = (_a = entries[index + 1]) === null || _a === void 0 ? void 0 : _a.offset) !== null && _b !== void 0 ? _b : decoded.length - first));
146
+ const nested = boundedParser(PDFObjectParser.forBytes(part, context), false);
147
+ const value = nested.parseObject();
148
+ trailingWhitespace(part, cursor(nested));
149
+ context.assign(PDFRef.of(entry.number, 0), value);
150
+ }
151
+ return object.dict;
152
+ }
153
+ return object.dict;
154
+ }
155
+ finally {
156
+ depth--;
157
+ }
158
+ };
159
+ return reader;
160
+ };
161
+ boundedParser(parser, true);
162
+ try {
163
+ await parser.parseDocument();
164
+ }
165
+ catch (error) {
166
+ if (signal.aborted)
167
+ throw signal.reason || new Error('PDF metadata inspection cancelled.');
168
+ throw error;
169
+ }
170
+ guard();
171
+ if (context.trailerInfo.Encrypt)
172
+ throw new Error('Encrypted PDF metadata is unsupported; no decryption was performed.');
173
+ const signatures = [];
174
+ const text = (object) => {
175
+ if (object instanceof PDFName)
176
+ return object.decodeText();
177
+ if (object instanceof PDFString || object instanceof PDFHexString) {
178
+ if (object.asBytes().length > 32768)
179
+ throw new Error('PDF signature text field exceeds its limit.');
180
+ return object.decodeText();
181
+ }
182
+ return undefined;
183
+ };
184
+ for (const candidate of candidates) {
185
+ guard();
186
+ const dictionary = candidate.dictionary;
187
+ const contentsObject = dictionary.get(name('Contents'));
188
+ const contents = contentsObject instanceof PDFString || contentsObject instanceof PDFHexString ? contentsObject.asBytes() : undefined;
189
+ const rangeObject = dictionary.get(name('ByteRange'));
190
+ if ((!(contents === null || contents === void 0 ? void 0 : contents.length) || contents.every(value => value === 0)) && (!rangeObject || (rangeObject instanceof PDFArray && rangeObject.asArray().every(value => value instanceof PDFNumber && value.asNumber() === 0))))
191
+ continue;
192
+ if (!contentsObject && !rangeObject)
193
+ continue;
194
+ if (contents && contents.length > 8 * 1024 * 1024)
195
+ throw new Error('PDF CMS contents exceed the metadata limit.');
196
+ const warnings = [];
197
+ let byteRange;
198
+ if (rangeObject instanceof PDFArray && rangeObject.size() >= 4 && rangeObject.size() <= 16 && rangeObject.size() % 2 === 0) {
199
+ try {
200
+ const ranges = rangeObject.asArray().map(value => number(value, bytes.length));
201
+ let end = 0;
202
+ if (ranges[0] !== 0)
203
+ throw new Error('ByteRange does not start at the original source.');
204
+ for (let index = 0; index < ranges.length; index += 2) {
205
+ const start = ranges[index], length = ranges[index + 1];
206
+ if (start < end || start + length > bytes.length)
207
+ throw new Error('ByteRange is outside the source or overlaps.');
208
+ end = start + length;
209
+ }
210
+ byteRange = ranges;
211
+ }
212
+ catch {
213
+ warnings.push('ByteRange is unsupported or incomplete; signature validity is not checked.');
214
+ }
215
+ }
216
+ else
217
+ warnings.push('ByteRange is missing or unsupported; signature validity is not checked.');
218
+ if (!contents)
219
+ warnings.push('Direct CMS contents are missing or unsupported.');
220
+ const revisionEnd = byteRange ? byteRange[byteRange.length - 2] + byteRange[byteRange.length - 1] : undefined;
221
+ signatures.push({
222
+ id: `${candidate.ref} / source definition ${candidate.sequence}`, contents, byteRange, revisionEnd,
223
+ fields: Object.fromEntries(['Filter', 'SubFilter', 'Name', 'M', 'Reason', 'Location', 'ContactInfo'].map(key => [key, text(dictionary.get(name(key)))])),
224
+ warnings: [...warnings, 'Original-source dictionary metadata only; active-field ownership, signed revision coverage and integrity were not verified.', ...(revisionEnd !== undefined && revisionEnd < bytes.length ? ['Bytes follow the declared ByteRange; later changes were not checked.'] : [])],
225
+ });
226
+ }
227
+ return { signatures, warnings: [] };
228
+ };