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 Nov 21, 2024
2 parents 5b458ed + 4575926 commit 4ebeb7f
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 22 deletions.
22 changes: 11 additions & 11 deletions itext.tests/itext.kernel.tests/itext/kernel/pdf/PdfReaderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class PdfReaderTest : ExtendedITextTest {

[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
CreateDestinationFolder(DESTINATION_FOLDER);
CreateOrClearDestinationFolder(DESTINATION_FOLDER);
}

[NUnit.Framework.OneTimeTearDown]
Expand Down Expand Up @@ -2623,17 +2623,17 @@ public virtual void ReadAandUaDocumentTest() {
}
}

//TODO DEVSIX-8695: Update after bug is fixed.
[LogMessage(iText.IO.Logs.IoLogMessageConstant.XREF_ERROR_WHILE_READING_TABLE_WILL_BE_REBUILT_WITH_CAUSE)]
[NUnit.Framework.Test]
public virtual void TrailerMissingBytesTest() {
FileInfo file = new FileInfo(SOURCE_FOLDER + "encryptedDocWithFlateDecodeError.pdf");
PdfReader pdfReader = new PdfReader(file);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
PdfWriter pdfWriter = new PdfWriter(byteArrayOutputStream);
Exception e = NUnit.Framework.Assert.Catch(typeof(PdfException), () => new PdfDocument(pdfReader, pdfWriter
));
NUnit.Framework.Assert.AreEqual(KernelExceptionMessageConstant.TRAILER_NOT_FOUND, e.Message);
public virtual void XrefStreamMissingBytesTest() {
String inputFile = SOURCE_FOLDER + "xrefStreamMissingBytes.pdf";
String outputFile = DESTINATION_FOLDER + "xrefStreamMissingBytes.pdf";
String cmpFile = SOURCE_FOLDER + "cmp_xrefStreamMissingBytes.pdf";
PdfReader pdfReader = new PdfReader(inputFile).SetUnethicalReading(true);
using (PdfDocument pdfDoc = new PdfDocument(pdfReader, CompareTool.CreateTestPdfWriter(outputFile))) {
pdfDoc.RemovePage(2);
}
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outputFile, cmpFile, DESTINATION_FOLDER,
"diff_"));
}

private static PdfDictionary GetTestPdfDictionary() {
Expand Down
Binary file not shown.
24 changes: 15 additions & 9 deletions itext/itext.commons/itext/commons/utils/JavaUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,55 +224,61 @@ public static double Random() {
}

public static void Fill(byte[] a, byte val) {
for (int i = 0, len = a.Length; i < len; i++) {
for (int i = 0; i < a.Length; i++) {
a[i] = val;
}
}

public static void Fill(byte[] a, int from, int to, byte val) {
for (int i = from; i < to; i++) {
a[i] = val;
}
}

public static void Fill(char[] a, char val) {
for (int i = 0, len = a.Length; i < len; i++) {
for (int i = 0; i < a.Length; i++) {
a[i] = val;
}
}

public static void Fill(bool[] a, bool val) {
for (int i = 0, len = a.Length; i < len; i++) {
for (int i = 0; i < a.Length; i++) {
a[i] = val;
}
}

public static void Fill(short[] a, short val) {
for (int i = 0, len = a.Length; i < len; i++) {
for (int i = 0; i < a.Length; i++) {
a[i] = val;
}
}

public static void Fill(int[] a, int val) {
for (int i = 0, len = a.Length; i < len; i++) {
for (int i = 0; i < a.Length; i++) {
a[i] = val;
}
}

public static void Fill(long[] a, long val) {
for (int i = 0, len = a.Length; i < len; i++) {
for (int i = 0; i < a.Length; i++) {
a[i] = val;
}
}

public static void Fill(float[] a, float val) {
for (int i = 0, len = a.Length; i < len; i++) {
for (int i = 0; i < a.Length; i++) {
a[i] = val;
}
}

public static void Fill(double[] a, double val) {
for (int i = 0, len = a.Length; i < len; i++) {
for (int i = 0; i < a.Length; i++) {
a[i] = val;
}
}

public static void Fill(object[] a, object val) {
for (int i = 0, len = a.Length; i < len; i++) {
for (int i = 0; i < a.Length; i++) {
a[i] = val;
}
}
Expand Down
5 changes: 5 additions & 0 deletions itext/itext.kernel/KernelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public static int JRead(this Stream stream, byte[] buffer, int offset, int count
return result == 0 ? -1 : result;
}

public static int JRead(this BinaryReader stream, byte[] buffer, int offset, int count) {
int result = stream.Read(buffer, offset, count);
return result == 0 ? -1 : result;
}

public static void Write(this Stream stream, byte[] buffer) {
stream.Write(buffer, 0, buffer.Length);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ You should have received a copy of the GNU Affero General Public License
using System;
using System.IO;
using System.util.zlib;
using iText.Commons.Utils;
using iText.Kernel.Exceptions;
using iText.Kernel.Pdf;

Expand Down Expand Up @@ -89,7 +90,10 @@ public static byte[] DecodePredictor(byte[] @in, PdfObject decodeParams) {
if (filter < 0) {
return fout.ToArray();
}
dataStream.ReadFully(curr, 0, bytesPerRow);
int bytesRead = dataStream.JRead(curr, 0, bytesPerRow);
if (bytesRead < bytesPerRow) {
JavaUtil.Fill(curr, bytesRead, bytesPerRow, (byte)0);
}
}
catch (Exception) {
return fout.ToArray();
Expand Down
2 changes: 1 addition & 1 deletion port-hash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1ad4f3a48de8884b72541d6afbfc5af196327728
606588ac45e658d125e76fd247d8e0f26bbe0567

0 comments on commit 4ebeb7f

Please sign in to comment.