Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Attempt to parse invalid beginning lines of xref table subsections. #91

Merged
merged 1 commit into from
Jun 14, 2019
Merged
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
14 changes: 14 additions & 0 deletions core/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,7 @@ func (parser *PdfParser) parseXrefTable() (*PdfObjectDictionary, error) {
curObjNum := -1
secObjects := 0
insideSubsection := false
unmatchedContent := ""
for {
parser.skipSpaces()
_, err := parser.reader.Peek(1)
Expand All @@ -781,13 +782,24 @@ func (parser *PdfParser) parseXrefTable() (*PdfObjectDictionary, error) {
}

result1 := reXrefSubsection.FindStringSubmatch(txt)
if len(result1) == 0 {
// Try to match invalid subsection beginning lines from previously
// read, unidentified lines. Covers cases in which the object number
// and the number of entries in the subsection are not on the same line.
tryMatch := len(unmatchedContent) > 0
unmatchedContent += txt + "\n"
if tryMatch {
result1 = reXrefSubsection.FindStringSubmatch(unmatchedContent)
}
}
if len(result1) == 3 {
// Match
first, _ := strconv.Atoi(result1[1])
second, _ := strconv.Atoi(result1[2])
curObjNum = first
secObjects = second
insideSubsection = true
unmatchedContent = ""
common.Log.Trace("xref subsection: first object: %d objects: %d", curObjNum, secObjects)
continue
}
Expand All @@ -801,6 +813,7 @@ func (parser *PdfParser) parseXrefTable() (*PdfObjectDictionary, error) {
first, _ := strconv.ParseInt(result2[1], 10, 64)
gen, _ := strconv.Atoi(result2[2])
third := result2[3]
unmatchedContent = ""

if strings.ToLower(third) == "n" && first > 1 {
// Object in use in the file! Load it.
Expand Down Expand Up @@ -829,6 +842,7 @@ func (parser *PdfParser) parseXrefTable() (*PdfObjectDictionary, error) {
curObjNum++
continue
}

if (len(txt) > 6) && (txt[:7] == "trailer") {
common.Log.Trace("Found trailer - %s", txt)
// Sometimes get "trailer << ...."
Expand Down