Skip to content

Commit

Permalink
Fix append pages when stream is not readable
Browse files Browse the repository at this point in the history
Fixes #191
  • Loading branch information
julianhille committed Jun 30, 2022
1 parent b043739 commit 4df356b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions src/deps/PDFWriter/PDFDocumentHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
14 changes: 12 additions & 2 deletions tests/AppendPagesTest.js
Original file line number Diff line number Diff line change
@@ -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')
})
});
Binary file added tests/TestMaterials/appendbreaks.pdf
Binary file not shown.

0 comments on commit 4df356b

Please sign in to comment.