Skip to content

Commit

Permalink
Merge branch 'develop' into devsecops
Browse files Browse the repository at this point in the history
  • Loading branch information
aleks-ivanov committed Jun 26, 2024
2 parents 00d289c + e77c360 commit a671955
Show file tree
Hide file tree
Showing 22 changed files with 165 additions and 20 deletions.
75 changes: 75 additions & 0 deletions itext.tests/itext.io.tests/itext/io/util/ZlibUtilTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2024 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using System.IO;
using iText.Commons.Utils;
using iText.IO.Source;
using iText.Test;

namespace iText.IO.Util {
[NUnit.Framework.Category("IntegrationTest")]
public class ZlibUtilTest : ExtendedITextTest {
private static readonly String SOURCE_FOLDER = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/itext/io/util/";

private static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/itext/io/util/";

[NUnit.Framework.SetUp]
public virtual void SetUp() {
CreateOrClearDestinationFolder(DESTINATION_FOLDER);
}

[NUnit.Framework.Test]
public virtual void ArrayIndexOutOfBoundsDeflateTest() {
// Test file is taken from https://issues.jenkins.io/browse/JENKINS-19473
// Unzip test file first
using (ZipFileReader reader = new ZipFileReader(SOURCE_FOLDER + "jzlib.zip")) {
using (Stream @is = reader.ReadFromZip("jzlib.fail")) {
using (Stream os = FileUtil.GetFileOutputStream(DESTINATION_FOLDER + "jzlib.fail")) {
byte[] buf = new byte[8192];
int length;
while ((length = @is.Read(buf)) != -1) {
os.Write(buf, 0, length);
}
}
}
}
// Deflate it
using (Stream is_1 = FileUtil.GetInputStreamForFile(DESTINATION_FOLDER + "jzlib.fail")) {
using (Stream os_1 = FileUtil.GetFileOutputStream(DESTINATION_FOLDER + "jzlib.fail.zz")) {
// -1 stands for default compression
using (DeflaterOutputStream zip = new DeflaterOutputStream(os_1, -1)) {
byte[] buf = new byte[8192];
int length;
while ((length = is_1.Read(buf)) != -1) {
zip.Write(buf, 0, length);
}
}
}
}
NUnit.Framework.Assert.IsTrue(FileUtil.FileExists(DESTINATION_FOLDER + "jzlib.fail.zz"));
NUnit.Framework.Assert.IsTrue(FileUtil.IsFileNotEmpty(DESTINATION_FOLDER + "jzlib.fail.zz"));
}
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ You should have received a copy of the GNU Affero General Public License
using iText.Test.Pdfa;

namespace iText.Pdfa {
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
[NUnit.Framework.Category("IntegrationTest")]
public class PdfA2AnnotationCheckTest : ExtendedITextTest {
public static readonly String sourceFolder = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ You should have received a copy of the GNU Affero General Public License
using iText.Test.Pdfa;

namespace iText.Pdfa {
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
[NUnit.Framework.Category("IntegrationTest")]
public class PdfA2LayoutOcgTest : ExtendedITextTest {
public static readonly String sourceFolder = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ You should have received a copy of the GNU Affero General Public License
using iText.Test.Pdfa;

namespace iText.Pdfa {
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
[NUnit.Framework.Category("IntegrationTest")]
public class PdfA2OCPropertiesTest : ExtendedITextTest {
public static readonly String SOURCE_FOLDER = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ You should have received a copy of the GNU Affero General Public License
using iText.Test.Pdfa;

namespace iText.Pdfa {
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
[NUnit.Framework.Category("IntegrationTest")]
public class PdfA3CatalogCheckTest : ExtendedITextTest {
public static readonly String sourceFolder = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ You should have received a copy of the GNU Affero General Public License
using iText.Test.Pdfa;

namespace iText.Pdfa {
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
[NUnit.Framework.Category("IntegrationTest")]
public class PdfA4AnnotationCheckTest : ExtendedITextTest {
private static readonly String SOURCE_FOLDER = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ You should have received a copy of the GNU Affero General Public License
using iText.Test.Pdfa;

namespace iText.Pdfa {
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
[NUnit.Framework.Category("IntegrationTest")]
public class PdfA4CatalogCheckTest : ExtendedITextTest {
public static readonly String sourceFolder = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ You should have received a copy of the GNU Affero General Public License
using iText.Test.Pdfa;

namespace iText.Pdfa {
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
[NUnit.Framework.Category("IntegrationTest")]
public class PdfA4GraphicsCheckTest : ExtendedITextTest {
public static readonly String SOURCE_FOLDER = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ You should have received a copy of the GNU Affero General Public License
using iText.Test.Pdfa;

namespace iText.Pdfa {
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
[NUnit.Framework.Category("IntegrationTest")]
public class PdfA4TransparencyCheckTest : ExtendedITextTest {
public static readonly String SOURCE_FOLDER = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
Expand Down
1 change: 1 addition & 0 deletions itext.tests/itext.pdfa.tests/itext/pdfa/PdfAFontTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ You should have received a copy of the GNU Affero General Public License
using iText.Test.Pdfa;

namespace iText.Pdfa {
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
[NUnit.Framework.Category("IntegrationTest")]
public class PdfAFontTest : ExtendedITextTest {
//\cond DO_NOT_DOCUMENT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ You should have received a copy of the GNU Affero General Public License
using iText.Test.Pdfa;

namespace iText.Pdfa {
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
[NUnit.Framework.Category("IntegrationTest")]
public class PdfAFormFieldTest : ExtendedITextTest {
public static readonly String SOURCE_FOLDER = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ You should have received a copy of the GNU Affero General Public License
using iText.Test.Pdfa;

namespace iText.Pdfua {
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf/ua validation on Android)
[NUnit.Framework.Category("IntegrationTest")]
public class PdfUAAnnotationsTest : ExtendedITextTest {
private static readonly String SOURCE_FOLDER = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
Expand Down Expand Up @@ -760,6 +761,7 @@ public virtual void Ua1PrinterMAnnotNotInTagStructureTest() {
NUnit.Framework.Assert.IsNotNull(new VeraPdfValidator().Validate(outPdf));
}

// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf/ua validation on Android)
private PdfTextAnnotation CreateRichTextAnnotation() {
PdfTextAnnotation annot = new PdfTextAnnotation(new Rectangle(100, 100, 100, 100));
annot.SetContents("Rich media annot");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ You should have received a copy of the GNU Affero General Public License
using iText.Test.Pdfa;

namespace iText.Pdfua {
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf/ua validation on Android)
/// <summary>Class that helps to test PDF/UA conformance.</summary>
/// <remarks>
/// Class that helps to test PDF/UA conformance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ You should have received a copy of the GNU Affero General Public License
using iText.Test.Pdfa;

namespace iText.Pdfua.Checkers {
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf/ua validation on Android)
[NUnit.Framework.Category("IntegrationTest")]
public class PdfUAHeadingsTest : ExtendedITextTest {
private static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ You should have received a copy of the GNU Affero General Public License
using iText.Test.Utils;

namespace iText.Pdfua.Checkers {
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf/ua validation on Android)
[NUnit.Framework.Category("IntegrationTest")]
public class PdfUAXfaTest : ExtendedITextTest {
private static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ You should have received a copy of the GNU Affero General Public License
using iText.Test.Pdfa;

namespace iText.Signatures.Sign {
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
[NUnit.Framework.Category("BouncyCastleIntegrationTest")]
public class PdfASigningTest : ExtendedITextTest {
public static readonly String sourceFolder = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ You should have received a copy of the GNU Affero General Public License
using iText.Test.Pdfa;

namespace iText.Signatures.Sign {
// Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf/ua validation on Android)
[NUnit.Framework.Category("BouncyCastleIntegrationTest")]
public class SignedAppearanceTextTest : ExtendedITextTest {
private static readonly IBouncyCastleFactory FACTORY = BouncyCastleFactoryCreator.GetFactory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,38 @@ public virtual void FunctionTest06() {
));
}

[NUnit.Framework.Test]
public virtual void StringTest01() {
RunTest("'a b c'", JavaUtil.ArraysAsList("a b c"), JavaUtil.ArraysAsList(CssDeclarationValueTokenizer.TokenType
.STRING));
}

[NUnit.Framework.Test]
public virtual void StringTest02() {
RunTest("\"a b c\"", JavaUtil.ArraysAsList("a b c"), JavaUtil.ArraysAsList(CssDeclarationValueTokenizer.TokenType
.STRING));
}

[NUnit.Framework.Test]
public virtual void StringTest03() {
RunTest("[ aa bb cc ]", JavaUtil.ArraysAsList("[ aa bb cc ]"), JavaUtil.ArraysAsList(CssDeclarationValueTokenizer.TokenType
.STRING));
}

[NUnit.Framework.Test]
public virtual void StringTest04() {
RunTest("[aa bb cc] [dd ee] 'ff ff'", JavaUtil.ArraysAsList("[aa bb cc]", "[dd ee]", "ff ff"), JavaUtil.ArraysAsList
(CssDeclarationValueTokenizer.TokenType.STRING, CssDeclarationValueTokenizer.TokenType.STRING, CssDeclarationValueTokenizer.TokenType
.STRING));
}

[NUnit.Framework.Test]
public virtual void FunctionWithSquareBracketsTest04() {
RunTest("'prefix' repeat(3, [aa bb cc] 2 [dd ee] 3) 'ff ff'", JavaUtil.ArraysAsList("prefix", "repeat(3, [aa bb cc] 2 [dd ee] 3)"
, "ff ff"), JavaUtil.ArraysAsList(CssDeclarationValueTokenizer.TokenType.STRING, CssDeclarationValueTokenizer.TokenType
.FUNCTION, CssDeclarationValueTokenizer.TokenType.STRING));
}

private void RunTest(String src, IList<String> tokenValues, IList<CssDeclarationValueTokenizer.TokenType>
tokenTypes) {
CssDeclarationValueTokenizer tokenizer = new CssDeclarationValueTokenizer(src);
Expand Down
2 changes: 1 addition & 1 deletion itext/itext.io/itext/io/util/zlib/Deflate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1383,7 +1383,7 @@ internal int deflateInit2(ZStream strm, int level, int method, int windowBits,
pending_buf = new byte[lit_bufsize*4];
pending_buf_size = lit_bufsize*4;

d_buf = lit_bufsize/2;
d_buf = lit_bufsize;
l_buf = (1+2)*lit_bufsize;

this.level = level;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,26 +163,43 @@ private CssDeclarationValueTokenizer.Token GetNextToken() {
);
}
else {
if (curChar == ',' && !inString && functionDepth == 0) {
if (buff.Length == 0) {
return new CssDeclarationValueTokenizer.Token(",", CssDeclarationValueTokenizer.TokenType.COMMA);
}
else {
--index;
return new CssDeclarationValueTokenizer.Token(buff.ToString(), CssDeclarationValueTokenizer.TokenType.UNKNOWN
);
}
if (curChar == '[') {
stringQuote = (char)0;
inString = true;
buff.Append(curChar);
}
else {
if (iText.IO.Util.TextUtil.IsWhiteSpace(curChar)) {
if (functionDepth > 0) {
buff.Append(curChar);
}
return new CssDeclarationValueTokenizer.Token(buff.ToString(), functionDepth > 0 ? CssDeclarationValueTokenizer.TokenType
.FUNCTION : CssDeclarationValueTokenizer.TokenType.UNKNOWN);
if (curChar == ']') {
inString = false;
buff.Append(curChar);
return new CssDeclarationValueTokenizer.Token(buff.ToString(), CssDeclarationValueTokenizer.TokenType.STRING
);
}
else {
buff.Append(curChar);
if (curChar == ',' && !inString && functionDepth == 0) {
if (buff.Length == 0) {
return new CssDeclarationValueTokenizer.Token(",", CssDeclarationValueTokenizer.TokenType.COMMA);
}
else {
--index;
return new CssDeclarationValueTokenizer.Token(buff.ToString(), CssDeclarationValueTokenizer.TokenType.UNKNOWN
);
}
}
else {
if (iText.IO.Util.TextUtil.IsWhiteSpace(curChar)) {
if (functionDepth > 0 || inString) {
buff.Append(curChar);
}
if (!inString) {
return new CssDeclarationValueTokenizer.Token(buff.ToString(), functionDepth > 0 ? CssDeclarationValueTokenizer.TokenType
.FUNCTION : CssDeclarationValueTokenizer.TokenType.UNKNOWN);
}
}
else {
buff.Append(curChar);
}
}
}
}
}
Expand All @@ -206,9 +223,13 @@ private bool IsHexDigit(char c) {
/// <param name="functionBuffer">the function buffer</param>
private void ProcessFunctionToken(CssDeclarationValueTokenizer.Token token, StringBuilder functionBuffer) {
if (token.IsString()) {
functionBuffer.Append(stringQuote);
if (stringQuote != 0) {
functionBuffer.Append(stringQuote);
}
functionBuffer.Append(token.GetValue());
functionBuffer.Append(stringQuote);
if (stringQuote != 0) {
functionBuffer.Append(stringQuote);
}
}
else {
functionBuffer.Append(token.GetValue());
Expand Down
2 changes: 1 addition & 1 deletion port-hash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9efb1ea892c9de623115126013ec4bdb361c4695
fc414da4ec172670063a0b874ecf6af0b7629338

0 comments on commit a671955

Please sign in to comment.