@@ -1160,21 +1160,29 @@ func processTrailer(c context.Context, ctx *model.Context, s *bufio.Scanner, lin
11601160}
11611161
11621162// Parse xRef section into corresponding number of xRef table entries.
1163- func parseXRefSection (c context.Context , ctx * model.Context , s * bufio.Scanner , ssCount * int , offCurXRef * int64 , offExtra int64 , repairOff int ) (* int64 , error ) {
1163+ func parseXRefSection (c context.Context , ctx * model.Context , s * bufio.Scanner , fields [] string , ssCount * int , offCurXRef * int64 , offExtra int64 , repairOff int ) (* int64 , error ) {
11641164 if log .ReadEnabled () {
11651165 log .Read .Println ("parseXRefSection begin" )
11661166 }
11671167
1168- line , err := scanLine ( s )
1169- if err != nil {
1170- return nil , err
1171- }
1168+ var (
1169+ line string
1170+ err error
1171+ )
11721172
1173- if log .ReadEnabled () {
1174- log .Read .Printf ("parseXRefSection: <%s>\n " , line )
1175- }
1173+ if len (fields ) == 0 {
11761174
1177- fields := strings .Fields (line )
1175+ line , err = scanLine (s )
1176+ if err != nil {
1177+ return nil , err
1178+ }
1179+
1180+ if log .ReadEnabled () {
1181+ log .Read .Printf ("parseXRefSection: <%s>\n " , line )
1182+ }
1183+
1184+ fields = strings .Fields (line )
1185+ }
11781186
11791187 // Process all sub sections of this xRef section.
11801188 for ! strings .HasPrefix (line , "trailer" ) && len (fields ) == 2 {
@@ -1507,10 +1515,18 @@ func tryXRefSection(c context.Context, ctx *model.Context, rs io.ReadSeeker, off
15071515 if log .ReadEnabled () {
15081516 log .Read .Println ("tryXRefSection: found xref section" )
15091517 }
1510- return parseXRefSection (c , ctx , s , xrefSectionCount , offset , offExtra , 0 )
1518+ return parseXRefSection (c , ctx , s , nil , xrefSectionCount , offset , offExtra , 0 )
1519+ }
1520+
1521+ // Repair fix for #823
1522+ if strings .HasPrefix (line , "xref" ) {
1523+ fields := strings .Fields (line )
1524+ if len (fields ) == 3 {
1525+ return parseXRefSection (c , ctx , s , fields [1 :], xrefSectionCount , offset , offExtra , 0 )
1526+ }
15111527 }
15121528
1513- // Retry using next line. ( Repair fix for #326)
1529+ // Repair fix for #326
15141530 if line , err = scanLine (s ); err != nil {
15151531 return nil , err
15161532 }
@@ -1527,7 +1543,7 @@ func tryXRefSection(c context.Context, ctx *model.Context, rs io.ReadSeeker, off
15271543 if log .ReadEnabled () {
15281544 log .Read .Printf ("Repair offset: %d\n " , repairOff )
15291545 }
1530- return parseXRefSection (c , ctx , s , xrefSectionCount , offset , offExtra , repairOff )
1546+ return parseXRefSection (c , ctx , s , nil , xrefSectionCount , offset , offExtra , repairOff )
15311547 }
15321548
15331549 return & zero , nil
@@ -2103,7 +2119,7 @@ func ParseObjectWithContext(c context.Context, ctx *model.Context, offset int64,
21032119func dereferencedObject (c context.Context , ctx * model.Context , objNr int ) (types.Object , error ) {
21042120 entry , ok := ctx .Find (objNr )
21052121 if ! ok {
2106- return nil , errors .New ("pdfcpu: dereferencedObject: unregistered object" )
2122+ return nil , errors .Errorf ("pdfcpu: dereferencedObject: unregistered object: %d" , objNr )
21072123 }
21082124
21092125 if entry .Compressed {
0 commit comments