diff --git a/CHANGELOG.md b/CHANGELOG.md index aee9c645..1a28fdc3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixes hard crash to exception when creating a stream with null object and calling createWriter with it - Fixes missing buffer information for recrypt typescript definition - Fixes missing options for append pdf pages +- Fixes NPE when stream is not readable in write stream object (PDFDocumentHandler) ## [2.5.0] - 2022-06-23 diff --git a/src/deps/PDFWriter/PDFDocumentHandler.cpp b/src/deps/PDFWriter/PDFDocumentHandler.cpp index de2480a7..e2867645 100755 --- a/src/deps/PDFWriter/PDFDocumentHandler.cpp +++ b/src/deps/PDFWriter/PDFDocumentHandler.cpp @@ -2032,6 +2032,10 @@ EStatusCode PDFDocumentHandler::WriteStreamObject(PDFStreamInput* inStream, IObj if(!readingDecrypted) { streamReader = mParser->StartReadingFromStreamForPlainCopying(inStream); } + + if (streamReader == NULL) { + status = PDFHummus::eFailure; + } while (it.MoveNext() && PDFHummus::eSuccess == status) { diff --git a/tests/AppendPagesTest.js b/tests/AppendPagesTest.js index 1ca89608..f22aa2fe 100644 --- a/tests/AppendPagesTest.js +++ b/tests/AppendPagesTest.js @@ -1,11 +1,21 @@ +const muhammara = require('../muhammara'); +const expect = require('chai').expect; + describe('AppendPagesTest', function() { it('should complete without error', function() { - var pdfWriter = require('../muhammara').createWriter(__dirname + '/output/AppendPagesTest.pdf'); - + var pdfWriter = muhammara.createWriter(__dirname + '/output/AppendPagesTest.pdf'); pdfWriter.appendPDFPagesFromPDF(__dirname + '/TestMaterials/Original.pdf'); pdfWriter.appendPDFPagesFromPDF(__dirname + '/TestMaterials/XObjectContent.PDF'); pdfWriter.appendPDFPagesFromPDF(__dirname + '/TestMaterials/BasicTIFFImagesTest.PDF'); pdfWriter.end(); }); + + it('should throw an error instead of a crash', () => { + var writerBuffer = new muhammara.PDFWStreamForBuffer([]); + var pdfWriter = muhammara.createWriter(writerBuffer) + expect(() => + pdfWriter.appendPDFPagesFromPDF(__dirname + '/TestMaterials/appendbreaks.pdf') + ).to.throw('unable to append') + }) }); diff --git a/tests/TestMaterials/appendbreaks.pdf b/tests/TestMaterials/appendbreaks.pdf new file mode 100644 index 00000000..78c542f3 Binary files /dev/null and b/tests/TestMaterials/appendbreaks.pdf differ