Skip to content

Commit abc0dab

Browse files
borislucas-deviText-CI
authored andcommitted
Ignore invalid catalog version on document load
Some invalid values in the optional Version field of the Catalog caused an exception on PDFDocument construction. It is now ignored and the document is created successfully. Closes 65. Autoported commit. Original commit hash: [6bf4ecfb0]
1 parent fe6c6cc commit abc0dab

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

itext.tests/itext.kernel.tests/itext/kernel/pdf/PdfDocumentTest.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,13 @@ public virtual void RemovePageWithInvalidOutlineTest() {
437437
));
438438
}
439439

440+
[NUnit.Framework.Test]
441+
public virtual void OpenDocumentWithInvalidCatalogVersionTest() {
442+
PdfReader reader = new PdfReader(SOURCE_FOLDER + "sample-with-invalid-catalog-version.pdf");
443+
PdfDocument pdfDocument = new PdfDocument(reader);
444+
NUnit.Framework.Assert.IsNotNull(pdfDocument);
445+
}
446+
440447
private class IgnoreTagStructurePdfDocument : PdfDocument {
441448
internal IgnoreTagStructurePdfDocument(PdfReader reader)
442449
: base(reader) {

itext/itext.kernel/itext/kernel/pdf/PdfDocument.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1971,9 +1971,13 @@ protected internal virtual void Open(PdfVersion newPdfVersion) {
19711971
if (catalog.GetPdfObject().ContainsKey(PdfName.Version)) {
19721972
// The version of the PDF specification to which the document conforms (for example, 1.4)
19731973
// if later than the version specified in the file's header
1974-
PdfVersion catalogVersion = PdfVersion.FromPdfName(catalog.GetPdfObject().GetAsName(PdfName.Version));
1975-
if (catalogVersion.CompareTo(pdfVersion) > 0) {
1976-
pdfVersion = catalogVersion;
1974+
try {
1975+
PdfVersion catalogVersion = PdfVersion.FromPdfName(catalog.GetPdfObject().GetAsName(PdfName.Version));
1976+
if (catalogVersion.CompareTo(pdfVersion) > 0) {
1977+
pdfVersion = catalogVersion;
1978+
}
1979+
}
1980+
catch (ArgumentException) {
19771981
}
19781982
}
19791983
PdfStream xmpMetadataStream = catalog.GetPdfObject().GetAsStream(PdfName.Metadata);

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9c36eb28befb33da8e432e51468f2f845f484d1d
1+
6bf4ecfb0e4a409b1e5f2096045ca741e3fb854e

0 commit comments

Comments
 (0)