Skip to content

Commit 7a06ec6

Browse files
committed
fix: handle error if the pdf incorrect format of dict and object
1 parent 5dc444b commit 7a06ec6

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lex.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
// string, a PDF string literal
2121
// keyword, a PDF keyword
2222
// name, a PDF name without the leading slash
23-
//
2423
type token interface{}
2524

2625
// A name is a PDF name, without the leading slash.
@@ -419,6 +418,9 @@ func (b *buffer) readObject() object {
419418
return b.readDict()
420419
case "[":
421420
return b.readArray()
421+
case ">>":
422+
// stop the object
423+
return nil
422424
}
423425
b.errorf("unexpected keyword %q parsing object", kw)
424426
return nil
@@ -480,8 +482,13 @@ func (b *buffer) readDict() object {
480482
if tok == nil || tok == keyword(">>") {
481483
break
482484
}
485+
if tok == io.EOF {
486+
tok = b.readToken()
487+
break
488+
}
483489
n, ok := tok.(name)
484490
if !ok {
491+
fmt.Printf("DEBUG: %T(%v)\n. Skip dict", tok, tok)
485492
b.errorf("unexpected non-name key %T(%v) parsing dictionary", tok, tok)
486493
continue
487494
}

0 commit comments

Comments
 (0)