fix(pdf): bounded attachment extraction by byte scan — no pdf-lib parse on import, export without object streams (BLK-009)

This commit is contained in:
bchanot committed 2026-10-11 16:42:45 +02:00
1 parent 62b8a43e09
commit 60ee71208f
14 files changed
+1054 -198

No files matched your search

+9 -1
View File
@@ -149,6 +149,11 @@ describe('attachment presence and selection', () => {
await rejects(bytes, { kind: 'attachment_stripped' })
})
it('a stamped PDF saved with object streams (pre-BLK-009 layout): the stamp is invisible, no_attachment', async () => {
const bytes = await pdfWithoutAttachment(['faunosteo-archive/1'], true)
await rejects(bytes, { kind: 'no_attachment' })
})
it('a foreign PDF: no_attachment', async () => {
await rejects(await pdfWithoutAttachment(), { kind: 'no_attachment' })
const foreign = await pdfWithAttachment('other.json', { hello: 'world' })
@@ -166,10 +171,13 @@ describe('attachment presence and selection', () => {
expect(outcome.report).toEqual(golden.reports.demo)
})
it('refuses an oversized or unparseable PDF as invalid_pdf', async () => {
it('refuses an oversized file or one without a %PDF- header as invalid_pdf', async () => {
await rejects(new Uint8Array(MAX_PDF_BYTES + 1), { kind: 'invalid_pdf' })
await rejects(new TextEncoder().encode('not a pdf at all'), {
kind: 'invalid_pdf',
})
const late = new Uint8Array(2048)
late.set(new TextEncoder().encode('%PDF-1.7'), 1024)
await rejects(late, { kind: 'invalid_pdf' })
})
})