Skip to content

Commit 6632d2f

Browse files
author
Dmitry Radchuk
committed
Improve metadata parsing for pdf/a documents
DEVSIX-9088 Autoported commit. Original commit hash: [3b5d4bd4d] Manual files: kernel/src/main/java/com/itextpdf/kernel/xmp/impl/XMPUtilsImpl.java
1 parent 170c73f commit 6632d2f

File tree

9 files changed

+44
-3
lines changed

9 files changed

+44
-3
lines changed

itext.tests/itext.pdfa.tests/itext/pdfa/PdfAXmpTest.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ You should have received a copy of the GNU Affero General Public License
2929
using iText.Kernel.XMP;
3030
using iText.Kernel.XMP.Options;
3131
using iText.Test;
32+
using iText.Test.Attributes;
3233

3334
namespace iText.Pdfa {
3435
[NUnit.Framework.Category("IntegrationTest")]
@@ -112,6 +113,34 @@ public virtual void SaveAndReadDocumentWithCanonicalXmpMetadata() {
112113
}
113114
}
114115

116+
[NUnit.Framework.Test]
117+
public virtual void ReadDocumentWithControlCharactersInXMPMetadata() {
118+
String src = sourceFolder + "pdfs/docWithControlCharactersInXmp.pdf";
119+
using (PdfADocument document = new PdfADocument(new PdfReader(src), new PdfWriter(new MemoryStream()), new
120+
StampingProperties())) {
121+
NUnit.Framework.Assert.AreEqual(PdfConformance.PDF_A_3A, document.GetConformance());
122+
}
123+
}
124+
125+
[NUnit.Framework.Test]
126+
public virtual void ReadDocumentWithInvalidConformance() {
127+
String src = sourceFolder + "pdfs/docWithInvalidConformance.pdf";
128+
using (PdfDocument document = new PdfDocument(new PdfReader(src), new PdfWriter(new MemoryStream()), new StampingProperties
129+
())) {
130+
NUnit.Framework.Assert.AreEqual(PdfConformance.PDF_NONE_CONFORMANCE, document.GetConformance());
131+
}
132+
}
133+
134+
[LogMessage(iText.IO.Logs.IoLogMessageConstant.EXCEPTION_WHILE_UPDATING_XMPMETADATA)]
135+
[NUnit.Framework.Test]
136+
public virtual void ReadDocumentWithInvalidXMPMetadata() {
137+
String src = sourceFolder + "pdfs/docWithInvalidMetadata.pdf";
138+
using (PdfDocument document = new PdfDocument(new PdfReader(src), new PdfWriter(new MemoryStream()), new StampingProperties
139+
())) {
140+
NUnit.Framework.Assert.AreEqual(PdfConformance.PDF_NONE_CONFORMANCE, document.GetConformance());
141+
}
142+
}
143+
115144
[NUnit.Framework.Test]
116145
public virtual void TestPdfUAExtensionMetadata() {
117146
String outFile = destinationFolder + "testPdfUAExtensionMetadata.pdf";
Binary file not shown.

itext/itext.commons/itext/commons/utils/PushbackReader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public override int Read() {
7575
/// <param name="off"> Offset at which to start writing characters </param>
7676
/// <param name="len"> Maximum number of characters to read
7777
/// </param>
78-
/// <returns> The number of characters read, or -1 if the end of the
78+
/// <returns> The number of characters read, or 0 if the end of the
7979
/// stream has been reached
8080
/// </returns>
8181
public override int Read(char[] cbuf, int off, int len) {

itext/itext.kernel/itext/kernel/pdf/PdfReader.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,7 @@ public virtual PdfConformance GetPdfConformance() {
674674
pdfConformance = PdfConformance.GetConformance(xmpMeta);
675675
}
676676
catch (XMPException) {
677+
pdfConformance = PdfConformance.PDF_NONE_CONFORMANCE;
677678
}
678679
}
679680
return pdfConformance;

itext/itext.kernel/itext/kernel/xmp/impl/FixASCIIControlsReader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public override int Read(char[] cbuf, int off, int len) {
103103
}
104104
}
105105
}
106-
return read > 0 || available ? read : -1;
106+
return read > 0 || available ? read : XMPUtilsImpl.EofReadBytesValue();
107107
}
108108

109109
/// <summary>Processes numeric escaped chars to find out if they are a control character.</summary>

itext/itext.kernel/itext/kernel/xmp/impl/XMPUtilsImpl.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ private XMPUtilsImpl()
5757
{
5858
}
5959

60+
/// <summary>
61+
/// Return value when eof encountered of <seealso cref="System.IO.TextReader.Read(char[], int, int)"/>.
62+
/// </summary>
63+
/// <returns>
64+
/// platform dependent eof read value (0 for C#)
65+
/// </returns>
66+
public static int EofReadBytesValue()
67+
{
68+
return 0;
69+
}
70+
6071
// EMPTY
6172
/// <seealso cref="iText.Kernel.XMP.XMPUtils.CatenateArrayItems(iText.Kernel.XMP.XMPMeta, System.String, System.String, System.String, System.String, bool)
6273
/// "/>

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6691f70abaf4119ab2e862f6b708e46bb3e76666
1+
3ccc99bd8391813f729cf2b6c656252687f17629

0 commit comments

Comments
 (0)