Skip to content

Commit

Permalink
Merge pull request #194 from julianhille/feature/191-append-issue
Browse files Browse the repository at this point in the history
Fix append pages when stream is not readable
  • Loading branch information
julianhille authored Jun 30, 2022
2 parents b043739 + 4df356b commit e89da10
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 e89da10

Please sign in to comment.