Skip to content

Commit

Permalink
Fix 137
Browse files Browse the repository at this point in the history
  • Loading branch information
hhrutter committed Dec 1, 2019
1 parent 7519e68 commit c20cd91
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 35 deletions.
1 change: 1 addition & 0 deletions pkg/pdfcpu/parse_common_test.go
Expand Up @@ -109,4 +109,5 @@ func TestParseObject(t *testing.T) {
doTestParseObjectOK("1 0 R%comment\x0a", t)
doTestParseObjectOK("[1 0 R /n 2 0 R]", t)
doTestParseObjectOK("<</n 1 0 R>>", t)
doTestParseObjectOK("(!\\(S:\\356[\\272H\\355>>R{sb\\007)", t)
}
56 changes: 21 additions & 35 deletions pkg/pdfcpu/read.go
Expand Up @@ -784,6 +784,15 @@ func scanLine(s *bufio.Scanner) (s1 string, err error) {
return s1, nil
}

func isDict(s string) bool {
o, err := parseObject(&s)
if err != nil {
return false
}
_, ok := o.(Dict)
return ok
}

func scanTrailer(s *bufio.Scanner, line string) (string, error) {

var buf bytes.Buffer
Expand Down Expand Up @@ -832,9 +841,13 @@ func scanTrailer(s *bufio.Scanner, line string) (string, error) {
if j >= 0 {
// Yes >>
if k == 0 {
return buf.String(), nil
// Check for dict
if isDict(buf.String()) {
return buf.String(), nil
}
} else {
k--
}
k--
line = line[j+2:]
continue
}
Expand Down Expand Up @@ -862,47 +875,20 @@ func scanTrailer(s *bufio.Scanner, line string) (string, error) {
} else {
// handle >>
if k == 0 {
return buf.String(), nil
// Check for dict
if isDict(buf.String()) {
return buf.String(), nil
}
} else {
k--
}
k--
line = line[j+2:]
}
}
}
}
}

func scanTrailerDict(s *bufio.Scanner, startTag bool) (string, error) {

var buf bytes.Buffer
var line string
var err error

if !startTag {
// scan for dict start tag <<
for strings.Index(line, "<<") < 0 {
line, err = scanLine(s)
if err != nil {
return "", err
}
buf.WriteString(line)
buf.WriteString(" ")
}
}

// scan for dict end tag >>
for strings.Index(line, ">>") < 0 {
line, err = scanLine(s)
if err != nil {
return "", err
}
buf.WriteString(line)
buf.WriteString(" ")
}

return buf.String(), nil
}

func processTrailer(ctx *Context, s *bufio.Scanner, line string) (*int64, error) {

var trailerString string
Expand Down

0 comments on commit c20cd91

Please sign in to comment.