Skip to content

Commit 7bebec3

Browse files
vitali-priText-CI
authored andcommitted
Add a test for fixed deflate algorithm
DEVSIX-8385 Autoported commit. Original commit hash: [0690f106b]
1 parent 15daf08 commit 7bebec3

File tree

3 files changed

+76
-1
lines changed

3 files changed

+76
-1
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2024 Apryse Group NV
4+
Authors: Apryse Software.
5+
6+
This program is offered under a commercial and under the AGPL license.
7+
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
8+
9+
AGPL licensing:
10+
This program is free software: you can redistribute it and/or modify
11+
it under the terms of the GNU Affero General Public License as published by
12+
the Free Software Foundation, either version 3 of the License, or
13+
(at your option) any later version.
14+
15+
This program is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
GNU Affero General Public License for more details.
19+
20+
You should have received a copy of the GNU Affero General Public License
21+
along with this program. If not, see <https://www.gnu.org/licenses/>.
22+
*/
23+
using System;
24+
using System.IO;
25+
using iText.Commons.Utils;
26+
using iText.IO.Source;
27+
using iText.Test;
28+
29+
namespace iText.IO.Util {
30+
[NUnit.Framework.Category("IntegrationTest")]
31+
public class ZlibUtilTest : ExtendedITextTest {
32+
private static readonly String SOURCE_FOLDER = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
33+
.CurrentContext.TestDirectory) + "/resources/itext/io/util/";
34+
35+
private static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory
36+
+ "/test/itext/io/util/";
37+
38+
[NUnit.Framework.SetUp]
39+
public virtual void SetUp() {
40+
CreateOrClearDestinationFolder(DESTINATION_FOLDER);
41+
}
42+
43+
[NUnit.Framework.Test]
44+
public virtual void ArrayIndexOutOfBoundsDeflateTest() {
45+
// Test file is taken from https://issues.jenkins.io/browse/JENKINS-19473
46+
// Unzip test file first
47+
using (ZipFileReader reader = new ZipFileReader(SOURCE_FOLDER + "jzlib.zip")) {
48+
using (Stream @is = reader.ReadFromZip("jzlib.fail")) {
49+
using (Stream os = FileUtil.GetFileOutputStream(DESTINATION_FOLDER + "jzlib.fail")) {
50+
byte[] buf = new byte[8192];
51+
int length;
52+
while ((length = @is.Read(buf)) != -1) {
53+
os.Write(buf, 0, length);
54+
}
55+
}
56+
}
57+
}
58+
// Deflate it
59+
using (Stream is_1 = FileUtil.GetInputStreamForFile(DESTINATION_FOLDER + "jzlib.fail")) {
60+
using (Stream os_1 = FileUtil.GetFileOutputStream(DESTINATION_FOLDER + "jzlib.fail.zz")) {
61+
// -1 stands for default compression
62+
using (DeflaterOutputStream zip = new DeflaterOutputStream(os_1, -1)) {
63+
byte[] buf = new byte[8192];
64+
int length;
65+
while ((length = is_1.Read(buf)) != -1) {
66+
zip.Write(buf, 0, length);
67+
}
68+
}
69+
}
70+
}
71+
NUnit.Framework.Assert.IsTrue(FileUtil.FileExists(DESTINATION_FOLDER + "jzlib.fail.zz"));
72+
NUnit.Framework.Assert.IsTrue(FileUtil.IsFileNotEmpty(DESTINATION_FOLDER + "jzlib.fail.zz"));
73+
}
74+
}
75+
}
201 KB
Binary file not shown.

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
fdbc9708981652ad8791896bbe9ce095e3d83ef8
1+
0690f106b3f89d2681fc1aba527f4264e99ba407

0 commit comments

Comments
 (0)