mirror of
https://github.com/qpdf/qpdf.git
synced 2024-06-07 12:50:52 +00:00
ABI change: fix use of off_t, size_t, and integer types
Significantly improve the code's use of off_t for file offsets, size_t for memory sizes, and integer types in cases where there has to be compatibility with external interfaces. Rework sections of the code that would have prevented qpdf from working on files larger than 2 (or maybe 4) GB in size.
This commit is contained in:
parent
24e2b2b76f
commit
5d4cad9c02
40
TODO
40
TODO
|
@ -1,35 +1,12 @@
|
||||||
Next
|
Next
|
||||||
====
|
====
|
||||||
|
|
||||||
* Get rid of off_t. size_t is okay. Use autoconf to figure out what
|
*** ABI changes have been made. build.mk has been updated.
|
||||||
type to use for offsets.
|
|
||||||
|
|
||||||
* Get rid of int/size_t/off_t inconsistencies. MSVC 2010 can find
|
|
||||||
these if you add /w14267 to the compilation. We might want to do
|
|
||||||
this by default. The easiest way to fix this on Windows is to
|
|
||||||
modify msvc.mk to add this to both cl /c lines and run
|
|
||||||
|
|
||||||
make 2>&1 | tee build.log
|
|
||||||
|
|
||||||
* Deal with portability issues from gcc 4.7. See portability.patch
|
|
||||||
from debian package.
|
|
||||||
|
|
||||||
* Do a Windows 64-bit build. MSVC 2010 Professional x86_64 verified
|
* Do a Windows 64-bit build. MSVC 2010 Professional x86_64 verified
|
||||||
to build and test cleanly in 2.3.1. Hopefully the next release
|
to build and test cleanly in 2.3.1. Hopefully the next release
|
||||||
will include 64-bit binary distributions and external libraries.
|
will include 64-bit binary distributions and external libraries.
|
||||||
|
|
||||||
* Provide an option to copy encryption parameters from another file.
|
|
||||||
This would make it possible to decrypt a file, manually work with
|
|
||||||
it, and then re-encrypt it using the original encryption parameters
|
|
||||||
including a possibly unknown owner password.
|
|
||||||
|
|
||||||
* See if I can support the new encryption formats mentioned in the
|
|
||||||
open bug on sourceforge. Check other sourceforge bugs.
|
|
||||||
|
|
||||||
|
|
||||||
Better 64-bit support on Windows
|
|
||||||
================================
|
|
||||||
|
|
||||||
* Building 64-bit libraries with MSVC works with existing build.sh as
|
* Building 64-bit libraries with MSVC works with existing build.sh as
|
||||||
long as the x86_64 version of the compiler is in the path.
|
long as the x86_64 version of the compiler is in the path.
|
||||||
Currently this generates 32-bit mingw and 64-bit msvc. We need to
|
Currently this generates 32-bit mingw and 64-bit msvc. We need to
|
||||||
|
@ -38,16 +15,13 @@ Better 64-bit support on Windows
|
||||||
only been verified with MSVC 2010 so far; we still need to get it
|
only been verified with MSVC 2010 so far; we still need to get it
|
||||||
working with 64-bit mingw.
|
working with 64-bit mingw.
|
||||||
|
|
||||||
* Get rid of int/size_t/off_t inconsistencies. MSVC 2010 can find
|
* Provide an option to copy encryption parameters from another file.
|
||||||
these if you add /w14267 to the compilation. We might want to do
|
This would make it possible to decrypt a file, manually work with
|
||||||
this by default. The easiest way to fix this on Windows is to
|
it, and then re-encrypt it using the original encryption parameters
|
||||||
modify msvc.mk to add this to both cl /c lines and run
|
including a possibly unknown owner password.
|
||||||
|
|
||||||
make 2>&1 | tee build.log
|
* See if I can support the new encryption formats mentioned in the
|
||||||
|
open bug on sourceforge. Check other sourceforge bugs.
|
||||||
Then, from emacs, compile with command cat build.log.
|
|
||||||
|
|
||||||
This will probably require ABI changes, but it seems worth doing.
|
|
||||||
|
|
||||||
|
|
||||||
General
|
General
|
||||||
|
|
21
configure.ac
21
configure.ac
|
@ -37,8 +37,29 @@ if test "$BUILD_INTERNAL_LIBS" = "0"; then
|
||||||
AC_SEARCH_LIBS(pcre_compile,pcre,,[MISSING_PCRE=1; MISSING_ANY=1])
|
AC_SEARCH_LIBS(pcre_compile,pcre,,[MISSING_PCRE=1; MISSING_ANY=1])
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
AC_SYS_LARGEFILE
|
||||||
|
AC_FUNC_FSEEKO
|
||||||
AC_TYPE_UINT16_T
|
AC_TYPE_UINT16_T
|
||||||
AC_TYPE_UINT32_T
|
AC_TYPE_UINT32_T
|
||||||
|
|
||||||
|
AC_MSG_CHECKING(for whether printf supports %ll)
|
||||||
|
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
int
|
||||||
|
main()
|
||||||
|
{
|
||||||
|
long long a = 160591605916059ll;
|
||||||
|
char t[50];
|
||||||
|
sprintf(t, "%lld", a);
|
||||||
|
}
|
||||||
|
]])],[qpdf_PRINTF_LL=yes],[qpdf_PRINTF_LL=no])
|
||||||
|
AC_MSG_RESULT($qpdf_PRINTF_LL)
|
||||||
|
if test "$qpdf_PRINTF_LL" = "yes"; then
|
||||||
|
AC_DEFINE([HAVE_PRINTF_LL], [1], [Whether printf supports %ll])
|
||||||
|
fi
|
||||||
|
|
||||||
AC_CHECK_FUNCS(random)
|
AC_CHECK_FUNCS(random)
|
||||||
|
|
||||||
# Check if LD supports linker scripts, and define conditional
|
# Check if LD supports linker scripts, and define conditional
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#define __BUFFER_HH__
|
#define __BUFFER_HH__
|
||||||
|
|
||||||
#include <qpdf/DLL.h>
|
#include <qpdf/DLL.h>
|
||||||
|
#include <cstring> // for size_t
|
||||||
|
|
||||||
class Buffer
|
class Buffer
|
||||||
{
|
{
|
||||||
|
@ -19,12 +20,12 @@ class Buffer
|
||||||
// Create a Buffer object whose memory is owned by the class and
|
// Create a Buffer object whose memory is owned by the class and
|
||||||
// will be freed when the Buffer object is destroyed.
|
// will be freed when the Buffer object is destroyed.
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
Buffer(unsigned long size);
|
Buffer(size_t size);
|
||||||
|
|
||||||
// Create a Buffer object whose memory is owned by the caller and
|
// Create a Buffer object whose memory is owned by the caller and
|
||||||
// will not be freed when the Buffer is destroyed.
|
// will not be freed when the Buffer is destroyed.
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
Buffer(unsigned char* buf, unsigned long size);
|
Buffer(unsigned char* buf, size_t size);
|
||||||
|
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
Buffer(Buffer const&);
|
Buffer(Buffer const&);
|
||||||
|
@ -33,19 +34,19 @@ class Buffer
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
~Buffer();
|
~Buffer();
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
unsigned long getSize() const;
|
size_t getSize() const;
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
unsigned char const* getBuffer() const;
|
unsigned char const* getBuffer() const;
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
unsigned char* getBuffer();
|
unsigned char* getBuffer();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void init(unsigned long size, unsigned char* buf, bool own_memory);
|
void init(size_t size, unsigned char* buf, bool own_memory);
|
||||||
void copy(Buffer const&);
|
void copy(Buffer const&);
|
||||||
void destroy();
|
void destroy();
|
||||||
|
|
||||||
bool own_memory;
|
bool own_memory;
|
||||||
unsigned long size;
|
size_t size;
|
||||||
unsigned char* buf;
|
unsigned char* buf;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ class Pipeline
|
||||||
// and then, if they are not end-of-line pipelines, call
|
// and then, if they are not end-of-line pipelines, call
|
||||||
// getNext()->write or getNext()->finish.
|
// getNext()->write or getNext()->finish.
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
virtual void write(unsigned char* data, int len) = 0;
|
virtual void write(unsigned char* data, size_t len) = 0;
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
virtual void finish() = 0;
|
virtual void finish() = 0;
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ class Pl_Buffer: public Pipeline
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
virtual ~Pl_Buffer();
|
virtual ~Pl_Buffer();
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
virtual void write(unsigned char*, int);
|
virtual void write(unsigned char*, size_t);
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
virtual void finish();
|
virtual void finish();
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
// calling finish().
|
// calling finish().
|
||||||
|
|
||||||
#include <qpdf/Pipeline.hh>
|
#include <qpdf/Pipeline.hh>
|
||||||
|
#include <qpdf/Types.h>
|
||||||
|
|
||||||
class Pl_Count: public Pipeline
|
class Pl_Count: public Pipeline
|
||||||
{
|
{
|
||||||
|
@ -21,19 +22,19 @@ class Pl_Count: public Pipeline
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
virtual ~Pl_Count();
|
virtual ~Pl_Count();
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
virtual void write(unsigned char*, int);
|
virtual void write(unsigned char*, size_t);
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
virtual void finish();
|
virtual void finish();
|
||||||
// Returns the number of bytes written
|
// Returns the number of bytes written
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
int getCount() const;
|
off_t getCount() const;
|
||||||
// Returns the last character written, or '\0' if no characters
|
// Returns the last character written, or '\0' if no characters
|
||||||
// have been written (in which case getCount() returns 0)
|
// have been written (in which case getCount() returns 0)
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
unsigned char getLastChar() const;
|
unsigned char getLastChar() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int count;
|
off_t count;
|
||||||
unsigned char last_char;
|
unsigned char last_char;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ class Pl_Discard: public Pipeline
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
virtual ~Pl_Discard();
|
virtual ~Pl_Discard();
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
virtual void write(unsigned char*, int);
|
virtual void write(unsigned char*, size_t);
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
virtual void finish();
|
virtual void finish();
|
||||||
};
|
};
|
||||||
|
|
|
@ -24,7 +24,7 @@ class Pl_Flate: public Pipeline
|
||||||
virtual ~Pl_Flate();
|
virtual ~Pl_Flate();
|
||||||
|
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
virtual void write(unsigned char* data, int len);
|
virtual void write(unsigned char* data, size_t len);
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
virtual void finish();
|
virtual void finish();
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ class Pl_StdioFile: public Pipeline
|
||||||
virtual ~Pl_StdioFile();
|
virtual ~Pl_StdioFile();
|
||||||
|
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
virtual void write(unsigned char* buf, int len);
|
virtual void write(unsigned char* buf, size_t len);
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
virtual void finish();
|
virtual void finish();
|
||||||
|
|
||||||
|
|
|
@ -388,7 +388,7 @@ class QPDF
|
||||||
virtual off_t tell() = 0;
|
virtual off_t tell() = 0;
|
||||||
virtual void seek(off_t offset, int whence) = 0;
|
virtual void seek(off_t offset, int whence) = 0;
|
||||||
virtual void rewind() = 0;
|
virtual void rewind() = 0;
|
||||||
virtual size_t read(char* buffer, int length) = 0;
|
virtual size_t read(char* buffer, size_t length) = 0;
|
||||||
virtual void unreadCh(char ch) = 0;
|
virtual void unreadCh(char ch) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -405,7 +405,7 @@ class QPDF
|
||||||
virtual off_t tell();
|
virtual off_t tell();
|
||||||
virtual void seek(off_t offset, int whence);
|
virtual void seek(off_t offset, int whence);
|
||||||
virtual void rewind();
|
virtual void rewind();
|
||||||
virtual size_t read(char* buffer, int length);
|
virtual size_t read(char* buffer, size_t length);
|
||||||
virtual void unreadCh(char ch);
|
virtual void unreadCh(char ch);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -428,7 +428,7 @@ class QPDF
|
||||||
virtual off_t tell();
|
virtual off_t tell();
|
||||||
virtual void seek(off_t offset, int whence);
|
virtual void seek(off_t offset, int whence);
|
||||||
virtual void rewind();
|
virtual void rewind();
|
||||||
virtual size_t read(char* buffer, int length);
|
virtual size_t read(char* buffer, size_t length);
|
||||||
virtual void unreadCh(char ch);
|
virtual void unreadCh(char ch);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -490,7 +490,7 @@ class QPDF
|
||||||
PointerHolder<InputSource> input, int objid, int generation,
|
PointerHolder<InputSource> input, int objid, int generation,
|
||||||
bool in_object_stream,
|
bool in_object_stream,
|
||||||
bool in_array, bool in_dictionary);
|
bool in_array, bool in_dictionary);
|
||||||
int recoverStreamLength(
|
size_t recoverStreamLength(
|
||||||
PointerHolder<InputSource> input, int objid, int generation,
|
PointerHolder<InputSource> input, int objid, int generation,
|
||||||
off_t stream_offset);
|
off_t stream_offset);
|
||||||
QPDFTokenizer::Token readToken(PointerHolder<InputSource>);
|
QPDFTokenizer::Token readToken(PointerHolder<InputSource>);
|
||||||
|
|
|
@ -327,7 +327,7 @@ class QPDFObjectHandle
|
||||||
// object must be dictionary object
|
// object must be dictionary object
|
||||||
static QPDFObjectHandle newStream(
|
static QPDFObjectHandle newStream(
|
||||||
QPDF* qpdf, int objid, int generation,
|
QPDF* qpdf, int objid, int generation,
|
||||||
QPDFObjectHandle stream_dict, off_t offset, int length)
|
QPDFObjectHandle stream_dict, off_t offset, size_t length)
|
||||||
{
|
{
|
||||||
return QPDFObjectHandle::newStream(
|
return QPDFObjectHandle::newStream(
|
||||||
qpdf, objid, generation, stream_dict, offset, length);
|
qpdf, objid, generation, stream_dict, offset, length);
|
||||||
|
@ -371,7 +371,7 @@ class QPDFObjectHandle
|
||||||
static QPDFObjectHandle newIndirect(QPDF*, int objid, int generation);
|
static QPDFObjectHandle newIndirect(QPDF*, int objid, int generation);
|
||||||
static QPDFObjectHandle newStream(
|
static QPDFObjectHandle newStream(
|
||||||
QPDF* qpdf, int objid, int generation,
|
QPDF* qpdf, int objid, int generation,
|
||||||
QPDFObjectHandle stream_dict, off_t offset, int length);
|
QPDFObjectHandle stream_dict, off_t offset, size_t length);
|
||||||
|
|
||||||
void assertInitialized() const;
|
void assertInitialized() const;
|
||||||
void assertType(char const* type_name, bool istype);
|
void assertType(char const* type_name, bool istype);
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
#include <qpdf/DLL.h>
|
#include <qpdf/DLL.h>
|
||||||
#include <qpdf/Constants.h>
|
#include <qpdf/Constants.h>
|
||||||
|
#include <qpdf/Types.h>
|
||||||
|
|
||||||
#include <qpdf/QPDFXRefEntry.hh>
|
#include <qpdf/QPDFXRefEntry.hh>
|
||||||
|
|
||||||
|
@ -219,7 +220,7 @@ class QPDFWriter
|
||||||
void writePad(int nspaces);
|
void writePad(int nspaces);
|
||||||
void assignCompressedObjectNumbers(int objid);
|
void assignCompressedObjectNumbers(int objid);
|
||||||
void enqueueObject(QPDFObjectHandle object);
|
void enqueueObject(QPDFObjectHandle object);
|
||||||
void writeObjectStreamOffsets(std::vector<int>& offsets, int first_obj);
|
void writeObjectStreamOffsets(std::vector<off_t>& offsets, int first_obj);
|
||||||
void writeObjectStream(QPDFObjectHandle object);
|
void writeObjectStream(QPDFObjectHandle object);
|
||||||
void writeObject(QPDFObjectHandle object, int object_stream_index = -1);
|
void writeObject(QPDFObjectHandle object, int object_stream_index = -1);
|
||||||
void writeTrailer(trailer_e which, int size,
|
void writeTrailer(trailer_e which, int size,
|
||||||
|
@ -229,7 +230,7 @@ class QPDFWriter
|
||||||
void unparseObject(QPDFObjectHandle object, int level,
|
void unparseObject(QPDFObjectHandle object, int level,
|
||||||
unsigned int flags,
|
unsigned int flags,
|
||||||
// for stream dictionaries
|
// for stream dictionaries
|
||||||
int stream_length, bool compress);
|
size_t stream_length, bool compress);
|
||||||
void unparseChild(QPDFObjectHandle child, int level, int flags);
|
void unparseChild(QPDFObjectHandle child, int level, int flags);
|
||||||
void initializeSpecialStreams();
|
void initializeSpecialStreams();
|
||||||
void preserveObjectStreams();
|
void preserveObjectStreams();
|
||||||
|
@ -266,8 +267,8 @@ class QPDFWriter
|
||||||
int prev,
|
int prev,
|
||||||
bool suppress_offsets,
|
bool suppress_offsets,
|
||||||
int hint_id,
|
int hint_id,
|
||||||
int hint_offset,
|
off_t hint_offset,
|
||||||
int hint_length);
|
off_t hint_length);
|
||||||
int writeXRefStream(int objid, int max_id, int max_offset,
|
int writeXRefStream(int objid, int max_id, int max_offset,
|
||||||
trailer_e which, int first, int last, int size);
|
trailer_e which, int first, int last, int size);
|
||||||
int writeXRefStream(int objid, int max_id, int max_offset,
|
int writeXRefStream(int objid, int max_id, int max_offset,
|
||||||
|
@ -275,8 +276,8 @@ class QPDFWriter
|
||||||
// for linearization
|
// for linearization
|
||||||
int prev,
|
int prev,
|
||||||
int hint_id,
|
int hint_id,
|
||||||
int hint_offset,
|
off_t hint_offset,
|
||||||
int hint_length,
|
off_t hint_length,
|
||||||
bool skip_compression);
|
bool skip_compression);
|
||||||
int calculateXrefStreamPadding(int xref_bytes);
|
int calculateXrefStreamPadding(int xref_bytes);
|
||||||
|
|
||||||
|
@ -295,7 +296,7 @@ class QPDFWriter
|
||||||
// stack items are of type Pl_Buffer, the buffer is retrieved.
|
// stack items are of type Pl_Buffer, the buffer is retrieved.
|
||||||
void popPipelineStack(PointerHolder<Buffer>* bp = 0);
|
void popPipelineStack(PointerHolder<Buffer>* bp = 0);
|
||||||
|
|
||||||
void adjustAESStreamLength(unsigned long& length);
|
void adjustAESStreamLength(size_t& length);
|
||||||
void pushEncryptionFilter();
|
void pushEncryptionFilter();
|
||||||
void pushDiscardFilter();
|
void pushDiscardFilter();
|
||||||
|
|
||||||
|
@ -336,7 +337,7 @@ class QPDFWriter
|
||||||
std::map<int, size_t> lengths;
|
std::map<int, size_t> lengths;
|
||||||
int next_objid;
|
int next_objid;
|
||||||
int cur_stream_length_id;
|
int cur_stream_length_id;
|
||||||
unsigned long cur_stream_length;
|
size_t cur_stream_length;
|
||||||
bool added_newline;
|
bool added_newline;
|
||||||
int max_ostream_index;
|
int max_ostream_index;
|
||||||
std::set<int> normalized_streams;
|
std::set<int> normalized_streams;
|
||||||
|
|
|
@ -23,12 +23,12 @@ class QPDFXRefEntry
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
QPDFXRefEntry();
|
QPDFXRefEntry();
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
QPDFXRefEntry(int type, int field1, int field2);
|
QPDFXRefEntry(int type, off_t field1, int field2);
|
||||||
|
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
int getType() const;
|
int getType() const;
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
int getOffset() const; // only for type 1
|
off_t getOffset() const; // only for type 1
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
int getObjStreamNumber() const; // only for type 2
|
int getObjStreamNumber() const; // only for type 2
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
|
@ -36,7 +36,7 @@ class QPDFXRefEntry
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int type;
|
int type;
|
||||||
int field1;
|
off_t field1;
|
||||||
int field2;
|
int field2;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#define __QUTIL_HH__
|
#define __QUTIL_HH__
|
||||||
|
|
||||||
#include <qpdf/DLL.h>
|
#include <qpdf/DLL.h>
|
||||||
|
#include <qpdf/Types.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
@ -20,7 +21,7 @@ namespace QUtil
|
||||||
// This is a collection of useful utility functions that don't
|
// This is a collection of useful utility functions that don't
|
||||||
// really go anywhere else.
|
// really go anywhere else.
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
std::string int_to_string(int, int length = 0);
|
std::string int_to_string(long long, int length = 0);
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
std::string double_to_string(double, int decimal_places = 0);
|
std::string double_to_string(double, int decimal_places = 0);
|
||||||
|
|
||||||
|
@ -44,6 +45,12 @@ namespace QUtil
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
FILE* fopen_wrapper(std::string const&, FILE*);
|
FILE* fopen_wrapper(std::string const&, FILE*);
|
||||||
|
|
||||||
|
// Wrap around off_t versions of fseek and ftell if available
|
||||||
|
QPDF_DLL
|
||||||
|
int fseek_off_t(FILE* stream, off_t offset, int whence);
|
||||||
|
QPDF_DLL
|
||||||
|
off_t ftell_off_t(FILE* stream);
|
||||||
|
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
char* copy_string(std::string const&);
|
char* copy_string(std::string const&);
|
||||||
|
|
||||||
|
|
|
@ -71,6 +71,7 @@
|
||||||
|
|
||||||
#include <qpdf/DLL.h>
|
#include <qpdf/DLL.h>
|
||||||
#include <qpdf/Constants.h>
|
#include <qpdf/Constants.h>
|
||||||
|
#include <qpdf/Types.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -300,7 +301,7 @@ extern "C" {
|
||||||
* if a subsequent call to qpdf_init_write or
|
* if a subsequent call to qpdf_init_write or
|
||||||
* qpdf_init_write_memory is called. */
|
* qpdf_init_write_memory is called. */
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
unsigned long qpdf_get_buffer_length(qpdf_data qpdf);
|
size_t qpdf_get_buffer_length(qpdf_data qpdf);
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
unsigned char const* qpdf_get_buffer(qpdf_data qpdf);
|
unsigned char const* qpdf_get_buffer(qpdf_data qpdf);
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ BitWriter::BitWriter(Pipeline* pl) :
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
BitWriter::writeBits(unsigned long val, int bits)
|
BitWriter::writeBits(unsigned long val, unsigned int bits)
|
||||||
{
|
{
|
||||||
write_bits(this->ch, this->bit_offset, val, bits, this->pl);
|
write_bits(this->ch, this->bit_offset, val, bits, this->pl);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,12 +7,12 @@ Buffer::Buffer()
|
||||||
init(0, 0, true);
|
init(0, 0, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
Buffer::Buffer(unsigned long size)
|
Buffer::Buffer(size_t size)
|
||||||
{
|
{
|
||||||
init(size, 0, true);
|
init(size, 0, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
Buffer::Buffer(unsigned char* buf, unsigned long size)
|
Buffer::Buffer(unsigned char* buf, size_t size)
|
||||||
{
|
{
|
||||||
init(size, buf, false);
|
init(size, buf, false);
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ Buffer::~Buffer()
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Buffer::init(unsigned long size, unsigned char* buf, bool own_memory)
|
Buffer::init(size_t size, unsigned char* buf, bool own_memory)
|
||||||
{
|
{
|
||||||
this->own_memory = own_memory;
|
this->own_memory = own_memory;
|
||||||
this->size = size;
|
this->size = size;
|
||||||
|
@ -75,7 +75,7 @@ Buffer::destroy()
|
||||||
this->buf = 0;
|
this->buf = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long
|
size_t
|
||||||
Buffer::getSize() const
|
Buffer::getSize() const
|
||||||
{
|
{
|
||||||
return this->size;
|
return this->size;
|
||||||
|
|
|
@ -308,7 +308,7 @@ void MD5::reset()
|
||||||
|
|
||||||
void MD5::encodeString(char const* str)
|
void MD5::encodeString(char const* str)
|
||||||
{
|
{
|
||||||
unsigned int len = strlen(str);
|
unsigned int len = (unsigned int)strlen(str);
|
||||||
|
|
||||||
update((unsigned char *)str, len);
|
update((unsigned char *)str, len);
|
||||||
final();
|
final();
|
||||||
|
@ -316,7 +316,7 @@ void MD5::encodeString(char const* str)
|
||||||
|
|
||||||
void MD5::appendString(char const* input_string)
|
void MD5::appendString(char const* input_string)
|
||||||
{
|
{
|
||||||
update((unsigned char *)input_string, strlen(input_string));
|
update((unsigned char *)input_string, (unsigned int) strlen(input_string));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MD5::encodeDataIncrementally(char const* data, int len)
|
void MD5::encodeDataIncrementally(char const* data, int len)
|
||||||
|
@ -332,7 +332,7 @@ void MD5::encodeFile(char const *filename, int up_to_size)
|
||||||
std::string("MD5: open ") + filename,
|
std::string("MD5: open ") + filename,
|
||||||
fopen(filename, "rb"));
|
fopen(filename, "rb"));
|
||||||
|
|
||||||
int len;
|
size_t len;
|
||||||
int so_far = 0;
|
int so_far = 0;
|
||||||
int to_try = 1024;
|
int to_try = 1024;
|
||||||
do
|
do
|
||||||
|
@ -344,7 +344,7 @@ void MD5::encodeFile(char const *filename, int up_to_size)
|
||||||
len = fread(buffer, 1, to_try, file);
|
len = fread(buffer, 1, to_try, file);
|
||||||
if (len > 0)
|
if (len > 0)
|
||||||
{
|
{
|
||||||
update(buffer, len);
|
update(buffer, (unsigned int) len);
|
||||||
so_far += len;
|
so_far += len;
|
||||||
if ((up_to_size >= 0) && (so_far >= up_to_size))
|
if ((up_to_size >= 0) && (so_far >= up_to_size))
|
||||||
{
|
{
|
||||||
|
|
|
@ -166,7 +166,7 @@ PCRE::match(char const* subject, int options, int startoffset, int size)
|
||||||
{
|
{
|
||||||
if (size == -1)
|
if (size == -1)
|
||||||
{
|
{
|
||||||
size = strlen(subject);
|
size = (int) strlen(subject);
|
||||||
}
|
}
|
||||||
|
|
||||||
Match result(this->nbackrefs, subject);
|
Match result(this->nbackrefs, subject);
|
||||||
|
|
|
@ -60,9 +60,9 @@ Pl_AES_PDF::useStaticIV()
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Pl_AES_PDF::write(unsigned char* data, int len)
|
Pl_AES_PDF::write(unsigned char* data, size_t len)
|
||||||
{
|
{
|
||||||
unsigned int bytes_left = len;
|
size_t bytes_left = len;
|
||||||
unsigned char* p = data;
|
unsigned char* p = data;
|
||||||
|
|
||||||
while (bytes_left > 0)
|
while (bytes_left > 0)
|
||||||
|
@ -72,8 +72,8 @@ Pl_AES_PDF::write(unsigned char* data, int len)
|
||||||
flush(false);
|
flush(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int available = this->buf_size - this->offset;
|
size_t available = this->buf_size - this->offset;
|
||||||
int bytes = (bytes_left < available ? bytes_left : available);
|
size_t bytes = (bytes_left < available ? bytes_left : available);
|
||||||
bytes_left -= bytes;
|
bytes_left -= bytes;
|
||||||
std::memcpy(this->inbuf + this->offset, p, bytes);
|
std::memcpy(this->inbuf + this->offset, p, bytes);
|
||||||
this->offset += bytes;
|
this->offset += bytes;
|
||||||
|
@ -93,7 +93,7 @@ Pl_AES_PDF::finish()
|
||||||
// Pad as described in section 3.5.1 of version 1.7 of the PDF
|
// Pad as described in section 3.5.1 of version 1.7 of the PDF
|
||||||
// specification, including providing an entire block of padding
|
// specification, including providing an entire block of padding
|
||||||
// if the input was a multiple of 16 bytes.
|
// if the input was a multiple of 16 bytes.
|
||||||
unsigned char pad = this->buf_size - this->offset;
|
unsigned char pad = (unsigned char) (this->buf_size - this->offset);
|
||||||
memset(this->inbuf + this->offset, pad, pad);
|
memset(this->inbuf + this->offset, pad, pad);
|
||||||
this->offset = this->buf_size;
|
this->offset = this->buf_size;
|
||||||
flush(false);
|
flush(false);
|
||||||
|
|
|
@ -16,13 +16,13 @@ Pl_ASCII85Decoder::~Pl_ASCII85Decoder()
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Pl_ASCII85Decoder::write(unsigned char* buf, int len)
|
Pl_ASCII85Decoder::write(unsigned char* buf, size_t len)
|
||||||
{
|
{
|
||||||
if (eod > 1)
|
if (eod > 1)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < len; ++i)
|
for (size_t i = 0; i < len; ++i)
|
||||||
{
|
{
|
||||||
if (eod > 1)
|
if (eod > 1)
|
||||||
{
|
{
|
||||||
|
|
|
@ -17,13 +17,13 @@ Pl_ASCIIHexDecoder::~Pl_ASCIIHexDecoder()
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Pl_ASCIIHexDecoder::write(unsigned char* buf, int len)
|
Pl_ASCIIHexDecoder::write(unsigned char* buf, size_t len)
|
||||||
{
|
{
|
||||||
if (this->eod)
|
if (this->eod)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < len; ++i)
|
for (size_t i = 0; i < len; ++i)
|
||||||
{
|
{
|
||||||
char ch = toupper(buf[i]);
|
char ch = toupper(buf[i]);
|
||||||
switch (ch)
|
switch (ch)
|
||||||
|
|
|
@ -15,7 +15,7 @@ Pl_Buffer::~Pl_Buffer()
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Pl_Buffer::write(unsigned char* buf, int len)
|
Pl_Buffer::write(unsigned char* buf, size_t len)
|
||||||
{
|
{
|
||||||
Buffer* b = new Buffer(len);
|
Buffer* b = new Buffer(len);
|
||||||
memcpy(b->getBuffer(), buf, len);
|
memcpy(b->getBuffer(), buf, len);
|
||||||
|
|
|
@ -12,7 +12,7 @@ Pl_Count::~Pl_Count()
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Pl_Count::write(unsigned char* buf, int len)
|
Pl_Count::write(unsigned char* buf, size_t len)
|
||||||
{
|
{
|
||||||
if (len)
|
if (len)
|
||||||
{
|
{
|
||||||
|
@ -28,7 +28,7 @@ Pl_Count::finish()
|
||||||
getNext()->finish();
|
getNext()->finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
off_t
|
||||||
Pl_Count::getCount() const
|
Pl_Count::getCount() const
|
||||||
{
|
{
|
||||||
return this->count;
|
return this->count;
|
||||||
|
|
|
@ -12,7 +12,7 @@ Pl_Discard::~Pl_Discard()
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Pl_Discard::write(unsigned char* buf, int len)
|
Pl_Discard::write(unsigned char* buf, size_t len)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ Pl_Flate::~Pl_Flate()
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Pl_Flate::write(unsigned char* data, int len)
|
Pl_Flate::write(unsigned char* data, size_t len)
|
||||||
{
|
{
|
||||||
if (this->outbuf == 0)
|
if (this->outbuf == 0)
|
||||||
{
|
{
|
||||||
|
@ -48,7 +48,19 @@ Pl_Flate::write(unsigned char* data, int len)
|
||||||
this->identifier +
|
this->identifier +
|
||||||
": Pl_Flate: write() called after finish() called");
|
": Pl_Flate: write() called after finish() called");
|
||||||
}
|
}
|
||||||
handleData(data, len, Z_NO_FLUSH);
|
|
||||||
|
// Write in chunks in case len is too big to fit in an int.
|
||||||
|
// Assume int is at least 32 bits.
|
||||||
|
static size_t const max_bytes = 1 << 30;
|
||||||
|
size_t bytes_left = len;
|
||||||
|
unsigned char* buf = data;
|
||||||
|
while (bytes_left > 0)
|
||||||
|
{
|
||||||
|
size_t bytes = (bytes_left >= max_bytes ? max_bytes : bytes_left);
|
||||||
|
handleData(buf, (int)bytes, Z_NO_FLUSH);
|
||||||
|
bytes_left -= bytes;
|
||||||
|
buf += bytes;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -25,9 +25,9 @@ Pl_LZWDecoder::~Pl_LZWDecoder()
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Pl_LZWDecoder::write(unsigned char* bytes, int len)
|
Pl_LZWDecoder::write(unsigned char* bytes, size_t len)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < len; ++i)
|
for (size_t i = 0; i < len; ++i)
|
||||||
{
|
{
|
||||||
this->buf[next++] = bytes[i];
|
this->buf[next++] = bytes[i];
|
||||||
if (this->next == 3)
|
if (this->next == 3)
|
||||||
|
@ -131,7 +131,7 @@ Pl_LZWDecoder::addToTable(unsigned char next)
|
||||||
assert(idx < table.size());
|
assert(idx < table.size());
|
||||||
Buffer& b = table[idx];
|
Buffer& b = table[idx];
|
||||||
last_data = b.getBuffer();
|
last_data = b.getBuffer();
|
||||||
last_size = b.getSize();
|
last_size = (unsigned int) b.getSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
Buffer entry(1 + last_size);
|
Buffer entry(1 + last_size);
|
||||||
|
@ -170,7 +170,7 @@ Pl_LZWDecoder::handleCode(int code)
|
||||||
// be what we read last plus the first character of what
|
// be what we read last plus the first character of what
|
||||||
// we're reading now.
|
// we're reading now.
|
||||||
unsigned char next = '\0';
|
unsigned char next = '\0';
|
||||||
unsigned int table_size = table.size();
|
unsigned int table_size = (unsigned int) table.size();
|
||||||
if (code < 256)
|
if (code < 256)
|
||||||
{
|
{
|
||||||
// just read < 256; last time's next was code
|
// just read < 256; last time's next was code
|
||||||
|
@ -178,7 +178,7 @@ Pl_LZWDecoder::handleCode(int code)
|
||||||
}
|
}
|
||||||
else if (code > 257)
|
else if (code > 257)
|
||||||
{
|
{
|
||||||
unsigned int idx = code - 258;
|
size_t idx = code - 258;
|
||||||
if (idx > table_size)
|
if (idx > table_size)
|
||||||
{
|
{
|
||||||
throw std::runtime_error("LZWDecoder: bad code received");
|
throw std::runtime_error("LZWDecoder: bad code received");
|
||||||
|
|
|
@ -12,14 +12,27 @@ Pl_MD5::~Pl_MD5()
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Pl_MD5::write(unsigned char* buf, int len)
|
Pl_MD5::write(unsigned char* buf, size_t len)
|
||||||
{
|
{
|
||||||
if (! this->in_progress)
|
if (! this->in_progress)
|
||||||
{
|
{
|
||||||
this->md5.reset();
|
this->md5.reset();
|
||||||
this->in_progress = true;
|
this->in_progress = true;
|
||||||
}
|
}
|
||||||
this->md5.encodeDataIncrementally((char*) buf, len);
|
|
||||||
|
// Write in chunks in case len is too big to fit in an int.
|
||||||
|
// Assume int is at least 32 bits.
|
||||||
|
static size_t const max_bytes = 1 << 30;
|
||||||
|
size_t bytes_left = len;
|
||||||
|
unsigned char* data = buf;
|
||||||
|
while (bytes_left > 0)
|
||||||
|
{
|
||||||
|
size_t bytes = (bytes_left >= max_bytes ? max_bytes : bytes_left);
|
||||||
|
this->md5.encodeDataIncrementally((char*) data, (int)bytes);
|
||||||
|
bytes_left -= bytes;
|
||||||
|
data += bytes;
|
||||||
|
}
|
||||||
|
|
||||||
this->getNext()->write(buf, len);
|
this->getNext()->write(buf, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,10 +29,10 @@ Pl_PNGFilter::~Pl_PNGFilter()
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Pl_PNGFilter::write(unsigned char* data, int len)
|
Pl_PNGFilter::write(unsigned char* data, size_t len)
|
||||||
{
|
{
|
||||||
int left = this->incoming - this->pos;
|
size_t left = this->incoming - this->pos;
|
||||||
unsigned int offset = 0;
|
size_t offset = 0;
|
||||||
while (len >= left)
|
while (len >= left)
|
||||||
{
|
{
|
||||||
// finish off current row
|
// finish off current row
|
||||||
|
|
|
@ -22,7 +22,7 @@ Pl_QPDFTokenizer::~Pl_QPDFTokenizer()
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Pl_QPDFTokenizer::writeNext(char const* buf, int len)
|
Pl_QPDFTokenizer::writeNext(char const* buf, size_t len)
|
||||||
{
|
{
|
||||||
if (len)
|
if (len)
|
||||||
{
|
{
|
||||||
|
@ -159,10 +159,10 @@ Pl_QPDFTokenizer::checkUnread()
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Pl_QPDFTokenizer::write(unsigned char* buf, int len)
|
Pl_QPDFTokenizer::write(unsigned char* buf, size_t len)
|
||||||
{
|
{
|
||||||
checkUnread();
|
checkUnread();
|
||||||
for (int i = 0; i < len; ++i)
|
for (size_t i = 0; i < len; ++i)
|
||||||
{
|
{
|
||||||
processChar(buf[i]);
|
processChar(buf[i]);
|
||||||
checkUnread();
|
checkUnread();
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
Pl_RC4::Pl_RC4(char const* identifier, Pipeline* next,
|
Pl_RC4::Pl_RC4(char const* identifier, Pipeline* next,
|
||||||
unsigned char const* key_data, int key_len,
|
unsigned char const* key_data, int key_len,
|
||||||
int out_bufsize) :
|
size_t out_bufsize) :
|
||||||
Pipeline(identifier, next),
|
Pipeline(identifier, next),
|
||||||
out_bufsize(out_bufsize),
|
out_bufsize(out_bufsize),
|
||||||
rc4(key_data, key_len)
|
rc4(key_data, key_len)
|
||||||
|
@ -21,7 +21,7 @@ Pl_RC4::~Pl_RC4()
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Pl_RC4::write(unsigned char* data, int len)
|
Pl_RC4::write(unsigned char* data, size_t len)
|
||||||
{
|
{
|
||||||
if (this->outbuf == 0)
|
if (this->outbuf == 0)
|
||||||
{
|
{
|
||||||
|
@ -30,14 +30,15 @@ Pl_RC4::write(unsigned char* data, int len)
|
||||||
": Pl_RC4: write() called after finish() called");
|
": Pl_RC4: write() called after finish() called");
|
||||||
}
|
}
|
||||||
|
|
||||||
int bytes_left = len;
|
size_t bytes_left = len;
|
||||||
unsigned char* p = data;
|
unsigned char* p = data;
|
||||||
|
|
||||||
while (bytes_left > 0)
|
while (bytes_left > 0)
|
||||||
{
|
{
|
||||||
int bytes = (bytes_left < this->out_bufsize ? bytes_left : out_bufsize);
|
size_t bytes =
|
||||||
|
(bytes_left < this->out_bufsize ? bytes_left : out_bufsize);
|
||||||
bytes_left -= bytes;
|
bytes_left -= bytes;
|
||||||
rc4.process(p, bytes, outbuf);
|
rc4.process(p, (int)bytes, outbuf);
|
||||||
p += bytes;
|
p += bytes;
|
||||||
getNext()->write(outbuf, bytes);
|
getNext()->write(outbuf, bytes);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ Pl_StdioFile::~Pl_StdioFile()
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Pl_StdioFile::write(unsigned char* buf, int len)
|
Pl_StdioFile::write(unsigned char* buf, size_t len)
|
||||||
{
|
{
|
||||||
size_t so_far = 0;
|
size_t so_far = 0;
|
||||||
while (len > 0)
|
while (len > 0)
|
||||||
|
|
|
@ -117,7 +117,7 @@ QPDF::FileInputSource::getName() const
|
||||||
off_t
|
off_t
|
||||||
QPDF::FileInputSource::tell()
|
QPDF::FileInputSource::tell()
|
||||||
{
|
{
|
||||||
return ftell(this->file);
|
return QUtil::ftell_off_t(this->file);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -126,7 +126,7 @@ QPDF::FileInputSource::seek(off_t offset, int whence)
|
||||||
QUtil::os_wrapper(std::string("seek to ") + this->filename + ", offset " +
|
QUtil::os_wrapper(std::string("seek to ") + this->filename + ", offset " +
|
||||||
QUtil::int_to_string(offset) + " (" +
|
QUtil::int_to_string(offset) + " (" +
|
||||||
QUtil::int_to_string(whence) + ")",
|
QUtil::int_to_string(whence) + ")",
|
||||||
fseek(this->file, offset, whence));
|
QUtil::fseek_off_t(this->file, offset, whence));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -136,9 +136,9 @@ QPDF::FileInputSource::rewind()
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
QPDF::FileInputSource::read(char* buffer, int length)
|
QPDF::FileInputSource::read(char* buffer, size_t length)
|
||||||
{
|
{
|
||||||
this->last_offset = ftell(this->file);
|
this->last_offset = QUtil::ftell_off_t(this->file);
|
||||||
size_t len = fread(buffer, 1, length, this->file);
|
size_t len = fread(buffer, 1, length, this->file);
|
||||||
if ((len == 0) && ferror(this->file))
|
if ((len == 0) && ferror(this->file))
|
||||||
{
|
{
|
||||||
|
@ -197,7 +197,7 @@ QPDF::BufferInputSource::seek(off_t offset, int whence)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SEEK_END:
|
case SEEK_END:
|
||||||
this->cur_offset = this->buf->getSize() + offset;
|
this->cur_offset = (off_t)this->buf->getSize() + offset;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SEEK_CUR:
|
case SEEK_CUR:
|
||||||
|
@ -218,9 +218,9 @@ QPDF::BufferInputSource::rewind()
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
QPDF::BufferInputSource::read(char* buffer, int length)
|
QPDF::BufferInputSource::read(char* buffer, size_t length)
|
||||||
{
|
{
|
||||||
off_t end_pos = this->buf->getSize();
|
off_t end_pos = (off_t) this->buf->getSize();
|
||||||
if (this->cur_offset >= end_pos)
|
if (this->cur_offset >= end_pos)
|
||||||
{
|
{
|
||||||
this->last_offset = end_pos;
|
this->last_offset = end_pos;
|
||||||
|
@ -228,7 +228,7 @@ QPDF::BufferInputSource::read(char* buffer, int length)
|
||||||
}
|
}
|
||||||
|
|
||||||
this->last_offset = this->cur_offset;
|
this->last_offset = this->cur_offset;
|
||||||
size_t len = std::min((int)(end_pos - this->cur_offset), length);
|
size_t len = std::min((size_t)(end_pos - this->cur_offset), length);
|
||||||
memcpy(buffer, buf->getBuffer() + this->cur_offset, len);
|
memcpy(buffer, buf->getBuffer() + this->cur_offset, len);
|
||||||
this->cur_offset += len;
|
this->cur_offset += len;
|
||||||
return len;
|
return len;
|
||||||
|
@ -432,7 +432,7 @@ QPDF::parse(char const* password)
|
||||||
throw QPDFExc(qpdf_e_damaged_pdf, this->file->getName(), "", 0,
|
throw QPDFExc(qpdf_e_damaged_pdf, this->file->getName(), "", 0,
|
||||||
"can't find startxref");
|
"can't find startxref");
|
||||||
}
|
}
|
||||||
off_t xref_offset = atoi(m2.getMatch(1).c_str());
|
off_t xref_offset = atol(m2.getMatch(1).c_str());
|
||||||
read_xref(xref_offset);
|
read_xref(xref_offset);
|
||||||
}
|
}
|
||||||
catch (QPDFExc& e)
|
catch (QPDFExc& e)
|
||||||
|
@ -878,10 +878,10 @@ QPDF::processXRefStream(off_t xref_offset, QPDFObjectHandle& xref_obj)
|
||||||
entry_size += W[i];
|
entry_size += W[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
int expected_size = entry_size * num_entries;
|
size_t expected_size = entry_size * num_entries;
|
||||||
|
|
||||||
PointerHolder<Buffer> bp = xref_obj.getStreamData();
|
PointerHolder<Buffer> bp = xref_obj.getStreamData();
|
||||||
int actual_size = bp->getSize();
|
size_t actual_size = bp->getSize();
|
||||||
|
|
||||||
if (expected_size != actual_size)
|
if (expected_size != actual_size)
|
||||||
{
|
{
|
||||||
|
@ -1396,7 +1396,7 @@ QPDF::readObjectInternal(PointerHolder<InputSource> input,
|
||||||
// objects since resolving a previously unresolved
|
// objects since resolving a previously unresolved
|
||||||
// indirect object will change file position.
|
// indirect object will change file position.
|
||||||
off_t stream_offset = input->tell();
|
off_t stream_offset = input->tell();
|
||||||
int length = 0;
|
size_t length = 0;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -1419,7 +1419,7 @@ QPDF::readObjectInternal(PointerHolder<InputSource> input,
|
||||||
}
|
}
|
||||||
|
|
||||||
length = length_obj.getIntValue();
|
length = length_obj.getIntValue();
|
||||||
input->seek(stream_offset + length, SEEK_SET);
|
input->seek(stream_offset + (off_t)length, SEEK_SET);
|
||||||
if (! (readToken(input) ==
|
if (! (readToken(input) ==
|
||||||
QPDFTokenizer::Token(
|
QPDFTokenizer::Token(
|
||||||
QPDFTokenizer::tt_word, "endstream")))
|
QPDFTokenizer::tt_word, "endstream")))
|
||||||
|
@ -1457,7 +1457,7 @@ QPDF::readObjectInternal(PointerHolder<InputSource> input,
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
size_t
|
||||||
QPDF::recoverStreamLength(PointerHolder<InputSource> input,
|
QPDF::recoverStreamLength(PointerHolder<InputSource> input,
|
||||||
int objid, int generation, off_t stream_offset)
|
int objid, int generation, off_t stream_offset)
|
||||||
{
|
{
|
||||||
|
@ -1474,7 +1474,7 @@ QPDF::recoverStreamLength(PointerHolder<InputSource> input,
|
||||||
input->seek(stream_offset, SEEK_SET);
|
input->seek(stream_offset, SEEK_SET);
|
||||||
std::string last_line;
|
std::string last_line;
|
||||||
off_t last_line_offset = 0;
|
off_t last_line_offset = 0;
|
||||||
int length = 0;
|
size_t length = 0;
|
||||||
while (input->tell() < eof)
|
while (input->tell() < eof)
|
||||||
{
|
{
|
||||||
std::string line = input->readLine();
|
std::string line = input->readLine();
|
||||||
|
|
|
@ -604,7 +604,7 @@ QPDFObjectHandle::newDictionary(
|
||||||
QPDFObjectHandle
|
QPDFObjectHandle
|
||||||
QPDFObjectHandle::newStream(QPDF* qpdf, int objid, int generation,
|
QPDFObjectHandle::newStream(QPDF* qpdf, int objid, int generation,
|
||||||
QPDFObjectHandle stream_dict,
|
QPDFObjectHandle stream_dict,
|
||||||
off_t offset, int length)
|
off_t offset, size_t length)
|
||||||
{
|
{
|
||||||
return QPDFObjectHandle(new QPDF_Stream(
|
return QPDFObjectHandle(new QPDF_Stream(
|
||||||
qpdf, objid, generation,
|
qpdf, objid, generation,
|
||||||
|
|
|
@ -175,7 +175,7 @@ QPDFTokenizer::presentCharacter(char ch)
|
||||||
string_ignoring_newline = false;
|
string_ignoring_newline = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int bs_num_count = strlen(bs_num_register);
|
size_t bs_num_count = strlen(bs_num_register);
|
||||||
bool ch_is_octal = ((ch >= '0') && (ch <= '7'));
|
bool ch_is_octal = ((ch >= '0') && (ch <= '7'));
|
||||||
if ((bs_num_count == 3) || ((bs_num_count > 0) && (! ch_is_octal)))
|
if ((bs_num_count == 3) || ((bs_num_count > 0) && (! ch_is_octal)))
|
||||||
{
|
{
|
||||||
|
|
|
@ -651,7 +651,7 @@ QPDFWriter::popPipelineStack(PointerHolder<Buffer>* bp)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
QPDFWriter::adjustAESStreamLength(unsigned long& length)
|
QPDFWriter::adjustAESStreamLength(size_t& length)
|
||||||
{
|
{
|
||||||
if (this->encrypted && (! this->cur_data_key.empty()) &&
|
if (this->encrypted && (! this->cur_data_key.empty()) &&
|
||||||
this->encrypt_use_aes)
|
this->encrypt_use_aes)
|
||||||
|
@ -679,7 +679,7 @@ QPDFWriter::pushEncryptionFilter()
|
||||||
{
|
{
|
||||||
p = new Pl_RC4("rc4 stream encryption", this->pipeline,
|
p = new Pl_RC4("rc4 stream encryption", this->pipeline,
|
||||||
(unsigned char*) this->cur_data_key.c_str(),
|
(unsigned char*) this->cur_data_key.c_str(),
|
||||||
this->cur_data_key.length());
|
(int)this->cur_data_key.length());
|
||||||
}
|
}
|
||||||
pushPipeline(p);
|
pushPipeline(p);
|
||||||
}
|
}
|
||||||
|
@ -879,9 +879,9 @@ QPDFWriter::writeTrailer(trailer_e which, int size, bool xref_stream, int prev)
|
||||||
if (which == t_lin_first)
|
if (which == t_lin_first)
|
||||||
{
|
{
|
||||||
writeString(" /Prev ");
|
writeString(" /Prev ");
|
||||||
int pos = this->pipeline->getCount();
|
off_t pos = this->pipeline->getCount();
|
||||||
writeString(QUtil::int_to_string(prev));
|
writeString(QUtil::int_to_string(prev));
|
||||||
int nspaces = pos + 11 - this->pipeline->getCount();
|
int nspaces = (int)(pos - this->pipeline->getCount() + 11);
|
||||||
assert(nspaces >= 0);
|
assert(nspaces >= 0);
|
||||||
writePad(nspaces);
|
writePad(nspaces);
|
||||||
}
|
}
|
||||||
|
@ -926,7 +926,8 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level,
|
||||||
|
|
||||||
void
|
void
|
||||||
QPDFWriter::unparseObject(QPDFObjectHandle object, int level,
|
QPDFWriter::unparseObject(QPDFObjectHandle object, int level,
|
||||||
unsigned int flags, int stream_length, bool compress)
|
unsigned int flags, size_t stream_length,
|
||||||
|
bool compress)
|
||||||
{
|
{
|
||||||
unsigned int child_flags = flags & ~f_stream;
|
unsigned int child_flags = flags & ~f_stream;
|
||||||
|
|
||||||
|
@ -1137,16 +1138,16 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level,
|
||||||
Buffer* buf = bufpl.getBuffer();
|
Buffer* buf = bufpl.getBuffer();
|
||||||
val = QPDF_String(
|
val = QPDF_String(
|
||||||
std::string((char*)buf->getBuffer(),
|
std::string((char*)buf->getBuffer(),
|
||||||
(size_t)buf->getSize())).unparse(true);
|
buf->getSize())).unparse(true);
|
||||||
delete buf;
|
delete buf;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
char* tmp = QUtil::copy_string(val);
|
char* tmp = QUtil::copy_string(val);
|
||||||
unsigned int vlen = val.length();
|
size_t vlen = val.length();
|
||||||
RC4 rc4((unsigned char const*)this->cur_data_key.c_str(),
|
RC4 rc4((unsigned char const*)this->cur_data_key.c_str(),
|
||||||
this->cur_data_key.length());
|
(int)this->cur_data_key.length());
|
||||||
rc4.process((unsigned char*)tmp, vlen);
|
rc4.process((unsigned char*)tmp, (int)vlen);
|
||||||
val = QPDF_String(std::string(tmp, vlen)).unparse();
|
val = QPDF_String(std::string(tmp, vlen)).unparse();
|
||||||
delete [] tmp;
|
delete [] tmp;
|
||||||
}
|
}
|
||||||
|
@ -1164,7 +1165,7 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level,
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
QPDFWriter::writeObjectStreamOffsets(std::vector<int>& offsets,
|
QPDFWriter::writeObjectStreamOffsets(std::vector<off_t>& offsets,
|
||||||
int first_obj)
|
int first_obj)
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0; i < offsets.size(); ++i)
|
for (unsigned int i = 0; i < offsets.size(); ++i)
|
||||||
|
@ -1190,8 +1191,8 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object)
|
||||||
int old_id = object.getObjectID();
|
int old_id = object.getObjectID();
|
||||||
int new_id = obj_renumber[old_id];
|
int new_id = obj_renumber[old_id];
|
||||||
|
|
||||||
std::vector<int> offsets;
|
std::vector<off_t> offsets;
|
||||||
int first = 0;
|
off_t first = 0;
|
||||||
|
|
||||||
// Generate stream itself. We have to do this in two passes so we
|
// Generate stream itself. We have to do this in two passes so we
|
||||||
// can calculate offsets in the first pass.
|
// can calculate offsets in the first pass.
|
||||||
|
@ -1209,7 +1210,7 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object)
|
||||||
// Adjust offsets to skip over comment before first object
|
// Adjust offsets to skip over comment before first object
|
||||||
|
|
||||||
first = offsets[0];
|
first = offsets[0];
|
||||||
for (std::vector<int>::iterator iter = offsets.begin();
|
for (std::vector<off_t>::iterator iter = offsets.begin();
|
||||||
iter != offsets.end(); ++iter)
|
iter != offsets.end(); ++iter)
|
||||||
{
|
{
|
||||||
*iter -= first;
|
*iter -= first;
|
||||||
|
@ -1280,7 +1281,7 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object)
|
||||||
writeStringQDF("\n ");
|
writeStringQDF("\n ");
|
||||||
writeString(" /Type /ObjStm");
|
writeString(" /Type /ObjStm");
|
||||||
writeStringQDF("\n ");
|
writeStringQDF("\n ");
|
||||||
unsigned long length = stream_buffer->getSize();
|
size_t length = stream_buffer->getSize();
|
||||||
adjustAESStreamLength(length);
|
adjustAESStreamLength(length);
|
||||||
writeString(" /Length " + QUtil::int_to_string(length));
|
writeString(" /Length " + QUtil::int_to_string(length));
|
||||||
writeStringQDF("\n ");
|
writeStringQDF("\n ");
|
||||||
|
@ -1523,8 +1524,9 @@ QPDFWriter::generateObjectStreams()
|
||||||
// This code doesn't do anything with /Extends.
|
// This code doesn't do anything with /Extends.
|
||||||
|
|
||||||
std::vector<int> const& eligible = this->pdf.getCompressibleObjects();
|
std::vector<int> const& eligible = this->pdf.getCompressibleObjects();
|
||||||
unsigned int n_object_streams = (eligible.size() + 99) / 100;
|
unsigned int n_object_streams =
|
||||||
unsigned int n_per = eligible.size() / n_object_streams;
|
(unsigned int)((eligible.size() + 99) / 100);
|
||||||
|
unsigned int n_per = (unsigned int)(eligible.size() / n_object_streams);
|
||||||
if (n_per * n_object_streams < eligible.size())
|
if (n_per * n_object_streams < eligible.size())
|
||||||
{
|
{
|
||||||
++n_per;
|
++n_per;
|
||||||
|
@ -1777,7 +1779,7 @@ QPDFWriter::writeHintStream(int hint_id)
|
||||||
openObject(hint_id);
|
openObject(hint_id);
|
||||||
setDataKey(hint_id);
|
setDataKey(hint_id);
|
||||||
|
|
||||||
unsigned long hlen = hint_buffer->getSize();
|
size_t hlen = hint_buffer->getSize();
|
||||||
|
|
||||||
writeString("<< /Filter /FlateDecode /S ");
|
writeString("<< /Filter /FlateDecode /S ");
|
||||||
writeString(QUtil::int_to_string(S));
|
writeString(QUtil::int_to_string(S));
|
||||||
|
@ -1817,13 +1819,13 @@ QPDFWriter::writeXRefTable(trailer_e which, int first, int last, int size)
|
||||||
int
|
int
|
||||||
QPDFWriter::writeXRefTable(trailer_e which, int first, int last, int size,
|
QPDFWriter::writeXRefTable(trailer_e which, int first, int last, int size,
|
||||||
int prev, bool suppress_offsets,
|
int prev, bool suppress_offsets,
|
||||||
int hint_id, int hint_offset, int hint_length)
|
int hint_id, off_t hint_offset, off_t hint_length)
|
||||||
{
|
{
|
||||||
writeString("xref\n");
|
writeString("xref\n");
|
||||||
writeString(QUtil::int_to_string(first));
|
writeString(QUtil::int_to_string(first));
|
||||||
writeString(" ");
|
writeString(" ");
|
||||||
writeString(QUtil::int_to_string(last - first + 1));
|
writeString(QUtil::int_to_string(last - first + 1));
|
||||||
int space_before_zero = this->pipeline->getCount();
|
off_t space_before_zero = this->pipeline->getCount();
|
||||||
writeString("\n");
|
writeString("\n");
|
||||||
for (int i = first; i <= last; ++i)
|
for (int i = first; i <= last; ++i)
|
||||||
{
|
{
|
||||||
|
@ -1865,10 +1867,10 @@ int
|
||||||
QPDFWriter::writeXRefStream(int xref_id, int max_id, int max_offset,
|
QPDFWriter::writeXRefStream(int xref_id, int max_id, int max_offset,
|
||||||
trailer_e which, int first, int last, int size,
|
trailer_e which, int first, int last, int size,
|
||||||
int prev, int hint_id,
|
int prev, int hint_id,
|
||||||
int hint_offset, int hint_length,
|
off_t hint_offset, off_t hint_length,
|
||||||
bool skip_compression)
|
bool skip_compression)
|
||||||
{
|
{
|
||||||
int xref_offset = this->pipeline->getCount();
|
off_t xref_offset = this->pipeline->getCount();
|
||||||
int space_before_zero = xref_offset - 1;
|
int space_before_zero = xref_offset - 1;
|
||||||
|
|
||||||
// field 1 contains offsets and object stream identifiers
|
// field 1 contains offsets and object stream identifiers
|
||||||
|
@ -2021,7 +2023,8 @@ QPDFWriter::writeLinearized()
|
||||||
//
|
//
|
||||||
|
|
||||||
// Second half objects
|
// Second half objects
|
||||||
int second_half_uncompressed = part7.size() + part8.size() + part9.size();
|
int second_half_uncompressed =
|
||||||
|
(int)(part7.size() + part8.size() + part9.size());
|
||||||
int second_half_first_obj = 1;
|
int second_half_first_obj = 1;
|
||||||
int after_second_half = 1 + second_half_uncompressed;
|
int after_second_half = 1 + second_half_uncompressed;
|
||||||
this->next_objid = after_second_half;
|
this->next_objid = after_second_half;
|
||||||
|
@ -2077,13 +2080,13 @@ QPDFWriter::writeLinearized()
|
||||||
|
|
||||||
int part4_end_marker = part4.back().getObjectID();
|
int part4_end_marker = part4.back().getObjectID();
|
||||||
int part6_end_marker = part6.back().getObjectID();
|
int part6_end_marker = part6.back().getObjectID();
|
||||||
int space_before_zero = 0;
|
off_t space_before_zero = 0;
|
||||||
int file_size = 0;
|
off_t file_size = 0;
|
||||||
int part6_end_offset = 0;
|
off_t part6_end_offset = 0;
|
||||||
int first_half_max_obj_offset = 0;
|
off_t first_half_max_obj_offset = 0;
|
||||||
int second_xref_offset = 0;
|
off_t second_xref_offset = 0;
|
||||||
int first_xref_end = 0;
|
off_t first_xref_end = 0;
|
||||||
int second_xref_end = 0;
|
off_t second_xref_end = 0;
|
||||||
|
|
||||||
this->next_objid = part4_first_obj;
|
this->next_objid = part4_first_obj;
|
||||||
enqueuePart(part4);
|
enqueuePart(part4);
|
||||||
|
@ -2097,7 +2100,7 @@ QPDFWriter::writeLinearized()
|
||||||
enqueuePart(part9);
|
enqueuePart(part9);
|
||||||
assert(this->next_objid == after_second_half);
|
assert(this->next_objid == after_second_half);
|
||||||
|
|
||||||
int hint_length = 0;
|
off_t hint_length = 0;
|
||||||
PointerHolder<Buffer> hint_buffer;
|
PointerHolder<Buffer> hint_buffer;
|
||||||
|
|
||||||
// Write file in two passes. Part numbers refer to PDF spec 1.4.
|
// Write file in two passes. Part numbers refer to PDF spec 1.4.
|
||||||
|
@ -2118,14 +2121,14 @@ QPDFWriter::writeLinearized()
|
||||||
// space if all numerical values in the parameter dictionary
|
// space if all numerical values in the parameter dictionary
|
||||||
// are 10 digits long plus a few extra characters for safety.
|
// are 10 digits long plus a few extra characters for safety.
|
||||||
|
|
||||||
int pos = this->pipeline->getCount();
|
off_t pos = this->pipeline->getCount();
|
||||||
openObject(lindict_id);
|
openObject(lindict_id);
|
||||||
writeString("<<");
|
writeString("<<");
|
||||||
if (pass == 2)
|
if (pass == 2)
|
||||||
{
|
{
|
||||||
std::vector<QPDFObjectHandle> const& pages = pdf.getAllPages();
|
std::vector<QPDFObjectHandle> const& pages = pdf.getAllPages();
|
||||||
int first_page_object = obj_renumber[pages[0].getObjectID()];
|
int first_page_object = obj_renumber[pages[0].getObjectID()];
|
||||||
int npages = pages.size();
|
int npages = (int)pages.size();
|
||||||
|
|
||||||
writeString(" /Linearized 1 /L ");
|
writeString(" /Linearized 1 /L ");
|
||||||
writeString(QUtil::int_to_string(file_size + hint_length));
|
writeString(QUtil::int_to_string(file_size + hint_length));
|
||||||
|
@ -2147,15 +2150,15 @@ QPDFWriter::writeLinearized()
|
||||||
writeString(" >>");
|
writeString(" >>");
|
||||||
closeObject(lindict_id);
|
closeObject(lindict_id);
|
||||||
static int const pad = 150;
|
static int const pad = 150;
|
||||||
int spaces = (pos + pad - this->pipeline->getCount());
|
int spaces = (pos - this->pipeline->getCount() + pad);
|
||||||
assert(spaces >= 0);
|
assert(spaces >= 0);
|
||||||
writePad(spaces);
|
writePad(spaces);
|
||||||
writeString("\n");
|
writeString("\n");
|
||||||
|
|
||||||
// Part 3: first page cross reference table and trailer.
|
// Part 3: first page cross reference table and trailer.
|
||||||
|
|
||||||
int first_xref_offset = this->pipeline->getCount();
|
off_t first_xref_offset = this->pipeline->getCount();
|
||||||
int hint_offset = 0;
|
off_t hint_offset = 0;
|
||||||
if (pass == 2)
|
if (pass == 2)
|
||||||
{
|
{
|
||||||
hint_offset = this->xref[hint_id].getOffset();
|
hint_offset = this->xref[hint_id].getOffset();
|
||||||
|
@ -2183,7 +2186,7 @@ QPDFWriter::writeLinearized()
|
||||||
hint_length + second_xref_offset,
|
hint_length + second_xref_offset,
|
||||||
hint_id, hint_offset, hint_length,
|
hint_id, hint_offset, hint_length,
|
||||||
(pass == 1));
|
(pass == 1));
|
||||||
int endpos = this->pipeline->getCount();
|
off_t endpos = this->pipeline->getCount();
|
||||||
if (pass == 1)
|
if (pass == 1)
|
||||||
{
|
{
|
||||||
// Pad so we have enough room for the real xref
|
// Pad so we have enough room for the real xref
|
||||||
|
@ -2260,7 +2263,7 @@ QPDFWriter::writeLinearized()
|
||||||
t_lin_second, 0, second_half_end,
|
t_lin_second, 0, second_half_end,
|
||||||
second_trailer_size,
|
second_trailer_size,
|
||||||
0, 0, 0, 0, (pass == 1));
|
0, 0, 0, 0, (pass == 1));
|
||||||
int endpos = this->pipeline->getCount();
|
off_t endpos = this->pipeline->getCount();
|
||||||
|
|
||||||
if (pass == 1)
|
if (pass == 1)
|
||||||
{
|
{
|
||||||
|
@ -2274,14 +2277,14 @@ QPDFWriter::writeLinearized()
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Make the file size the same.
|
// Make the file size the same.
|
||||||
int pos = this->pipeline->getCount();
|
off_t pos = this->pipeline->getCount();
|
||||||
writePad(second_xref_end + hint_length - 1 - pos);
|
writePad(second_xref_end + hint_length - 1 - pos);
|
||||||
writeString("\n");
|
writeString("\n");
|
||||||
|
|
||||||
// If this assertion fails, maybe we didn't have
|
// If this assertion fails, maybe we didn't have
|
||||||
// enough padding above.
|
// enough padding above.
|
||||||
assert(this->pipeline->getCount() ==
|
assert(this->pipeline->getCount() ==
|
||||||
second_xref_end + hint_length);
|
(off_t)(second_xref_end + hint_length));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -2309,7 +2312,7 @@ QPDFWriter::writeLinearized()
|
||||||
activatePipelineStack();
|
activatePipelineStack();
|
||||||
writeHintStream(hint_id);
|
writeHintStream(hint_id);
|
||||||
popPipelineStack(&hint_buffer);
|
popPipelineStack(&hint_buffer);
|
||||||
hint_length = hint_buffer->getSize();
|
hint_length = (off_t)hint_buffer->getSize();
|
||||||
|
|
||||||
// Restore hint offset
|
// Restore hint offset
|
||||||
this->xref[hint_id] = QPDFXRefEntry(1, hint_offset, 0);
|
this->xref[hint_id] = QPDFXRefEntry(1, hint_offset, 0);
|
||||||
|
|
|
@ -9,7 +9,7 @@ QPDFXRefEntry::QPDFXRefEntry() :
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QPDFXRefEntry::QPDFXRefEntry(int type, int field1, int field2) :
|
QPDFXRefEntry::QPDFXRefEntry(int type, off_t field1, int field2) :
|
||||||
type(type),
|
type(type),
|
||||||
field1(field1),
|
field1(field1),
|
||||||
field2(field2)
|
field2(field2)
|
||||||
|
@ -27,7 +27,7 @@ QPDFXRefEntry::getType() const
|
||||||
return this->type;
|
return this->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
off_t
|
||||||
QPDFXRefEntry::getOffset() const
|
QPDFXRefEntry::getOffset() const
|
||||||
{
|
{
|
||||||
if (this->type != 1)
|
if (this->type != 1)
|
||||||
|
@ -46,7 +46,7 @@ QPDFXRefEntry::getObjStreamNumber() const
|
||||||
throw std::logic_error(
|
throw std::logic_error(
|
||||||
"getObjStreamNumber called for xref entry of type != 2");
|
"getObjStreamNumber called for xref entry of type != 2");
|
||||||
}
|
}
|
||||||
return this->field1;
|
return (int) this->field1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
|
@ -37,7 +37,7 @@ QPDF_Array::unparse()
|
||||||
int
|
int
|
||||||
QPDF_Array::getNItems() const
|
QPDF_Array::getNItems() const
|
||||||
{
|
{
|
||||||
return this->items.size();
|
return (int)this->items.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
QPDFObjectHandle
|
QPDFObjectHandle
|
||||||
|
|
|
@ -22,7 +22,7 @@ std::map<std::string, std::string> QPDF_Stream::filter_abbreviations;
|
||||||
|
|
||||||
QPDF_Stream::QPDF_Stream(QPDF* qpdf, int objid, int generation,
|
QPDF_Stream::QPDF_Stream(QPDF* qpdf, int objid, int generation,
|
||||||
QPDFObjectHandle stream_dict,
|
QPDFObjectHandle stream_dict,
|
||||||
off_t offset, int length) :
|
off_t offset, size_t length) :
|
||||||
qpdf(qpdf),
|
qpdf(qpdf),
|
||||||
objid(objid),
|
objid(objid),
|
||||||
generation(generation),
|
generation(generation),
|
||||||
|
@ -379,8 +379,8 @@ QPDF_Stream::pipeStreamData(Pipeline* pipeline, bool filter,
|
||||||
Pl_Count count("stream provider count", pipeline);
|
Pl_Count count("stream provider count", pipeline);
|
||||||
this->stream_provider->provideStreamData(
|
this->stream_provider->provideStreamData(
|
||||||
this->objid, this->generation, &count);
|
this->objid, this->generation, &count);
|
||||||
size_t actual_length = count.getCount();
|
off_t actual_length = count.getCount();
|
||||||
size_t desired_length =
|
off_t desired_length =
|
||||||
this->stream_dict.getKey("/Length").getIntValue();
|
this->stream_dict.getKey("/Length").getIntValue();
|
||||||
if (actual_length == desired_length)
|
if (actual_length == desired_length)
|
||||||
{
|
{
|
||||||
|
@ -446,5 +446,5 @@ QPDF_Stream::replaceFilterData(QPDFObjectHandle const& filter,
|
||||||
this->stream_dict.replaceOrRemoveKey("/Filter", filter);
|
this->stream_dict.replaceOrRemoveKey("/Filter", filter);
|
||||||
this->stream_dict.replaceOrRemoveKey("/DecodeParms", decode_parms);
|
this->stream_dict.replaceOrRemoveKey("/DecodeParms", decode_parms);
|
||||||
this->stream_dict.replaceKey("/Length",
|
this->stream_dict.replaceKey("/Length",
|
||||||
QPDFObjectHandle::newInteger(length));
|
QPDFObjectHandle::newInteger((int)length));
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,7 +157,7 @@ std::string
|
||||||
QPDF_String::getUTF8Val() const
|
QPDF_String::getUTF8Val() const
|
||||||
{
|
{
|
||||||
std::string result;
|
std::string result;
|
||||||
unsigned int len = this->val.length();
|
size_t len = this->val.length();
|
||||||
if ((len >= 2) && (len % 2 == 0) &&
|
if ((len >= 2) && (len % 2 == 0) &&
|
||||||
(this->val[0] == '\xfe') && (this->val[1] == '\xff'))
|
(this->val[0] == '\xfe') && (this->val[1] == '\xff'))
|
||||||
{
|
{
|
||||||
|
|
|
@ -29,7 +29,7 @@ static unsigned int const key_bytes = 32;
|
||||||
void
|
void
|
||||||
pad_or_truncate_password(std::string const& password, char k1[key_bytes])
|
pad_or_truncate_password(std::string const& password, char k1[key_bytes])
|
||||||
{
|
{
|
||||||
int password_bytes = std::min((size_t) key_bytes, password.length());
|
int password_bytes = std::min(key_bytes, (unsigned int)password.length());
|
||||||
int pad_bytes = key_bytes - password_bytes;
|
int pad_bytes = key_bytes - password_bytes;
|
||||||
memcpy(k1, password.c_str(), password_bytes);
|
memcpy(k1, password.c_str(), password_bytes);
|
||||||
memcpy(k1 + password_bytes, padding_string, pad_bytes);
|
memcpy(k1 + password_bytes, padding_string, pad_bytes);
|
||||||
|
@ -121,7 +121,7 @@ QPDF::compute_data_key(std::string const& encryption_key,
|
||||||
}
|
}
|
||||||
|
|
||||||
MD5 md5;
|
MD5 md5;
|
||||||
md5.encodeDataIncrementally(result.c_str(), result.length());
|
md5.encodeDataIncrementally(result.c_str(), (int)result.length());
|
||||||
MD5::Digest digest;
|
MD5::Digest digest;
|
||||||
md5.digest(digest);
|
md5.digest(digest);
|
||||||
return std::string((char*) digest,
|
return std::string((char*) digest,
|
||||||
|
@ -144,7 +144,7 @@ QPDF::compute_encryption_key(
|
||||||
pbytes[2] = (char) ((data.P >> 16) & 0xff);
|
pbytes[2] = (char) ((data.P >> 16) & 0xff);
|
||||||
pbytes[3] = (char) ((data.P >> 24) & 0xff);
|
pbytes[3] = (char) ((data.P >> 24) & 0xff);
|
||||||
md5.encodeDataIncrementally(pbytes, 4);
|
md5.encodeDataIncrementally(pbytes, 4);
|
||||||
md5.encodeDataIncrementally(data.id1.c_str(), data.id1.length());
|
md5.encodeDataIncrementally(data.id1.c_str(), (int)data.id1.length());
|
||||||
if ((data.R >= 4) && (! data.encrypt_metadata))
|
if ((data.R >= 4) && (! data.encrypt_metadata))
|
||||||
{
|
{
|
||||||
char bytes[4];
|
char bytes[4];
|
||||||
|
@ -218,7 +218,7 @@ compute_U_value_R3(std::string const& user_password,
|
||||||
MD5 md5;
|
MD5 md5;
|
||||||
md5.encodeDataIncrementally(
|
md5.encodeDataIncrementally(
|
||||||
pad_or_truncate_password("").c_str(), key_bytes);
|
pad_or_truncate_password("").c_str(), key_bytes);
|
||||||
md5.encodeDataIncrementally(data.id1.c_str(), data.id1.length());
|
md5.encodeDataIncrementally(data.id1.c_str(), (int)data.id1.length());
|
||||||
MD5::Digest digest;
|
MD5::Digest digest;
|
||||||
md5.digest(digest);
|
md5.digest(digest);
|
||||||
iterate_rc4(digest, sizeof(MD5::Digest),
|
iterate_rc4(digest, sizeof(MD5::Digest),
|
||||||
|
@ -583,16 +583,16 @@ QPDF::decryptString(std::string& str, int objid, int generation)
|
||||||
pl.write((unsigned char*)str.c_str(), str.length());
|
pl.write((unsigned char*)str.c_str(), str.length());
|
||||||
pl.finish();
|
pl.finish();
|
||||||
PointerHolder<Buffer> buf = bufpl.getBuffer();
|
PointerHolder<Buffer> buf = bufpl.getBuffer();
|
||||||
str = std::string((char*)buf->getBuffer(), (size_t)buf->getSize());
|
str = std::string((char*)buf->getBuffer(), buf->getSize());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QTC::TC("qpdf", "QPDF_encryption rc4 decode string");
|
QTC::TC("qpdf", "QPDF_encryption rc4 decode string");
|
||||||
unsigned int vlen = str.length();
|
unsigned int vlen = (int)str.length();
|
||||||
// Using PointerHolder guarantees that tmp will
|
// Using PointerHolder guarantees that tmp will
|
||||||
// be freed even if rc4.process throws an exception.
|
// be freed even if rc4.process throws an exception.
|
||||||
PointerHolder<char> tmp(true, QUtil::copy_string(str));
|
PointerHolder<char> tmp(true, QUtil::copy_string(str));
|
||||||
RC4 rc4((unsigned char const*)key.c_str(), key.length());
|
RC4 rc4((unsigned char const*)key.c_str(), (int)key.length());
|
||||||
rc4.process((unsigned char*)tmp.getPointer(), vlen);
|
rc4.process((unsigned char*)tmp.getPointer(), vlen);
|
||||||
str = std::string(tmp.getPointer(), vlen);
|
str = std::string(tmp.getPointer(), vlen);
|
||||||
}
|
}
|
||||||
|
@ -704,7 +704,7 @@ QPDF::decryptStream(Pipeline*& pipeline, int objid, int generation,
|
||||||
{
|
{
|
||||||
QTC::TC("qpdf", "QPDF_encryption rc4 decode stream");
|
QTC::TC("qpdf", "QPDF_encryption rc4 decode stream");
|
||||||
pipeline = new Pl_RC4("RC4 stream decryption", pipeline,
|
pipeline = new Pl_RC4("RC4 stream decryption", pipeline,
|
||||||
(unsigned char*) key.c_str(), key.length());
|
(unsigned char*) key.c_str(), (int)key.length());
|
||||||
}
|
}
|
||||||
heap.push_back(pipeline);
|
heap.push_back(pipeline);
|
||||||
}
|
}
|
||||||
|
|
|
@ -289,7 +289,7 @@ QPDF::readLinearizationData()
|
||||||
PointerHolder<Buffer> hbp = pb.getBuffer();
|
PointerHolder<Buffer> hbp = pb.getBuffer();
|
||||||
Buffer* hb = hbp.getPointer();
|
Buffer* hb = hbp.getPointer();
|
||||||
unsigned char const* h_buf = hb->getBuffer();
|
unsigned char const* h_buf = hb->getBuffer();
|
||||||
int h_size = hb->getSize();
|
int h_size = (int)hb->getSize();
|
||||||
|
|
||||||
readHPageOffset(BitStream(h_buf, h_size));
|
readHPageOffset(BitStream(h_buf, h_size));
|
||||||
|
|
||||||
|
@ -345,7 +345,7 @@ QPDF::readHintStream(Pipeline& pl, off_t offset, size_t length)
|
||||||
{
|
{
|
||||||
QTC::TC("qpdf", "QPDF hint table length direct");
|
QTC::TC("qpdf", "QPDF hint table length direct");
|
||||||
}
|
}
|
||||||
off_t computed_end = offset + length;
|
off_t computed_end = offset + (off_t)length;
|
||||||
if ((computed_end < min_end_offset) ||
|
if ((computed_end < min_end_offset) ||
|
||||||
(computed_end > max_end_offset))
|
(computed_end > max_end_offset))
|
||||||
{
|
{
|
||||||
|
@ -488,7 +488,7 @@ QPDF::checkLinearizationInternal()
|
||||||
}
|
}
|
||||||
|
|
||||||
// N: number of pages
|
// N: number of pages
|
||||||
int npages = pages.size();
|
int npages = (int)pages.size();
|
||||||
if (p.npages != npages)
|
if (p.npages != npages)
|
||||||
{
|
{
|
||||||
// Not tested in the test suite
|
// Not tested in the test suite
|
||||||
|
@ -736,7 +736,7 @@ QPDF::checkHPageOffset(std::list<std::string>& errors,
|
||||||
// under a page's /Resources dictionary in with shared objects
|
// under a page's /Resources dictionary in with shared objects
|
||||||
// even when they are private.
|
// even when they are private.
|
||||||
|
|
||||||
unsigned int npages = pages.size();
|
unsigned int npages = (unsigned int)pages.size();
|
||||||
int table_offset = adjusted_offset(
|
int table_offset = adjusted_offset(
|
||||||
this->page_offset_hints.first_page_offset);
|
this->page_offset_hints.first_page_offset);
|
||||||
ObjGen first_page_og(pages[0].getObjectID(), pages[0].getGeneration());
|
ObjGen first_page_og(pages[0].getObjectID(), pages[0].getGeneration());
|
||||||
|
@ -1425,7 +1425,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
|
||||||
pages.push_back(getUncompressedObject(*iter, object_stream_data));
|
pages.push_back(getUncompressedObject(*iter, object_stream_data));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unsigned int npages = pages.size();
|
unsigned int npages = (unsigned int)pages.size();
|
||||||
|
|
||||||
// We will be initializing some values of the computed hint
|
// We will be initializing some values of the computed hint
|
||||||
// tables. Specifically, we can initialize any items that deal
|
// tables. Specifically, we can initialize any items that deal
|
||||||
|
@ -1495,7 +1495,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
|
||||||
// in garbage values for all the shared object identifiers on the
|
// in garbage values for all the shared object identifiers on the
|
||||||
// first page.
|
// first page.
|
||||||
|
|
||||||
this->c_page_offset_data.entries[0].nobjects = this->part6.size();
|
this->c_page_offset_data.entries[0].nobjects = (int)this->part6.size();
|
||||||
|
|
||||||
// Part 7: other pages' private objects
|
// Part 7: other pages' private objects
|
||||||
|
|
||||||
|
@ -1646,9 +1646,11 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
|
||||||
|
|
||||||
// Make sure we got everything exactly once.
|
// Make sure we got everything exactly once.
|
||||||
|
|
||||||
unsigned int num_placed = this->part4.size() + this->part6.size() +
|
unsigned int num_placed =
|
||||||
this->part7.size() + this->part8.size() + this->part9.size();
|
(unsigned int)(this->part4.size() + this->part6.size() +
|
||||||
unsigned int num_wanted = this->object_to_obj_users.size();
|
this->part7.size() + this->part8.size() +
|
||||||
|
this->part9.size());
|
||||||
|
unsigned int num_wanted = (unsigned int)this->object_to_obj_users.size();
|
||||||
if (num_placed != num_wanted)
|
if (num_placed != num_wanted)
|
||||||
{
|
{
|
||||||
throw std::logic_error(
|
throw std::logic_error(
|
||||||
|
@ -1672,10 +1674,11 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
|
||||||
// can map from object number only without regards to generation.
|
// can map from object number only without regards to generation.
|
||||||
std::map<int, int> obj_to_index;
|
std::map<int, int> obj_to_index;
|
||||||
|
|
||||||
this->c_shared_object_data.nshared_first_page = this->part6.size();
|
this->c_shared_object_data.nshared_first_page =
|
||||||
|
(unsigned int)this->part6.size();
|
||||||
this->c_shared_object_data.nshared_total =
|
this->c_shared_object_data.nshared_total =
|
||||||
this->c_shared_object_data.nshared_first_page +
|
this->c_shared_object_data.nshared_first_page +
|
||||||
this->part8.size();
|
(unsigned int) this->part8.size();
|
||||||
|
|
||||||
std::vector<CHSharedObjectEntry>& shared =
|
std::vector<CHSharedObjectEntry>& shared =
|
||||||
this->c_shared_object_data.entries;
|
this->c_shared_object_data.entries;
|
||||||
|
@ -1684,7 +1687,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
|
||||||
{
|
{
|
||||||
QPDFObjectHandle& oh = *iter;
|
QPDFObjectHandle& oh = *iter;
|
||||||
int obj = oh.getObjectID();
|
int obj = oh.getObjectID();
|
||||||
obj_to_index[obj] = shared.size();
|
obj_to_index[obj] = (int)shared.size();
|
||||||
shared.push_back(CHSharedObjectEntry(obj));
|
shared.push_back(CHSharedObjectEntry(obj));
|
||||||
}
|
}
|
||||||
QTC::TC("qpdf", "QPDF lin part 8 empty", this->part8.empty() ? 1 : 0);
|
QTC::TC("qpdf", "QPDF lin part 8 empty", this->part8.empty() ? 1 : 0);
|
||||||
|
@ -1698,7 +1701,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
|
||||||
{
|
{
|
||||||
QPDFObjectHandle& oh = *iter;
|
QPDFObjectHandle& oh = *iter;
|
||||||
int obj = oh.getObjectID();
|
int obj = oh.getObjectID();
|
||||||
obj_to_index[obj] = shared.size();
|
obj_to_index[obj] = (int)shared.size();
|
||||||
shared.push_back(CHSharedObjectEntry(obj));
|
shared.push_back(CHSharedObjectEntry(obj));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1814,7 +1817,7 @@ QPDF::calculateHPageOffset(
|
||||||
// values.
|
// values.
|
||||||
|
|
||||||
std::vector<QPDFObjectHandle> const& pages = getAllPages();
|
std::vector<QPDFObjectHandle> const& pages = getAllPages();
|
||||||
unsigned int npages = pages.size();
|
unsigned int npages = (unsigned int)pages.size();
|
||||||
CHPageOffset& cph = this->c_page_offset_data;
|
CHPageOffset& cph = this->c_page_offset_data;
|
||||||
std::vector<CHPageOffsetEntry>& cphe = cph.entries;
|
std::vector<CHPageOffsetEntry>& cphe = cph.entries;
|
||||||
|
|
||||||
|
@ -2019,7 +2022,7 @@ QPDF::writeHPageOffset(BitWriter& w)
|
||||||
w.writeBits(t.nbits_shared_numerator, 16); // 12
|
w.writeBits(t.nbits_shared_numerator, 16); // 12
|
||||||
w.writeBits(t.shared_denominator, 16); // 13
|
w.writeBits(t.shared_denominator, 16); // 13
|
||||||
|
|
||||||
unsigned int nitems = getAllPages().size();
|
unsigned int nitems = (unsigned int)getAllPages().size();
|
||||||
std::vector<HPageOffsetEntry>& entries = t.entries;
|
std::vector<HPageOffsetEntry>& entries = t.entries;
|
||||||
|
|
||||||
write_vector_int(w, nitems, entries,
|
write_vector_int(w, nitems, entries,
|
||||||
|
@ -2110,12 +2113,12 @@ QPDF::generateHintStream(std::map<int, QPDFXRefEntry> const& xref,
|
||||||
BitWriter w(&c);
|
BitWriter w(&c);
|
||||||
|
|
||||||
writeHPageOffset(w);
|
writeHPageOffset(w);
|
||||||
S = c.getCount();
|
S = (int)c.getCount();
|
||||||
writeHSharedObject(w);
|
writeHSharedObject(w);
|
||||||
O = 0;
|
O = 0;
|
||||||
if (this->outline_hints.nobjects > 0)
|
if (this->outline_hints.nobjects > 0)
|
||||||
{
|
{
|
||||||
O = c.getCount();
|
O = (int)c.getCount();
|
||||||
writeHGeneric(w, this->outline_hints);
|
writeHGeneric(w, this->outline_hints);
|
||||||
}
|
}
|
||||||
c.finish();
|
c.finish();
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include <qpdf/QUtil.hh>
|
#include <qpdf/QUtil.hh>
|
||||||
|
#include <qpdf/qpdf-config.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
@ -14,7 +15,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
QUtil::int_to_string(int num, int fullpad)
|
QUtil::int_to_string(long long num, int fullpad)
|
||||||
{
|
{
|
||||||
// This routine will need to be recompiled if an int can be longer than
|
// This routine will need to be recompiled if an int can be longer than
|
||||||
// 49 digits.
|
// 49 digits.
|
||||||
|
@ -28,14 +29,20 @@ QUtil::int_to_string(int num, int fullpad)
|
||||||
"limit");
|
"limit");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_PRINTF_LL
|
||||||
|
# define PRINTF_LL "ll"
|
||||||
|
#else
|
||||||
|
# define PRINTF_LL "l"
|
||||||
|
#endif
|
||||||
if (fullpad)
|
if (fullpad)
|
||||||
{
|
{
|
||||||
sprintf(t, "%0*d", fullpad, num);
|
sprintf(t, "%0*" PRINTF_LL "d", fullpad, num);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sprintf(t, "%d", num);
|
sprintf(t, "%" PRINTF_LL "d", num);
|
||||||
}
|
}
|
||||||
|
#undef PRINTF_LL
|
||||||
|
|
||||||
return std::string(t);
|
return std::string(t);
|
||||||
}
|
}
|
||||||
|
@ -101,6 +108,26 @@ QUtil::fopen_wrapper(std::string const& description, FILE* f)
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
QUtil::fseek_off_t(FILE* stream, off_t offset, int whence)
|
||||||
|
{
|
||||||
|
#if HAVE_FSEEKO
|
||||||
|
return fseeko(stream, offset, whence);
|
||||||
|
#else
|
||||||
|
return fseek(stream, offset, whence);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
off_t
|
||||||
|
QUtil::ftell_off_t(FILE* stream)
|
||||||
|
{
|
||||||
|
#if HAVE_FSEEKO
|
||||||
|
return ftello(stream);
|
||||||
|
#else
|
||||||
|
return ftell(stream);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
char*
|
char*
|
||||||
QUtil::copy_string(std::string const& str)
|
QUtil::copy_string(std::string const& str)
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,7 +15,7 @@ RC4::RC4(unsigned char const* key_data, int key_len)
|
||||||
{
|
{
|
||||||
if (key_len == -1)
|
if (key_len == -1)
|
||||||
{
|
{
|
||||||
key_len = strlen((char*)key_data);
|
key_len = (int)strlen((char*)key_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 256; ++i)
|
for (int i = 0; i < 256; ++i)
|
||||||
|
|
|
@ -95,7 +95,7 @@ read_bits(unsigned char const*& p, unsigned int& bit_offset,
|
||||||
#ifdef BITS_WRITE
|
#ifdef BITS_WRITE
|
||||||
static void
|
static void
|
||||||
write_bits(unsigned char& ch, unsigned int& bit_offset,
|
write_bits(unsigned char& ch, unsigned int& bit_offset,
|
||||||
unsigned long val, unsigned bits, Pipeline* pipeline)
|
unsigned long val, unsigned int bits, Pipeline* pipeline)
|
||||||
{
|
{
|
||||||
if (bits > 32)
|
if (bits > 32)
|
||||||
{
|
{
|
||||||
|
|
|
@ -462,10 +462,10 @@ static void qpdf_get_buffer_internal(qpdf_data qpdf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long qpdf_get_buffer_length(qpdf_data qpdf)
|
size_t qpdf_get_buffer_length(qpdf_data qpdf)
|
||||||
{
|
{
|
||||||
qpdf_get_buffer_internal(qpdf);
|
qpdf_get_buffer_internal(qpdf);
|
||||||
unsigned long result = 0L;
|
size_t result = 0;
|
||||||
if (qpdf->output_buffer)
|
if (qpdf->output_buffer)
|
||||||
{
|
{
|
||||||
result = qpdf->output_buffer->getSize();
|
result = qpdf->output_buffer->getSize();
|
||||||
|
|
|
@ -15,7 +15,7 @@ class BitWriter
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
BitWriter(Pipeline* pl);
|
BitWriter(Pipeline* pl);
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
void writeBits(unsigned long val, int bits);
|
void writeBits(unsigned long val, unsigned int bits);
|
||||||
// Force any partial byte to be written to the pipeline.
|
// Force any partial byte to be written to the pipeline.
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
void flush();
|
void flush();
|
||||||
|
|
|
@ -22,7 +22,7 @@ class Pl_AES_PDF: public Pipeline
|
||||||
virtual ~Pl_AES_PDF();
|
virtual ~Pl_AES_PDF();
|
||||||
|
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
virtual void write(unsigned char* data, int len);
|
virtual void write(unsigned char* data, size_t len);
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
virtual void finish();
|
virtual void finish();
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ class Pl_AES_PDF: public Pipeline
|
||||||
bool encrypt;
|
bool encrypt;
|
||||||
bool cbc_mode;
|
bool cbc_mode;
|
||||||
bool first;
|
bool first;
|
||||||
unsigned int offset;
|
size_t offset; // offset into memory buffer
|
||||||
unsigned char key[key_size];
|
unsigned char key[key_size];
|
||||||
uint32_t rk[key_size + 28];
|
uint32_t rk[key_size + 28];
|
||||||
unsigned char inbuf[buf_size];
|
unsigned char inbuf[buf_size];
|
||||||
|
|
|
@ -11,7 +11,7 @@ class Pl_ASCII85Decoder: public Pipeline
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
virtual ~Pl_ASCII85Decoder();
|
virtual ~Pl_ASCII85Decoder();
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
virtual void write(unsigned char* buf, int len);
|
virtual void write(unsigned char* buf, size_t len);
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
virtual void finish();
|
virtual void finish();
|
||||||
|
|
||||||
|
@ -19,8 +19,8 @@ class Pl_ASCII85Decoder: public Pipeline
|
||||||
void flush();
|
void flush();
|
||||||
|
|
||||||
char inbuf[5];
|
char inbuf[5];
|
||||||
int pos;
|
size_t pos;
|
||||||
int eod;
|
size_t eod;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __PL_ASCII85DECODER_HH__
|
#endif // __PL_ASCII85DECODER_HH__
|
||||||
|
|
|
@ -11,7 +11,7 @@ class Pl_ASCIIHexDecoder: public Pipeline
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
virtual ~Pl_ASCIIHexDecoder();
|
virtual ~Pl_ASCIIHexDecoder();
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
virtual void write(unsigned char* buf, int len);
|
virtual void write(unsigned char* buf, size_t len);
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
virtual void finish();
|
virtual void finish();
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ class Pl_ASCIIHexDecoder: public Pipeline
|
||||||
void flush();
|
void flush();
|
||||||
|
|
||||||
char inbuf[3];
|
char inbuf[3];
|
||||||
int pos;
|
size_t pos;
|
||||||
bool eod;
|
bool eod;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ class Pl_LZWDecoder: public Pipeline
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
virtual ~Pl_LZWDecoder();
|
virtual ~Pl_LZWDecoder();
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
virtual void write(unsigned char* buf, int len);
|
virtual void write(unsigned char* buf, size_t len);
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
virtual void finish();
|
virtual void finish();
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ class Pl_MD5: public Pipeline
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
virtual ~Pl_MD5();
|
virtual ~Pl_MD5();
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
virtual void write(unsigned char*, int);
|
virtual void write(unsigned char*, size_t);
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
virtual void finish();
|
virtual void finish();
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
|
|
|
@ -30,7 +30,7 @@ class Pl_PNGFilter: public Pipeline
|
||||||
virtual ~Pl_PNGFilter();
|
virtual ~Pl_PNGFilter();
|
||||||
|
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
virtual void write(unsigned char* data, int len);
|
virtual void write(unsigned char* data, size_t len);
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
virtual void finish();
|
virtual void finish();
|
||||||
|
|
||||||
|
@ -45,8 +45,8 @@ class Pl_PNGFilter: public Pipeline
|
||||||
unsigned char* prev_row;
|
unsigned char* prev_row;
|
||||||
unsigned char* buf1;
|
unsigned char* buf1;
|
||||||
unsigned char* buf2;
|
unsigned char* buf2;
|
||||||
int pos;
|
size_t pos;
|
||||||
int incoming;
|
size_t incoming;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __PL_PNGFILTER_HH__
|
#endif // __PL_PNGFILTER_HH__
|
||||||
|
|
|
@ -18,13 +18,13 @@ class Pl_QPDFTokenizer: public Pipeline
|
||||||
public:
|
public:
|
||||||
Pl_QPDFTokenizer(char const* identifier, Pipeline* next);
|
Pl_QPDFTokenizer(char const* identifier, Pipeline* next);
|
||||||
virtual ~Pl_QPDFTokenizer();
|
virtual ~Pl_QPDFTokenizer();
|
||||||
virtual void write(unsigned char* buf, int len);
|
virtual void write(unsigned char* buf, size_t len);
|
||||||
virtual void finish();
|
virtual void finish();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void processChar(char ch);
|
void processChar(char ch);
|
||||||
void checkUnread();
|
void checkUnread();
|
||||||
void writeNext(char const*, int len);
|
void writeNext(char const*, size_t len);
|
||||||
void writeToken(QPDFTokenizer::Token&);
|
void writeToken(QPDFTokenizer::Token&);
|
||||||
|
|
||||||
QPDFTokenizer tokenizer;
|
QPDFTokenizer tokenizer;
|
||||||
|
|
|
@ -14,18 +14,18 @@ class Pl_RC4: public Pipeline
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
Pl_RC4(char const* identifier, Pipeline* next,
|
Pl_RC4(char const* identifier, Pipeline* next,
|
||||||
unsigned char const* key_data, int key_len = -1,
|
unsigned char const* key_data, int key_len = -1,
|
||||||
int out_bufsize = def_bufsize);
|
size_t out_bufsize = def_bufsize);
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
virtual ~Pl_RC4();
|
virtual ~Pl_RC4();
|
||||||
|
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
virtual void write(unsigned char* data, int len);
|
virtual void write(unsigned char* data, size_t len);
|
||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
virtual void finish();
|
virtual void finish();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned char* outbuf;
|
unsigned char* outbuf;
|
||||||
int out_bufsize;
|
size_t out_bufsize;
|
||||||
RC4 rc4;
|
RC4 rc4;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ class QPDF_Stream: public QPDFObject
|
||||||
public:
|
public:
|
||||||
QPDF_Stream(QPDF*, int objid, int generation,
|
QPDF_Stream(QPDF*, int objid, int generation,
|
||||||
QPDFObjectHandle stream_dict,
|
QPDFObjectHandle stream_dict,
|
||||||
off_t offset, int length);
|
off_t offset, size_t length);
|
||||||
virtual ~QPDF_Stream();
|
virtual ~QPDF_Stream();
|
||||||
virtual std::string unparse();
|
virtual std::string unparse();
|
||||||
QPDFObjectHandle getDict() const;
|
QPDFObjectHandle getDict() const;
|
||||||
|
@ -51,7 +51,7 @@ class QPDF_Stream: public QPDFObject
|
||||||
int generation;
|
int generation;
|
||||||
QPDFObjectHandle stream_dict;
|
QPDFObjectHandle stream_dict;
|
||||||
off_t offset;
|
off_t offset;
|
||||||
int length;
|
size_t length;
|
||||||
PointerHolder<Buffer> stream_data;
|
PointerHolder<Buffer> stream_data;
|
||||||
PointerHolder<QPDFObjectHandle::StreamDataProvider> stream_provider;
|
PointerHolder<QPDFObjectHandle::StreamDataProvider> stream_provider;
|
||||||
};
|
};
|
||||||
|
|
|
@ -46,7 +46,7 @@ int main(int argc, char* argv[])
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int hexkeylen = strlen(hexkey);
|
unsigned int hexkeylen = (unsigned int)strlen(hexkey);
|
||||||
unsigned int keylen = hexkeylen / 2;
|
unsigned int keylen = hexkeylen / 2;
|
||||||
if (keylen != Pl_AES_PDF::key_size)
|
if (keylen != Pl_AES_PDF::key_size)
|
||||||
{
|
{
|
||||||
|
@ -93,7 +93,7 @@ int main(int argc, char* argv[])
|
||||||
bool done = false;
|
bool done = false;
|
||||||
while (! done)
|
while (! done)
|
||||||
{
|
{
|
||||||
int len = fread(buf, 1, sizeof(buf), infile);
|
size_t len = fread(buf, 1, sizeof(buf), infile);
|
||||||
if (len <= 0)
|
if (len <= 0)
|
||||||
{
|
{
|
||||||
done = true;
|
done = true;
|
||||||
|
|
|
@ -15,7 +15,7 @@ int main()
|
||||||
bool done = false;
|
bool done = false;
|
||||||
while (! done)
|
while (! done)
|
||||||
{
|
{
|
||||||
int len = fread(buf, 1, sizeof(buf), stdin);
|
size_t len = fread(buf, 1, sizeof(buf), stdin);
|
||||||
if (len <= 0)
|
if (len <= 0)
|
||||||
{
|
{
|
||||||
done = true;
|
done = true;
|
||||||
|
|
|
@ -46,7 +46,7 @@ print_buffer(Pl_Buffer* bp)
|
||||||
bp->finish();
|
bp->finish();
|
||||||
Buffer* b = bp->getBuffer();
|
Buffer* b = bp->getBuffer();
|
||||||
unsigned char const* p = b->getBuffer();
|
unsigned char const* p = b->getBuffer();
|
||||||
unsigned long l = b->getSize();
|
size_t l = b->getSize();
|
||||||
for (unsigned long i = 0; i < l; ++i)
|
for (unsigned long i = 0; i < l; ++i)
|
||||||
{
|
{
|
||||||
printf("%02x%s", (unsigned int)(p[i]),
|
printf("%02x%s", (unsigned int)(p[i]),
|
||||||
|
|
|
@ -15,7 +15,7 @@ int main()
|
||||||
bool done = false;
|
bool done = false;
|
||||||
while (! done)
|
while (! done)
|
||||||
{
|
{
|
||||||
int len = fread(buf, 1, sizeof(buf), stdin);
|
size_t len = fread(buf, 1, sizeof(buf), stdin);
|
||||||
if (len <= 0)
|
if (len <= 0)
|
||||||
{
|
{
|
||||||
done = true;
|
done = true;
|
||||||
|
|
|
@ -38,7 +38,7 @@ int main(int argc, char* argv[])
|
||||||
bool done = false;
|
bool done = false;
|
||||||
while (! done)
|
while (! done)
|
||||||
{
|
{
|
||||||
int len = fread(buf, 1, sizeof(buf), infile);
|
size_t len = fread(buf, 1, sizeof(buf), infile);
|
||||||
if (len <= 0)
|
if (len <= 0)
|
||||||
{
|
{
|
||||||
done = true;
|
done = true;
|
||||||
|
|
|
@ -54,7 +54,7 @@ int main(int, char*[])
|
||||||
bool done = false;
|
bool done = false;
|
||||||
while (! done)
|
while (! done)
|
||||||
{
|
{
|
||||||
int len = fread(buf, 1, sizeof(buf), f);
|
size_t len = fread(buf, 1, sizeof(buf), f);
|
||||||
if (len <= 0)
|
if (len <= 0)
|
||||||
{
|
{
|
||||||
done = true;
|
done = true;
|
||||||
|
|
|
@ -17,8 +17,8 @@ int main(int argc, char* argv[])
|
||||||
char* hexkey = argv[1];
|
char* hexkey = argv[1];
|
||||||
char* infilename = argv[2];
|
char* infilename = argv[2];
|
||||||
char* outfilename = argv[3];
|
char* outfilename = argv[3];
|
||||||
int hexkeylen = strlen(hexkey);
|
unsigned int hexkeylen = (unsigned int)strlen(hexkey);
|
||||||
int keylen = hexkeylen / 2;
|
unsigned int keylen = hexkeylen / 2;
|
||||||
unsigned char* key = new unsigned char[keylen + 1];
|
unsigned char* key = new unsigned char[keylen + 1];
|
||||||
key[keylen] = '\0';
|
key[keylen] = '\0';
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ int main(int argc, char* argv[])
|
||||||
bool done = false;
|
bool done = false;
|
||||||
while (! done)
|
while (! done)
|
||||||
{
|
{
|
||||||
int len = fread(buf, 1, sizeof(buf), infile);
|
size_t len = fread(buf, 1, sizeof(buf), infile);
|
||||||
if (len <= 0)
|
if (len <= 0)
|
||||||
{
|
{
|
||||||
done = true;
|
done = true;
|
||||||
|
|
12
make/msvc.mk
12
make/msvc.mk
|
@ -19,6 +19,16 @@ endef
|
||||||
CFLAGS := $(filter-out -g,$(CFLAGS))
|
CFLAGS := $(filter-out -g,$(CFLAGS))
|
||||||
CXXFLAGS := $(filter-out -g,$(CXXFLAGS))
|
CXXFLAGS := $(filter-out -g,$(CXXFLAGS))
|
||||||
|
|
||||||
|
# /WX makes all warnings errors.
|
||||||
|
CFLAGS += /WX
|
||||||
|
CXXFLAGS += /WX
|
||||||
|
|
||||||
|
# /w14267 makes warning 4267 a level 1 warning. This warning reports
|
||||||
|
# potential issues between size_t, off_t, and non-compatible integer
|
||||||
|
# types.
|
||||||
|
CFLAGS += /w14267
|
||||||
|
CXXFLAGS += /w14267
|
||||||
|
|
||||||
clean::
|
clean::
|
||||||
$(RM) *.pdb
|
$(RM) *.pdb
|
||||||
|
|
||||||
|
@ -35,7 +45,7 @@ endef
|
||||||
# 1 2
|
# 1 2
|
||||||
# Usage: $(call c_compile,src,includes)
|
# Usage: $(call c_compile,src,includes)
|
||||||
define c_compile
|
define c_compile
|
||||||
cl /nologo /O2 /Zi /Gy /EHsc /MD $(CPPFLAGS) $(CXXFLAGS) \
|
cl /nologo /O2 /Zi /Gy /EHsc /MD $(CPPFLAGS) $(CFLAGS) \
|
||||||
$(foreach I,$(2),-I$(I)) \
|
$(foreach I,$(2),-I$(I)) \
|
||||||
/c $(1) /Fo$(call c_src_to_obj,$(1))
|
/c $(1) /Fo$(call c_src_to_obj,$(1))
|
||||||
endef
|
endef
|
||||||
|
|
|
@ -74,7 +74,7 @@ void runtest(int n, char const* filename)
|
||||||
FILE* f = QUtil::fopen_wrapper(std::string("open ") + filename,
|
FILE* f = QUtil::fopen_wrapper(std::string("open ") + filename,
|
||||||
fopen(filename, "rb"));
|
fopen(filename, "rb"));
|
||||||
fseek(f, 0, SEEK_END);
|
fseek(f, 0, SEEK_END);
|
||||||
size_t size = (size_t) ftell(f);
|
size_t size = (size_t) QUtil::ftell_off_t(f);
|
||||||
fseek(f, 0, SEEK_SET);
|
fseek(f, 0, SEEK_SET);
|
||||||
file_buf = PointerHolder<char>(true, new char[size]);
|
file_buf = PointerHolder<char>(true, new char[size]);
|
||||||
char* buf_p = file_buf.getPointer();
|
char* buf_p = file_buf.getPointer();
|
||||||
|
|
|
@ -70,7 +70,7 @@ int main(int argc, char* argv[])
|
||||||
bool done = false;
|
bool done = false;
|
||||||
while (! done)
|
while (! done)
|
||||||
{
|
{
|
||||||
int len = fread(buf, 1, sizeof(buf), stdin);
|
size_t len = fread(buf, 1, sizeof(buf), stdin);
|
||||||
if (len <= 0)
|
if (len <= 0)
|
||||||
{
|
{
|
||||||
done = true;
|
done = true;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user