~ubuntu-branches/ubuntu/lucid/xpdf/lucid-updates

« back to all changes in this revision

Viewing changes to xpdf/Parser.cc

  • Committer: Bazaar Package Importer
  • Author(s): Andy Price
  • Date: 2007-05-17 22:04:33 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070517220433-gzcx2lrvllkbl7mr
Tags: 3.02-1ubuntu1
* Merge from Debian unstable (LP: #113365), remaining changes:
  - Added back 09_xpdfrc_manpage.dpatch (LP #71753)
  - Set Ubuntu maintainer

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
#include "Object.h"
17
17
#include "Array.h"
18
18
#include "Dict.h"
 
19
#include "Decrypt.h"
19
20
#include "Parser.h"
20
21
#include "XRef.h"
21
22
#include "Error.h"
22
 
#include "Decrypt.h"
23
23
 
24
 
Parser::Parser(XRef *xrefA, Lexer *lexerA) {
 
24
Parser::Parser(XRef *xrefA, Lexer *lexerA, GBool allowStreamsA) {
25
25
  xref = xrefA;
26
26
  lexer = lexerA;
27
27
  inlineImg = 0;
 
28
  allowStreams = allowStreamsA;
28
29
  lexer->getObj(&buf1);
29
30
  lexer->getObj(&buf2);
30
31
}
35
36
  delete lexer;
36
37
}
37
38
 
38
 
Object *Parser::getObj(Object *obj,
39
 
                       Guchar *fileKey, int keyLength,
 
39
Object *Parser::getObj(Object *obj, Guchar *fileKey,
 
40
                       CryptAlgorithm encAlgorithm, int keyLength,
40
41
                       int objNum, int objGen) {
41
42
  char *key;
42
43
  Stream *str;
43
44
  Object obj2;
44
45
  int num;
45
 
  Decrypt *decrypt;
46
 
  GString *s;
47
 
  char *p;
48
 
  int i;
 
46
  DecryptStream *decrypt;
 
47
  GString *s, *s2;
 
48
  int c;
49
49
 
50
50
  // refill buffer after inline image data
51
51
  if (inlineImg == 2) {
61
61
    shift();
62
62
    obj->initArray(xref);
63
63
    while (!buf1.isCmd("]") && !buf1.isEOF())
64
 
      obj->arrayAdd(getObj(&obj2, fileKey, keyLength, objNum, objGen));
 
64
      obj->arrayAdd(getObj(&obj2, fileKey, encAlgorithm, keyLength,
 
65
                           objNum, objGen));
65
66
    if (buf1.isEOF())
66
67
      error(getPos(), "End of file inside array");
67
68
    shift();
81
82
          gfree(key);
82
83
          break;
83
84
        }
84
 
        obj->dictAdd(key, getObj(&obj2, fileKey, keyLength, objNum, objGen));
 
85
        obj->dictAdd(key, getObj(&obj2, fileKey, encAlgorithm, keyLength,
 
86
                                 objNum, objGen));
85
87
      }
86
88
    }
87
89
    if (buf1.isEOF())
88
90
      error(getPos(), "End of file inside dictionary");
89
 
    if (buf2.isCmd("stream")) {
90
 
      if ((str = makeStream(obj))) {
 
91
    // stream objects are not allowed inside content streams or
 
92
    // object streams
 
93
    if (allowStreams && buf2.isCmd("stream")) {
 
94
      if ((str = makeStream(obj, fileKey, encAlgorithm, keyLength,
 
95
                            objNum, objGen))) {
91
96
        obj->initStream(str);
92
 
        if (fileKey) {
93
 
          str->getBaseStream()->doDecryption(fileKey, keyLength,
94
 
                                             objNum, objGen);
95
 
        }
96
97
      } else {
97
98
        obj->free();
98
99
        obj->initError();
115
116
 
116
117
  // string
117
118
  } else if (buf1.isString() && fileKey) {
118
 
    buf1.copy(obj);
119
 
    s = obj->getString();
120
 
    decrypt = new Decrypt(fileKey, keyLength, objNum, objGen);
121
 
    for (i = 0, p = obj->getString()->getCString();
122
 
         i < s->getLength();
123
 
         ++i, ++p) {
124
 
      *p = decrypt->decryptByte(*p);
 
119
    s = buf1.getString();
 
120
    s2 = new GString();
 
121
    obj2.initNull();
 
122
    decrypt = new DecryptStream(new MemStream(s->getCString(), 0,
 
123
                                              s->getLength(), &obj2),
 
124
                                fileKey, encAlgorithm, keyLength,
 
125
                                objNum, objGen);
 
126
    decrypt->reset();
 
127
    while ((c = decrypt->getChar()) != EOF) {
 
128
      s2->append((char)c);
125
129
    }
126
130
    delete decrypt;
 
131
    obj->initString(s2);
127
132
    shift();
128
133
 
129
134
  // simple object
135
140
  return obj;
136
141
}
137
142
 
138
 
Stream *Parser::makeStream(Object *dict) {
 
143
Stream *Parser::makeStream(Object *dict, Guchar *fileKey,
 
144
                           CryptAlgorithm encAlgorithm, int keyLength,
 
145
                           int objNum, int objGen) {
139
146
  Object obj;
140
147
  BaseStream *baseStr;
141
148
  Stream *str;
186
193
  // make base stream
187
194
  str = baseStr->makeSubStream(pos, gTrue, length, dict);
188
195
 
 
196
  // handle decryption
 
197
  if (fileKey) {
 
198
    str = new DecryptStream(str, fileKey, encAlgorithm, keyLength,
 
199
                            objNum, objGen);
 
200
  }
 
201
 
189
202
  // get filters
190
203
  str = str->addFilters(dict);
191
204