diff --git a/internal/document/clean/pdf_test.go b/internal/document/clean/pdf_test.go index 61459b19..ac67e9dc 100644 --- a/internal/document/clean/pdf_test.go +++ b/internal/document/clean/pdf_test.go @@ -31,6 +31,69 @@ func TestIsCorrupt(t *testing.T) { reason := pdf.isCorrupted(ctx) assert.Equal(t, InvalidDocumentLargeFile, *reason) }) + t.Run("version 1.0", func(t *testing.T) { + ctx := context.Background() + pdf := NewPDF(strings.NewReader(PDF1_0)) + + reason := pdf.isCorrupted(ctx) + assert.Nil(t, reason) + }) + t.Run("version 1.1", func(t *testing.T) { + ctx := context.Background() + pdf := NewPDF(strings.NewReader(PDF1_1)) + + reason := pdf.isCorrupted(ctx) + assert.Nil(t, reason) + }) + t.Run("version 1.2", func(t *testing.T) { + ctx := context.Background() + pdf := NewPDF(strings.NewReader(PDF1_2)) + + reason := pdf.isCorrupted(ctx) + assert.Nil(t, reason) + }) + t.Run("version 1.3", func(t *testing.T) { + ctx := context.Background() + pdf := NewPDF(strings.NewReader(PDF1_3)) + + reason := pdf.isCorrupted(ctx) + assert.Nil(t, reason) + }) + t.Run("version 1.4", func(t *testing.T) { + ctx := context.Background() + pdf := NewPDF(strings.NewReader(PDF1_4)) + + reason := pdf.isCorrupted(ctx) + assert.Nil(t, reason) + }) + t.Run("version 1.5", func(t *testing.T) { + ctx := context.Background() + pdf := NewPDF(strings.NewReader(PDF1_5)) + + reason := pdf.isCorrupted(ctx) + assert.Nil(t, reason) + }) + t.Run("version 1.6", func(t *testing.T) { + ctx := context.Background() + pdf := NewPDF(strings.NewReader(PDF1_6)) + + reason := pdf.isCorrupted(ctx) + assert.Nil(t, reason) + }) + t.Run("version 1.7", func(t *testing.T) { + ctx := context.Background() + pdf := NewPDF(strings.NewReader(PDF1_7)) + + reason := pdf.isCorrupted(ctx) + assert.Nil(t, reason) + }) + t.Run("version 2.0", func(t *testing.T) { + ctx := context.Background() + pdf := NewPDF(strings.NewReader(PDF2_0)) + + reason := pdf.isCorrupted(ctx) + assert.Nil(t, reason) + }) } func TestNewPDF(t *testing.T) { @@ -41,3 +104,637 @@ func TestNewPDF(t *testing.T) { assert.Equal(t, 3000, pdf.maxPages) }) } + +const PDF1_0 = `%PDF-1.0 +%¥±ë % Binary comment for PDF parsers + +1 0 obj +<< /Type /Catalog + /Pages 2 0 R +>> +endobj + +2 0 obj +<< /Type /Pages + /Kids [3 0 R] + /Count 1 +>> +endobj + +3 0 obj +<< /Type /Page + /Parent 2 0 R + /MediaBox [0 0 612 792] + /Contents 4 0 R + /Resources << /ProcSet [/PDF /Text] + /Font << /F1 5 0 R >> + >> +>> +endobj + +4 0 obj +<< /Length 52 >> +stream +BT +/F1 24 Tf +100 700 Td +(PDF 1.0 Example) Tj +ET +endstream +endobj + +5 0 obj +<< /Type /Font + /Subtype /Type1 + /BaseFont /Helvetica +>> +endobj + +xref +0 6 +0000000000 65535 f +0000000018 00000 n +0000000072 00000 n +0000000134 00000 n +0000000309 00000 n +0000000411 00000 n +trailer +<< /Size 6 + /Root 1 0 R +>> +startxref +485 +%%EOF` + +const PDF1_1 = `%PDF-1.1 +%âãÏÓ + +1 0 obj +<< /Type /Catalog + /Pages 2 0 R +>> +endobj + +2 0 obj +<< /Type /Pages + /Kids [3 0 R] + /Count 1 +>> +endobj + +3 0 obj +<< /Type /Page + /Parent 2 0 R + /MediaBox [0 0 612 792] + /Contents 4 0 R + /Resources << /ProcSet [/PDF /Text] + /Font << /F1 5 0 R >> + >> +>> +endobj + +4 0 obj +<< /Length 52 >> +stream +BT +/F1 24 Tf +100 700 Td +(PDF 1.1 Example) Tj +ET +endstream +endobj + +5 0 obj +<< /Type /Font + /Subtype /Type1 + /BaseFont /Helvetica +>> +endobj + +xref +0 6 +0000000000 65535 f +0000000018 00000 n +0000000072 00000 n +0000000134 00000 n +0000000309 00000 n +0000000411 00000 n +trailer +<< /Size 6 + /Root 1 0 R +>> +startxref +485 +%%EOF` + +const PDF1_2 = `%PDF-1.2 +1 0 obj +<< /Type /Catalog + /Pages 2 0 R +>> +endobj + +2 0 obj +<< /Type /Pages + /Kids [3 0 R] + /Count 1 +>> +endobj + +3 0 obj +<< /Type /Page + /Parent 2 0 R + /MediaBox [0 0 612 792] + /Contents 4 0 R +>> +endobj + +4 0 obj +<< /Length 65 /Filter /FlateDecode >> +stream +x�s +�2�30W0 P&� � +� +� +�(X�Y��\��R!$�K��H����PS!$��RR�P�� �)� +endstream +endobj + +xref +0 5 +0000000000 65535 f +0000000009 00000 n +0000000063 00000 n +0000000125 00000 n +0000000210 00000 n +trailer +<< /Size 5 + /Root 1 0 R +>> +startxref +325 +%%EOF` + +const PDF1_3 = `%PDF-1.3 +1 0 obj +<< /Type /Catalog + /Pages 2 0 R +>> +endobj + +2 0 obj +<< /Type /Pages + /Kids [3 0 R] + /Count 1 +>> +endobj + +3 0 obj +<< /Type /Page + /Parent 2 0 R + /MediaBox [0 0 612 792] + /Contents 4 0 R + /Resources << /ProcSet [/PDF /Text] + /Font << /F1 5 0 R >> + >> +>> +endobj + +4 0 obj +<< /Length 52 >> +stream +BT +/F1 24 Tf +100 700 Td +(PDF 1.3 Example) Tj +ET +endstream +endobj + +5 0 obj +<< /Type /Font + /Subtype /Type1 + /BaseFont /Helvetica +>> +endobj + +xref +0 6 +0000000000 65535 f +0000000009 00000 n +0000000063 00000 n +0000000125 00000 n +0000000300 00000 n +0000000402 00000 n +trailer +<< /Size 6 + /Root 1 0 R +>> +startxref +476 +%%EOF` + +const PDF1_4 = `%PDF-1.4 +1 0 obj +<< /Type /Catalog + /Pages 2 0 R +>> +endobj + +2 0 obj +<< /Type /Pages + /Kids [3 0 R] + /Count 1 +>> +endobj + +3 0 obj +<< /Type /Page + /Parent 2 0 R + /MediaBox [0 0 612 792] + /Contents 4 0 R + /Resources << /ProcSet [/PDF /Text] + /Font << /F1 5 0 R >> + /ExtGState << /GS1 6 0 R >> + >> +>> +endobj + +4 0 obj +<< /Length 78 >> +stream +BT +/F1 24 Tf +100 700 Td +(PDF 1.4 Example with Transparency) Tj +ET +endstream +endobj + +5 0 obj +<< /Type /Font + /Subtype /Type1 + /BaseFont /Helvetica +>> +endobj + +6 0 obj +<< /Type /ExtGState + /ca 0.5 + /CA 0.5 +>> +endobj + +xref +0 7 +0000000000 65535 f +0000000009 00000 n +0000000063 00000 n +0000000125 00000 n +0000000342 00000 n +0000000470 00000 n +0000000544 00000 n +trailer +<< /Size 7 + /Root 1 0 R +>> +startxref +603 +%%EOF` + +const PDF1_5 = `%PDF-1.5 +1 0 obj +<< /Type /Catalog + /Pages 2 0 R + /Version /1.5 +>> +endobj + +2 0 obj +<< /Type /Pages + /Kids [3 0 R] + /Count 1 +>> +endobj + +3 0 obj +<< /Type /Page + /Parent 2 0 R + /MediaBox [0 0 612 792] + /Contents 4 0 R + /Resources << /ProcSet [/PDF /Text] + /Font << /F1 5 0 R >> + >> +>> +endobj + +4 0 obj +<< /Length 52 >> +stream +BT +/F1 24 Tf +100 700 Td +(PDF 1.5 Example) Tj +ET +endstream +endobj + +5 0 obj +<< /Type /Font + /Subtype /Type1 + /BaseFont /Helvetica +>> +endobj + +6 0 obj +<< /Type /ObjStm + /N 1 + /First 4 + /Length 19 +>> +stream +7 0 << /Im 8 0 R >> +endstream +endobj + +xref +0 7 +0000000000 65535 f +0000000009 00000 n +0000000075 00000 n +0000000137 00000 n +0000000312 00000 n +0000000414 00000 n +0000000488 00000 n +trailer +<< /Size 7 + /Root 1 0 R +>> +startxref +585 +%%EOF` + +const PDF1_6 = `%PDF-1.6 +1 0 obj +<< /Type /Catalog + /Pages 2 0 R + /Version /1.6 +>> +endobj + +2 0 obj +<< /Type /Pages + /Kids [3 0 R] + /Count 1 +>> +endobj + +3 0 obj +<< /Type /Page + /Parent 2 0 R + /MediaBox [0 0 612 792] + /Contents 4 0 R + /Resources << /ProcSet [/PDF /Text] + /Font << /F1 5 0 R >> + >> + /Annots [6 0 R] +>> +endobj + +4 0 obj +<< /Length 52 >> +stream +BT +/F1 24 Tf +100 700 Td +(PDF 1.6 Example) Tj +ET +endstream +endobj + +5 0 obj +<< /Type /Font + /Subtype /Type1 + /BaseFont /Helvetica +>> +endobj + +6 0 obj +<< /Type /Annot + /Subtype /3D + /Rect [100 100 400 500] + /3DD 7 0 R + /AP << /N 8 0 R >> +>> +endobj + +7 0 obj +<< /Type /3DStream + /Subtype /U3D + /Length 14 +>> +stream +Placeholder3D +endstream +endobj + +8 0 obj +<< /Type /XObject + /Subtype /Form + /BBox [0 0 300 400] + /Length 25 +>> +stream +q +1 0 0 1 0 0 cm +/Fm1 Do +Q +endstream +endobj + +xref +0 9 +0000000000 65535 f +0000000009 00000 n +0000000075 00000 n +0000000137 00000 n +0000000332 00000 n +0000000434 00000 n +0000000508 00000 n +0000000621 00000 n +0000000708 00000 n +trailer +<< /Size 9 + /Root 1 0 R +>> +startxref +835 +%%EOF` + +const PDF1_7 = `%PDF-1.7 +1 0 obj +<< /Type /Catalog + /Pages 2 0 R + /Version /1.7 +>> +endobj + +2 0 obj +<< /Type /Pages + /Kids [3 0 R] + /Count 1 +>> +endobj + +3 0 obj +<< /Type /Page + /Parent 2 0 R + /MediaBox [0 0 612 792] + /Contents 4 0 R + /Resources << /ProcSet [/PDF /Text] + /Font << /F1 5 0 R >> + >> + /Annots [6 0 R] +>> +endobj + +4 0 obj +<< /Length 52 >> +stream +BT +/F1 24 Tf +100 700 Td +(PDF 1.7 Example) Tj +ET +endstream +endobj + +5 0 obj +<< /Type /Font + /Subtype /Type1 + /BaseFont /Helvetica +>> +endobj + +6 0 obj +<< /Type /Annot + /Subtype /RichMedia + /Rect [100 100 400 500] + /RichMediaContent 7 0 R +>> +endobj + +7 0 obj +<< /Type /RichMediaContent + /Assets 8 0 R + /Configurations [9 0 R] +>> +endobj + +8 0 obj +<< /Names [(asset1) 10 0 R] +>> +endobj + +9 0 obj +<< /Type /RichMediaConfiguration + /Instances [<< /Asset (asset1) >>] +>> +endobj + +10 0 obj +<< /Type /Filespec + /F (media.mp4) + /EF << /F 11 0 R >> +>> +endobj + +11 0 obj +<< /Length 22 >> +stream +PlaceholderMediaContent +endstream +endobj + +xref +0 12 +0000000000 65535 f +0000000009 00000 n +0000000075 00000 n +0000000137 00000 n +0000000332 00000 n +0000000434 00000 n +0000000508 00000 n +0000000612 00000 n +0000000696 00000 n +0000000741 00000 n +0000000826 00000 n +0000000901 00000 n +trailer +<< /Size 12 + /Root 1 0 R +>> +startxref +975 +%%EOF` + +const PDF2_0 = `%PDF-2.0 +%âãÏÓ + +1 0 obj +<< /Type /Catalog + /Pages 2 0 R +>> +endobj + +2 0 obj +<< /Type /Pages + /Kids [3 0 R] + /Count 1 +>> +endobj + +3 0 obj +<< /Type /Page + /Parent 2 0 R + /MediaBox [0 0 612 792] + /Contents 4 0 R + /Resources << /ProcSet [/PDF /Text] + /Font << /F1 5 0 R >> + >> +>> +endobj + +4 0 obj +<< /Length 52 >> +stream +BT +/F1 24 Tf +100 700 Td +(PDF 2.0 Example) Tj +ET +endstream +endobj + +5 0 obj +<< /Type /Font + /Subtype /Type1 + /BaseFont /Helvetica +>> +endobj + +xref +0 6 +0000000000 65535 f +0000000018 00000 n +0000000072 00000 n +0000000134 00000 n +0000000309 00000 n +0000000411 00000 n +trailer +<< /Size 6 + /Root 1 0 R +>> +startxref +485 +%%EOF`