()
| 74 | } |
| 75 | |
| 76 | func (r *pdfReader) readCrossReferenceTable() (pdfDict, error) { |
| 77 | var starttrailer int |
| 78 | var line []byte |
| 79 | |
| 80 | var i0 uint32 |
| 81 | lr := newLineReader(r.data, r.startxref) |
| 82 | _ = lr.Next() // xref |
| 83 | for { |
| 84 | starttrailer = lr.Pos() |
| 85 | line = lr.Next() |
| 86 | if line == nil { |
| 87 | return pdfDict{}, fmt.Errorf("invalid cross reference table") |
| 88 | } else if bytes.HasPrefix(line, []byte("trailer")) { |
| 89 | break |
| 90 | } |
| 91 | |
| 92 | first, n := strconv.ParseUint(line) |
| 93 | if n == 0 { |
| 94 | return pdfDict{}, fmt.Errorf("invalid cross reference table") |
| 95 | } |
| 96 | i := moveWhiteSpace(line, n) |
| 97 | entries, n := strconv.ParseUint(line[i:]) |
| 98 | if n == 0 { |
| 99 | return pdfDict{}, fmt.Errorf("invalid cross reference table") |
| 100 | } |
| 101 | |
| 102 | for i := uint32(0); i < uint32(entries); i++ { |
| 103 | line = lr.Next() |
| 104 | if len(line) != 18 && len(line) != 19 { |
| 105 | return pdfDict{}, fmt.Errorf("invalid cross reference table") |
| 106 | } |
| 107 | offset, n := strconv.ParseUint(line) |
| 108 | if n != 10 { |
| 109 | return pdfDict{}, fmt.Errorf("invalid cross reference table") |
| 110 | } |
| 111 | generation, n := strconv.ParseUint(line[11:]) |
| 112 | if n != 5 || line[17] != 'f' && line[17] != 'n' { |
| 113 | return pdfDict{}, fmt.Errorf("invalid cross reference table") |
| 114 | } |
| 115 | free := line[17] == 'f' |
| 116 | if i0+i == 0 && (!free || generation != 65535) { |
| 117 | return pdfDict{}, fmt.Errorf("invalid cross reference table") |
| 118 | } |
| 119 | ref := pdfRef{uint32(first) + i, uint32(generation)} |
| 120 | if _, ok := r.objects[ref]; !ok { |
| 121 | // add object of previous generations only if not over-written by a new version |
| 122 | if free { |
| 123 | r.objects[ref] = pdfObject{free: true, object: uint32(offset)} |
| 124 | } else { |
| 125 | r.objects[ref] = pdfObject{offset: int(offset)} |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | i0 += uint32(entries) |
| 130 | } |
| 131 | |
| 132 | // trailer |
| 133 | starttrailer = moveWhiteSpace(r.data, starttrailer+7) |
no test coverage detected