~ubuntu-branches/ubuntu/hoary/libextractor/hoary

« back to all changes in this revision

Viewing changes to src/plugins/pdf/Parser.cc

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2004-10-30 23:50:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20041030235000-poix4e5mzhmzkpbk
Tags: 0.3.10-2
* Added fix from cvs for various Sparc64 problems (Closes #278905).
* Added workaround from cvs for re-load glib problem of OLE2 extractor.
* debian/watch added.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
//
3
3
// Parser.cc
4
4
//
5
 
// Copyright 1996 Derek B. Noonburg
 
5
// Copyright 1996-2003 Glyph & Cog, LLC
6
6
//
7
7
//========================================================================
8
8
 
9
 
#ifdef __GNUC__
 
9
#include <aconf.h>
 
10
 
 
11
#ifdef USE_GCC_PRAGMAS
10
12
#pragma implementation
11
13
#endif
12
14
 
21
23
#include "Decrypt.h"
22
24
#endif
23
25
 
24
 
Parser::Parser(Lexer *lexerA) {
 
26
Parser::Parser(XRef *xrefA, Lexer *lexerA) {
 
27
  xref = xrefA;
25
28
  lexer = lexerA;
26
29
  inlineImg = 0;
27
30
  lexer->getObj(&buf1);
64
67
  // array
65
68
  if (buf1.isCmd("[")) {
66
69
    shift();
67
 
    obj->initArray();
 
70
    obj->initArray(xref);
68
71
    while (!buf1.isCmd("]") && !buf1.isEOF())
69
72
#ifndef NO_DECRYPTION
70
73
      obj->arrayAdd(getObj(&obj2, fileKey, keyLength, objNum, objGen));
78
81
  // dictionary or stream
79
82
  } else if (buf1.isCmd("<<")) {
80
83
    shift();
81
 
    obj->initDict();
 
84
    obj->initDict(xref);
82
85
    while (!buf1.isCmd(">>") && !buf1.isEOF()) {
83
86
      if (!buf1.isName()) {
84
87
        error(getPos(), "Dictionary key must be a name object");
86
89
      } else {
87
90
        key = copyString(buf1.getName());
88
91
        shift();
89
 
        if (buf1.isEOF() || buf1.isError())
 
92
        if (buf1.isEOF() || buf1.isError()) {
 
93
          gfree(key);
90
94
          break;
 
95
        }
91
96
#ifndef NO_DECRYPTION
92
97
        obj->dictAdd(key, getObj(&obj2, fileKey, keyLength, objNum, objGen));
93
98
#else
153
158
Stream *Parser::makeStream(Object *dict) {
154
159
  Object obj;
155
160
  Stream *str;
156
 
  int pos, endPos, length;
 
161
  Guint pos, endPos, length;
157
162
 
158
163
  // get stream start position
159
164
  lexer->skipToNextLine();
162
167
  // get length
163
168
  dict->dictLookup("Length", &obj);
164
169
  if (obj.isInt()) {
165
 
    length = obj.getInt();
 
170
    length = (Guint)obj.getInt();
166
171
    obj.free();
167
172
  } else {
168
173
    error(getPos(), "Bad 'Length' attribute in stream");
171
176
  }
172
177
 
173
178
  // check for length in damaged file
174
 
  if ((endPos = xref->getStreamEnd(pos)) >= 0) {
 
179
  if (xref && xref->getStreamEnd(pos, &endPos)) {
175
180
    length = endPos - pos;
176
181
  }
177
182
 
 
183
  // in badly damaged PDF files, we can run off the end of the input
 
184
  // stream immediately after the "stream" token
 
185
  if (!lexer->getStream()) {
 
186
    return NULL;
 
187
  }
 
188
 
178
189
  // make base stream
179
 
  str = lexer->getStream()->getBaseStream()->makeSubStream(pos, length, dict);
 
190
  str = lexer->getStream()->getBaseStream()->makeSubStream(pos, gTrue,
 
191
                                                           length, dict);
180
192
 
181
193
  // get filters
182
194
  str = str->addFilters(dict);
187
199
  // refill token buffers and check for 'endstream'
188
200
  shift();  // kill '>>'
189
201
  shift();  // kill 'stream'
190
 
  if (buf1.isCmd("endstream"))
 
202
  if (buf1.isCmd("endstream")) {
191
203
    shift();
192
 
  else
 
204
  } else {
193
205
    error(getPos(), "Missing 'endstream'");
 
206
    str->ignoreLength();
 
207
  }
194
208
 
195
209
  return str;
196
210
}
197
211
 
198
212
void Parser::shift() {
199
213
  if (inlineImg > 0) {
200
 
    ++inlineImg;
 
214
    if (inlineImg < 2) {
 
215
      ++inlineImg;
 
216
    } else {
 
217
      // in a damaged content stream, if 'ID' shows up in the middle
 
218
      // of a dictionary, we need to reset
 
219
      inlineImg = 0;
 
220
    }
201
221
  } else if (buf2.isCmd("ID")) {
202
222
    lexer->skipChar();          // skip char after 'ID' command
203
223
    inlineImg = 1;