Skip to content

Commit 2223518

Browse files
committed
Merge branch 'develop' into devsecops
2 parents 6d2197a + 7941d36 commit 2223518

File tree

6 files changed

+55
-1
lines changed

6 files changed

+55
-1
lines changed

itext.tests/itext.sign.tests/itext/signatures/validation/DocumentRevisionsValidatorIntegrationTest.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,43 @@ public virtual void TaggedDocRemoveStructTreeElementTest(bool continueValidation
468468
}
469469
}
470470

471+
[NUnit.Framework.TestCaseSource("CreateParameters")]
472+
public virtual void AnnotationModificationAllowedTabsChangesTest(bool continueValidationAfterFail) {
473+
SetUp(continueValidationAfterFail);
474+
using (PdfDocument document = new PdfDocument(new PdfReader(SOURCE_FOLDER + "annotationModificationAllowedTabsChangesTest.pdf"
475+
))) {
476+
DocumentRevisionsValidator validator = builder.BuildDocumentRevisionsValidator();
477+
ValidationReport report = validator.ValidateAllDocumentRevisions(validationContext, document);
478+
AssertValidationReport.AssertThat(report, (a) => a.HasStatus(ValidationReport.ValidationResult.VALID).HasNumberOfLogs
479+
(0));
480+
}
481+
}
482+
483+
[NUnit.Framework.TestCaseSource("CreateParameters")]
484+
public virtual void AnnotationModificationNotAllowedTabsChangesTest(bool continueValidationAfterFail) {
485+
SetUp(continueValidationAfterFail);
486+
using (PdfDocument document = new PdfDocument(new PdfReader(SOURCE_FOLDER + "annotationModificationNotAllowedTabsChangesTest.pdf"
487+
))) {
488+
DocumentRevisionsValidator validator = builder.BuildDocumentRevisionsValidator();
489+
ValidationReport report = validator.ValidateAllDocumentRevisions(validationContext, document);
490+
AssertValidationReport.AssertThat(report, (a) => a.HasStatus(ValidationReport.ValidationResult.INVALID).HasNumberOfFailures
491+
(1).HasLogItem((l) => l.WithCheckName(DocumentRevisionsValidator.DOC_MDP_CHECK).WithMessage(DocumentRevisionsValidator
492+
.TABS_MODIFIED).WithStatus(ReportItem.ReportItemStatus.INVALID)));
493+
}
494+
}
495+
496+
[NUnit.Framework.TestCaseSource("CreateParameters")]
497+
public virtual void AnnotationModificationNotAllowedTabsSetToDefaultTest(bool continueValidationAfterFail) {
498+
SetUp(continueValidationAfterFail);
499+
using (PdfDocument document = new PdfDocument(new PdfReader(SOURCE_FOLDER + "annotationModificationNotAllowedTabsSetToDefaultTest.pdf"
500+
))) {
501+
DocumentRevisionsValidator validator = builder.BuildDocumentRevisionsValidator();
502+
ValidationReport report = validator.ValidateAllDocumentRevisions(validationContext, document);
503+
AssertValidationReport.AssertThat(report, (a) => a.HasStatus(ValidationReport.ValidationResult.VALID).HasNumberOfLogs
504+
(0));
505+
}
506+
}
507+
471508
[NUnit.Framework.TestCaseSource("CreateParameters")]
472509
public virtual void OutlinesNotModifiedTest(bool continueValidationAfterFail) {
473510
SetUp(continueValidationAfterFail);

itext/itext.sign/itext/signatures/validation/DocumentRevisionsValidator.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ public class DocumentRevisionsValidator {
152152
internal const String PAGE_MODIFIED = "Page was unexpectedly modified.";
153153
//\endcond
154154

155+
//\cond DO_NOT_DOCUMENT
156+
internal const String TABS_MODIFIED = "Tabs entry in a page dictionary was unexpectedly modified.";
157+
//\endcond
158+
155159
//\cond DO_NOT_DOCUMENT
156160
internal const String PERMISSIONS_REMOVED = "Permissions dictionary was removed from the catalog.";
157161
//\endcond
@@ -1510,15 +1514,21 @@ private bool ComparePages(PdfDictionary prevPages, PdfDictionary currPages, Vali
15101514
previousPageCopy.Remove(PdfName.Annots);
15111515
previousPageCopy.Remove(PdfName.Parent);
15121516
previousPageCopy.Remove(PdfName.StructParents);
1517+
previousPageCopy.Remove(PdfName.Tabs);
15131518
PdfDictionary currentPageCopy = new PdfDictionary(currentKid);
15141519
currentPageCopy.Remove(PdfName.Annots);
15151520
currentPageCopy.Remove(PdfName.Parent);
15161521
currentPageCopy.Remove(PdfName.StructParents);
1522+
currentPageCopy.Remove(PdfName.Tabs);
15171523
if (!ComparePdfObjects(previousPageCopy, currentPageCopy, usuallyModifiedObjects) || !CompareIndirectReferencesObjNums
15181524
(previousKid.Get(PdfName.Parent), currentKid.Get(PdfName.Parent), report, "Page parent")) {
15191525
report.AddReportItem(new ReportItem(DOC_MDP_CHECK, PAGE_MODIFIED, ReportItem.ReportItemStatus.INVALID));
15201526
return false;
15211527
}
1528+
if (!CompareTabs(previousKid.GetAsName(PdfName.Tabs), currentKid.GetAsName(PdfName.Tabs))) {
1529+
report.AddReportItem(new ReportItem(DOC_MDP_CHECK, TABS_MODIFIED, ReportItem.ReportItemStatus.INVALID));
1530+
return false;
1531+
}
15221532
PdfArray prevNotModifiableAnnots = GetAnnotsNotAllowedToBeModified(previousKid);
15231533
PdfArray currNotModifiableAnnots = GetAnnotsNotAllowedToBeModified(currentKid);
15241534
if (!ComparePageAnnotations(prevNotModifiableAnnots, currNotModifiableAnnots, report)) {
@@ -1533,6 +1543,13 @@ private bool ComparePages(PdfDictionary prevPages, PdfDictionary currPages, Vali
15331543
return true;
15341544
}
15351545

1546+
private bool CompareTabs(PdfName previousTabs, PdfName currentTabs) {
1547+
if (GetAccessPermissions() == AccessPermissions.ANNOTATION_MODIFICATION) {
1548+
return true;
1549+
}
1550+
return Object.Equals(previousTabs, currentTabs) || (previousTabs == null && currentTabs.Equals(PdfName.S));
1551+
}
1552+
15361553
private void CollectRemovedAndAddedAnnotations(PdfArray previousAnnotations, PdfArray currentAnnotations) {
15371554
ValidationReport dummyReport = new ValidationReport();
15381555
IList<PdfDictionary> prevAnnots = new List<PdfDictionary>();

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8d4fbb6308e2126af33891bf5ad981ec9f2fd81b
1+
ce35dbce51bd8c3f1b01e78313f1f5a2a02201ff

0 commit comments

Comments
 (0)