Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Handle missing comments on binary "line" when parsing #364

Merged
merged 2 commits into from
Feb 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/parser/PDFParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ class PDFParser extends PDFObjectParser {
this.parseIndirectObjectHeader();
this.bytes.moveTo(initialOffset);
} catch (e) {
this.skipLine();
this.bytes.next();
this.skipWhitespaceAndComments();
}
}
Expand Down
21 changes: 18 additions & 3 deletions tests/core/parser/PDFParser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,24 @@ describe(`PDFParser`, () => {
new Uint8Array([128, 1, 2, 3, 4, 5, 129, 130, 131, CharCodes.Newline]),
'1 0 obj\n',
' . (foobar)\n',
'foo',
'endobj',
);
const parser = PDFParser.forBytesWithOptions(typedArrayFor(input));
await expect(parser.parseDocument()).rejects.toThrow();
const context = await parser.parseDocument();
expect(context.enumerateIndirectObjects().length).toBe(1);
});

it(`handles invalid binary comments with missing newline after header`, async () => {
const input = mergeIntoTypedArray(
'%PDF-1.7\n',
new Uint8Array([142, 1, 2, 3, 4, 5, 129, 130, 131]),
'1 0 obj\n',
' . (foobar)\n',
'endobj',
);
const parser = PDFParser.forBytesWithOptions(typedArrayFor(input));
const context = await parser.parseDocument();
expect(context.enumerateIndirectObjects().length).toBe(1);
});

it(`does not stall when stuff follows the last %%EOL`, async () => {
Expand All @@ -83,7 +97,8 @@ describe(`PDFParser`, () => {
@@@@@@@@@@@@@@@@@@
`;
const parser = PDFParser.forBytesWithOptions(typedArrayFor(input));
await expect(parser.parseDocument()).resolves.not.toThrow();
const context = await parser.parseDocument();
expect(context.enumerateIndirectObjects().length).toBe(1);
});

it(`handles invalid indirect objects`, async () => {
Expand Down