Skip to content

Commit

Permalink
Fix npe as backport for 2.x
Browse files Browse the repository at this point in the history
Fixes #214
  • Loading branch information
julianhille committed Oct 23, 2022
1 parent 9713a09 commit 90b278d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Fixed

- NPE in parser when file ends before it really starts

## [2.6.0] - 2022-06-30

### Changed
Expand Down
6 changes: 6 additions & 0 deletions src/deps/PDFWriter/PDFParser.cpp
Expand Up @@ -352,6 +352,12 @@ EStatusCode PDFParser::ParseLastXrefPosition()
mObjectParser.ResetReadState();
RefCountPtr<PDFObject> anObject(mObjectParser.ParseNewObject());

if (!anObject) {
status = PDFHummus::eFailure;
TRACE_LOG("PDFParser::ParseXrefPosition: Unable to find any object");
break;
}

if(anObject->GetType() == PDFObject::ePDFObjectInteger)
{
mLastXrefPosition = (LongFilePositionType)((PDFInteger*)anObject.GetPtr())->GetValue();
Expand Down
12 changes: 12 additions & 0 deletions tests/SigSeg.js
@@ -0,0 +1,12 @@
var muhammara = require("../muhammara");
const { expect } = require("chai");

describe("SigSegv test", function () {
it("should read fields correctly", function () {
expect(() =>
muhammara.createReader(
__dirname + "/TestMaterials/BrokenPdfBadHeader.txt"
)
).to.throw();
});
});
2 changes: 2 additions & 0 deletions tests/TestMaterials/BrokenPdfBadHeader.txt
@@ -0,0 +1,2 @@
%PDF-1.4
%%EOF

0 comments on commit 90b278d

Please sign in to comment.