diff --git a/kernel/src/main/java/com/itextpdf/kernel/font/PdfFont.java b/kernel/src/main/java/com/itextpdf/kernel/font/PdfFont.java index 54a569f7c7..8c3e9d3172 100644 --- a/kernel/src/main/java/com/itextpdf/kernel/font/PdfFont.java +++ b/kernel/src/main/java/com/itextpdf/kernel/font/PdfFont.java @@ -538,7 +538,7 @@ protected static String updateSubsetPrefix(String fontName, boolean isSubset, bo * @throws PdfException Method will throw exception if {@code fontStreamBytes} is {@code null}. */ protected PdfStream getPdfFontStream(byte[] fontStreamBytes, int[] fontStreamLengths) { - if (fontStreamBytes == null) { + if (fontStreamBytes == null || fontStreamLengths == null) { throw new PdfException(KernelExceptionMessageConstant.FONT_EMBEDDING_ISSUE); } PdfStream fontStream = new PdfStream(fontStreamBytes); diff --git a/kernel/src/test/java/com/itextpdf/kernel/font/PdfFontUnitTest.java b/kernel/src/test/java/com/itextpdf/kernel/font/PdfFontUnitTest.java index 6ef2baa06f..afbc849c06 100644 --- a/kernel/src/test/java/com/itextpdf/kernel/font/PdfFontUnitTest.java +++ b/kernel/src/test/java/com/itextpdf/kernel/font/PdfFontUnitTest.java @@ -647,4 +647,22 @@ public void cannotGetFontStreamForNullBytesTest() throws IOException { PdfFont pdfFont = PdfFontFactory.createFont(); pdfFont.getPdfFontStream(null, new int[] {1}); } + + @Test + public void cannotGetFontStreamForNullLengthsTest() throws IOException { + junitExpectedException.expect(PdfException.class); + junitExpectedException.expectMessage(KernelExceptionMessageConstant.FONT_EMBEDDING_ISSUE); + + PdfFont pdfFont = PdfFontFactory.createFont(); + pdfFont.getPdfFontStream(new byte[] {1}, null); + } + + @Test + public void cannotGetFontStreamForNullBytesAndLengthsTest() throws IOException { + junitExpectedException.expect(PdfException.class); + junitExpectedException.expectMessage(KernelExceptionMessageConstant.FONT_EMBEDDING_ISSUE); + + PdfFont pdfFont = PdfFontFactory.createFont(); + pdfFont.getPdfFontStream(null, null); + } }