diff --git a/src/main/java/org/verapdf/parser/PDFParser.java b/src/main/java/org/verapdf/parser/PDFParser.java index 0c4758ad..302b7f51 100644 --- a/src/main/java/org/verapdf/parser/PDFParser.java +++ b/src/main/java/org/verapdf/parser/PDFParser.java @@ -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) {