[poppler] 2 commits - poppler/Decrypt.h poppler/PDFDoc.cc poppler/Stream.cc poppler/Stream.h
Albert Astals Cid
aacid at kemper.freedesktop.org
Sat Apr 6 09:28:47 PDT 2013
poppler/Decrypt.h | 3 ++-
poppler/PDFDoc.cc | 38 +++++++++++++++++++++++++++++++++++---
poppler/Stream.cc | 6 ++++++
poppler/Stream.h | 3 ++-
4 files changed, 45 insertions(+), 5 deletions(-)
New commits:
commit 42368fb9452c3719a7bbd159f1c1421068f40653
Author: Albert Astals Cid <aacid at kde.org>
Date: Sat Apr 6 18:28:35 2013 +0200
Add missing free()
diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc
index cda6ed7..9cfbc7a 100644
--- a/poppler/PDFDoc.cc
+++ b/poppler/PDFDoc.cc
@@ -1163,6 +1163,7 @@ void PDFDoc::writeObject (Object* obj, OutStream* outStr, XRef *xRef, Guint numO
removeFilter = gFalse;
break;
}
+ filterEle.free();
}
if (removeFilter) {
encStream = new EncryptStream(stream, fileKey, encAlgorithm, keyLength, objNum, objGen);
commit 2264e7a95e5dc252de1b5736a1edd6bf5de3ad1f
Author: Thomas Freitag <Thomas.Freitag at alfa.de>
Date: Sat Apr 6 18:27:57 2013 +0200
implement Crypt filter
Bug #62800
diff --git a/poppler/Decrypt.h b/poppler/Decrypt.h
index ac786b9..10a6386 100644
--- a/poppler/Decrypt.h
+++ b/poppler/Decrypt.h
@@ -18,6 +18,7 @@
// Copyright (C) 2012 Fabio D'Urso <fabiodurso at hotmail.it>
// Copyright (C) 2013 Adrian Johnson <ajohnson at redneon.com>
// Copyright (C) 2013 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2013 Thomas Freitag <Thomas.Freitag at alfa.de>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
@@ -105,7 +106,7 @@ public:
BaseCryptStream(Stream *strA, Guchar *fileKey, CryptAlgorithm algoA,
int keyLength, int objNum, int objGen);
virtual ~BaseCryptStream();
- virtual StreamKind getKind() { return strWeird; }
+ virtual StreamKind getKind() { return strCrypt; }
virtual void reset();
virtual int getChar();
virtual int lookChar() = 0;
diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc
index 52d694f..cda6ed7 100644
--- a/poppler/PDFDoc.cc
+++ b/poppler/PDFDoc.cc
@@ -1144,12 +1144,41 @@ void PDFDoc::writeObject (Object* obj, OutStream* outStr, XRef *xRef, Guint numO
//We can't modify stream with the current implementation (no write functions in Stream API)
// => the only type of streams which that have been modified are internal streams (=strWeird)
Stream *stream = obj->getStream();
- if (stream->getKind() == strWeird) {
+ if (stream->getKind() == strWeird || stream->getKind() == strCrypt) {
//we write the stream unencoded => TODO: write stream encoder
// Encrypt stream
EncryptStream *encStream = NULL;
- if (fileKey) {
+ GBool removeFilter = gTrue;
+ if (stream->getKind() == strWeird && fileKey) {
+ Object filter;
+ stream->getDict()->lookup("Filter", &filter);
+ if (!filter.isName("Crypt")) {
+ if (filter.isArray()) {
+ for (int i = 0; i < filter.arrayGetLength(); i++) {
+ Object filterEle;
+ filter.arrayGet(i, &filterEle);
+ if (filterEle.isName("Crypt")) {
+ filterEle.free();
+ removeFilter = gFalse;
+ break;
+ }
+ }
+ if (removeFilter) {
+ encStream = new EncryptStream(stream, fileKey, encAlgorithm, keyLength, objNum, objGen);
+ encStream->setAutoDelete(gFalse);
+ stream = encStream;
+ }
+ } else {
+ encStream = new EncryptStream(stream, fileKey, encAlgorithm, keyLength, objNum, objGen);
+ encStream->setAutoDelete(gFalse);
+ stream = encStream;
+ }
+ } else {
+ removeFilter = gFalse;
+ }
+ filter.free();
+ } else if (fileKey != NULL) { // Encrypt stream
encStream = new EncryptStream(stream, fileKey, encAlgorithm, keyLength, objNum, objGen);
encStream->setAutoDelete(gFalse);
stream = encStream;
@@ -1165,7 +1194,9 @@ void PDFDoc::writeObject (Object* obj, OutStream* outStr, XRef *xRef, Guint numO
stream->getDict()->set("Length", &obj1);
//Remove Stream encoding
- stream->getDict()->remove("Filter");
+ if (removeFilter) {
+ stream->getDict()->remove("Filter");
+ }
stream->getDict()->remove("DecodeParms");
writeDictionnary (stream->getDict(),outStr, xRef, numOffset, fileKey, encAlgorithm, keyLength, objNum, objGen);
diff --git a/poppler/Stream.cc b/poppler/Stream.cc
index 5053344..e9533fa 100644
--- a/poppler/Stream.cc
+++ b/poppler/Stream.cc
@@ -342,6 +342,12 @@ Stream *Stream::makeFilter(char *name, Stream *str, Object *params, int recursio
globals.free();
} else if (!strcmp(name, "JPXDecode")) {
str = new JPXStream(str);
+ } else if (!strcmp(name, "Crypt")) {
+ if (str->getKind() == strCrypt) {
+ str = str->getBaseStream();
+ } else {
+ error(errSyntaxError, getPos(), "Can't revert non decrypt streams");
+ }
} else {
error(errSyntaxError, getPos(), "Unknown filter '{0:s}'", name);
str = new EOFStream(str);
diff --git a/poppler/Stream.h b/poppler/Stream.h
index d0d6ea8..0a178b4 100644
--- a/poppler/Stream.h
+++ b/poppler/Stream.h
@@ -62,7 +62,8 @@ enum StreamKind {
strFlate,
strJBIG2,
strJPX,
- strWeird // internal-use stream types
+ strWeird, // internal-use stream types
+ strCrypt // internal-use to detect decode streams
};
enum StreamColorSpaceMode {
More information about the poppler
mailing list