Skip to content

Commit

Permalink
Merge pull request #399 from RomaPrograms/xref-check
Browse files Browse the repository at this point in the history
Fixed issue: #968
  • Loading branch information
BezrukovM authored Feb 11, 2020
2 parents 07192be + b08f562 commit b600c60
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/main/java/org/verapdf/parser/PDFParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -466,12 +466,40 @@ private void parseXrefTable(final COSXRefSection xrefs) throws IOException {
}
xref.free = value.charAt(0);
xrefs.addEntry(number + i, xref);

checkXrefTableEntryLastBytes();
}
nextToken();
}
this.source.seekFromCurrentPosition(-7);
}

/**
* Checks that last bytes in the entry of Xref table should be:
* EOL(CRLF), or Space and LF, or Space and CR
*
* @throws IOException - incorrect reading from file
*/
private void checkXrefTableEntryLastBytes() throws IOException {
boolean isLastBytesCorrect;

byte ch = this.source.readByte();
if (isCR(ch)) {
ch = this.source.readByte();
isLastBytesCorrect = isLF(ch);
} else if (ch == CharTable.ASCII_SPACE) {
ch = this.source.readByte();
isLastBytesCorrect = (isLF(ch) || isCR(ch));
} else {
isLastBytesCorrect = false;
}

if (!isLastBytesCorrect){
this.source.unread();
LOGGER.log(Level.WARNING, "Incorrect end of line in cross-reference table.");
}
}

private void parseXrefStream(final COSXRefInfo section) throws IOException {
nextToken();
if (this.getToken().type != Token.Type.TT_INTEGER) {
Expand Down

0 comments on commit b600c60

Please sign in to comment.