2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-06-03 19:00:51 +00:00

Use qpdf_offset_t in place of off_t in public APIs.

off_t is used internally only when needed to talk to standard
libraries.  This requires that the "long long" type be supported by
the compiler.
This commit is contained in:
Jay Berkenbilt 2012-06-21 19:32:21 -04:00
parent c833295a39
commit 81e8752362
21 changed files with 153 additions and 136 deletions

View File

@ -1,5 +1,9 @@
2012-06-21 Jay Berkenbilt <ejb@ql.org> 2012-06-21 Jay Berkenbilt <ejb@ql.org>
* Instead of using off_t in the public APIs, use qpdf_offset_t
instead. This is defined as long long in qpdf/Types.h. If your
system doesn't support long long, you can redefine it.
* Add pkg-config files * Add pkg-config files
* QPDFObjectHandle: add shallowCopy() method * QPDFObjectHandle: add shallowCopy() method

View File

@ -11,6 +11,7 @@ AC_CONFIG_FILES([libqpdf.pc])
AC_CONFIG_HEADERS([libqpdf/qpdf/qpdf-config.h]) AC_CONFIG_HEADERS([libqpdf/qpdf/qpdf-config.h])
AC_PROG_CC AC_PROG_CC
AC_PROG_CC_C99
AC_PROG_CXX AC_PROG_CXX
AC_HEADER_STDC AC_HEADER_STDC
LT_INIT([win32-dll]) LT_INIT([win32-dll])

View File

@ -27,14 +27,14 @@ class Pl_Count: public Pipeline
virtual void finish(); virtual void finish();
// Returns the number of bytes written // Returns the number of bytes written
QPDF_DLL QPDF_DLL
off_t getCount() const; qpdf_offset_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:
off_t count; qpdf_offset_t count;
unsigned char last_char; unsigned char last_char;
}; };

View File

@ -394,7 +394,7 @@ class QPDF
friend class QPDF_Stream; friend class QPDF_Stream;
private: private:
static void pipeStreamData(QPDF* qpdf, int objid, int generation, static void pipeStreamData(QPDF* qpdf, int objid, int generation,
off_t offset, size_t length, qpdf_offset_t offset, size_t length,
QPDFObjectHandle dict, QPDFObjectHandle dict,
Pipeline* pipeline) Pipeline* pipeline)
{ {
@ -418,19 +418,19 @@ class QPDF
{ {
} }
void setLastOffset(off_t); void setLastOffset(qpdf_offset_t);
off_t getLastOffset() const; qpdf_offset_t getLastOffset() const;
std::string readLine(); std::string readLine();
virtual std::string const& getName() const = 0; virtual std::string const& getName() const = 0;
virtual off_t tell() = 0; virtual qpdf_offset_t tell() = 0;
virtual void seek(off_t offset, int whence) = 0; virtual void seek(qpdf_offset_t offset, int whence) = 0;
virtual void rewind() = 0; virtual void rewind() = 0;
virtual size_t read(char* buffer, size_t 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:
off_t last_offset; qpdf_offset_t last_offset;
}; };
class FileInputSource: public InputSource class FileInputSource: public InputSource
@ -441,8 +441,8 @@ class QPDF
void setFile(FILE* filep); void setFile(FILE* filep);
virtual ~FileInputSource(); virtual ~FileInputSource();
virtual std::string const& getName() const; virtual std::string const& getName() const;
virtual off_t tell(); virtual qpdf_offset_t tell();
virtual void seek(off_t offset, int whence); virtual void seek(qpdf_offset_t offset, int whence);
virtual void rewind(); virtual void rewind();
virtual size_t read(char* buffer, size_t length); virtual size_t read(char* buffer, size_t length);
virtual void unreadCh(char ch); virtual void unreadCh(char ch);
@ -465,8 +465,8 @@ class QPDF
bool own_memory = false); bool own_memory = false);
virtual ~BufferInputSource(); virtual ~BufferInputSource();
virtual std::string const& getName() const; virtual std::string const& getName() const;
virtual off_t tell(); virtual qpdf_offset_t tell();
virtual void seek(off_t offset, int whence); virtual void seek(qpdf_offset_t offset, int whence);
virtual void rewind(); virtual void rewind();
virtual size_t read(char* buffer, size_t length); virtual size_t read(char* buffer, size_t length);
virtual void unreadCh(char ch); virtual void unreadCh(char ch);
@ -475,7 +475,7 @@ class QPDF
bool own_memory; bool own_memory;
std::string description; std::string description;
Buffer* buf; Buffer* buf;
off_t cur_offset; qpdf_offset_t cur_offset;
}; };
class ObjGen class ObjGen
@ -498,8 +498,8 @@ class QPDF
{ {
} }
ObjCache(PointerHolder<QPDFObject> object, ObjCache(PointerHolder<QPDFObject> object,
off_t end_before_space, qpdf_offset_t end_before_space,
off_t end_after_space) : qpdf_offset_t end_after_space) :
object(object), object(object),
end_before_space(end_before_space), end_before_space(end_before_space),
end_after_space(end_after_space) end_after_space(end_after_space)
@ -507,18 +507,18 @@ class QPDF
} }
PointerHolder<QPDFObject> object; PointerHolder<QPDFObject> object;
off_t end_before_space; qpdf_offset_t end_before_space;
off_t end_after_space; qpdf_offset_t end_after_space;
}; };
void parse(char const* password); void parse(char const* password);
void warn(QPDFExc const& e); void warn(QPDFExc const& e);
void setTrailer(QPDFObjectHandle obj); void setTrailer(QPDFObjectHandle obj);
void read_xref(off_t offset); void read_xref(qpdf_offset_t offset);
void reconstruct_xref(QPDFExc& e); void reconstruct_xref(QPDFExc& e);
int read_xrefTable(off_t offset); int read_xrefTable(qpdf_offset_t offset);
int read_xrefStream(off_t offset); int read_xrefStream(qpdf_offset_t offset);
int processXRefStream(off_t offset, QPDFObjectHandle& xref_stream); int processXRefStream(qpdf_offset_t offset, QPDFObjectHandle& xref_stream);
void insertXrefEntry(int obj, int f0, int f1, int f2, void insertXrefEntry(int obj, int f0, int f1, int f2,
bool overwrite = false); bool overwrite = false);
void setLastObjectDescription(std::string const& description, void setLastObjectDescription(std::string const& description,
@ -532,12 +532,12 @@ class QPDF
bool in_array, bool in_dictionary); bool in_array, bool in_dictionary);
size_t recoverStreamLength( size_t recoverStreamLength(
PointerHolder<InputSource> input, int objid, int generation, PointerHolder<InputSource> input, int objid, int generation,
off_t stream_offset); qpdf_offset_t stream_offset);
QPDFTokenizer::Token readToken(PointerHolder<InputSource>); QPDFTokenizer::Token readToken(PointerHolder<InputSource>);
QPDFObjectHandle readObjectAtOffset( QPDFObjectHandle readObjectAtOffset(
bool attempt_recovery, bool attempt_recovery,
off_t offset, std::string const& description, qpdf_offset_t offset, std::string const& description,
int exp_objid, int exp_generation, int exp_objid, int exp_generation,
int& act_objid, int& act_generation); int& act_objid, int& act_generation);
PointerHolder<QPDFObject> resolve(int objid, int generation); PointerHolder<QPDFObject> resolve(int objid, int generation);
@ -545,7 +545,7 @@ class QPDF
// Calls finish() on the pipeline when done but does not delete it // Calls finish() on the pipeline when done but does not delete it
void pipeStreamData(int objid, int generation, void pipeStreamData(int objid, int generation,
off_t offset, size_t length, qpdf_offset_t offset, size_t length,
QPDFObjectHandle dict, QPDFObjectHandle dict,
Pipeline* pipeline); Pipeline* pipeline);
@ -832,7 +832,8 @@ class QPDF
void readLinearizationData(); void readLinearizationData();
bool checkLinearizationInternal(); bool checkLinearizationInternal();
void dumpLinearizationDataInternal(); void dumpLinearizationDataInternal();
QPDFObjectHandle readHintStream(Pipeline&, off_t offset, size_t length); QPDFObjectHandle readHintStream(
Pipeline&, qpdf_offset_t offset, size_t length);
void readHPageOffset(BitStream); void readHPageOffset(BitStream);
void readHSharedObject(BitStream); void readHSharedObject(BitStream);
void readHGeneric(BitStream, HGeneric&); void readHGeneric(BitStream, HGeneric&);

View File

@ -21,7 +21,7 @@ class QPDFExc: public std::runtime_error
QPDFExc(qpdf_error_code_e error_code, QPDFExc(qpdf_error_code_e error_code,
std::string const& filename, std::string const& filename,
std::string const& object, std::string const& object,
off_t offset, qpdf_offset_t offset,
std::string const& message); std::string const& message);
QPDF_DLL QPDF_DLL
virtual ~QPDFExc() throw (); virtual ~QPDFExc() throw ();
@ -43,20 +43,20 @@ class QPDFExc: public std::runtime_error
QPDF_DLL QPDF_DLL
std::string const& getObject() const; std::string const& getObject() const;
QPDF_DLL QPDF_DLL
off_t getFilePosition() const; qpdf_offset_t getFilePosition() const;
QPDF_DLL QPDF_DLL
std::string const& getMessageDetail() const; std::string const& getMessageDetail() const;
private: private:
static std::string createWhat(std::string const& filename, static std::string createWhat(std::string const& filename,
std::string const& object, std::string const& object,
off_t offset, qpdf_offset_t offset,
std::string const& message); std::string const& message);
qpdf_error_code_e error_code; qpdf_error_code_e error_code;
std::string filename; std::string filename;
std::string object; std::string object;
off_t offset; qpdf_offset_t offset;
std::string message; std::string message;
}; };

View File

@ -347,7 +347,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, size_t length) QPDFObjectHandle stream_dict, qpdf_offset_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);
@ -395,7 +395,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, size_t length); QPDFObjectHandle stream_dict, qpdf_offset_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);

View File

@ -221,7 +221,8 @@ 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<off_t>& offsets, int first_obj); void writeObjectStreamOffsets(
std::vector<qpdf_offset_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,
@ -268,8 +269,8 @@ class QPDFWriter
int prev, int prev,
bool suppress_offsets, bool suppress_offsets,
int hint_id, int hint_id,
off_t hint_offset, qpdf_offset_t hint_offset,
off_t hint_length); qpdf_offset_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,
@ -277,8 +278,8 @@ class QPDFWriter
// for linearization // for linearization
int prev, int prev,
int hint_id, int hint_id,
off_t hint_offset, qpdf_offset_t hint_offset,
off_t hint_length, qpdf_offset_t hint_length,
bool skip_compression); bool skip_compression);
int calculateXrefStreamPadding(int xref_bytes); int calculateXrefStreamPadding(int xref_bytes);

View File

@ -23,12 +23,12 @@ class QPDFXRefEntry
QPDF_DLL QPDF_DLL
QPDFXRefEntry(); QPDFXRefEntry();
QPDF_DLL QPDF_DLL
QPDFXRefEntry(int type, off_t field1, int field2); QPDFXRefEntry(int type, qpdf_offset_t field1, int field2);
QPDF_DLL QPDF_DLL
int getType() const; int getType() const;
QPDF_DLL QPDF_DLL
off_t getOffset() const; // only for type 1 qpdf_offset_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;
off_t field1; qpdf_offset_t field1;
int field2; int field2;
}; };

View File

@ -10,7 +10,6 @@
#include <qpdf/DLL.h> #include <qpdf/DLL.h>
#include <qpdf/Types.h> #include <qpdf/Types.h>
#include <string> #include <string>
#include <list> #include <list>
#include <stdexcept> #include <stdexcept>
@ -26,6 +25,9 @@ namespace QUtil
QPDF_DLL QPDF_DLL
std::string double_to_string(double, int decimal_places = 0); std::string double_to_string(double, int decimal_places = 0);
QPDF_DLL
long long string_to_ll(char const* str);
// Throw std::runtime_error with a string formed by appending to // Throw std::runtime_error with a string formed by appending to
// "description: " the standard string corresponding to the // "description: " the standard string corresponding to the
// current value of errno. // current value of errno.
@ -48,9 +50,9 @@ namespace QUtil
// Wrap around off_t versions of fseek and ftell if available // Wrap around off_t versions of fseek and ftell if available
QPDF_DLL QPDF_DLL
int fseek_off_t(FILE* stream, off_t offset, int whence); int fseek_off_t(FILE* stream, qpdf_offset_t offset, int whence);
QPDF_DLL QPDF_DLL
off_t ftell_off_t(FILE* stream); qpdf_offset_t ftell_off_t(FILE* stream);
QPDF_DLL QPDF_DLL
char* copy_string(std::string const&); char* copy_string(std::string const&);

View File

@ -1,20 +1,11 @@
#ifndef __QPDFTYPES_H__ #ifndef __QPDFTYPES_H__
#define __QPDFTYPES_H__ #define __QPDFTYPES_H__
/* This file must be included before any system files. It should be /* Provide an offset type that should be as big as off_t on just about
* included right after <qpdf/DLL.h> within the library. * any system. If your compiler doesn't support C99 (or at least the
* "long long" type), then you may have to modify this definition.
*/ */
/* Attempt to provide off_t and size_t on any recent platform. To typedef long long int qpdf_offset_t;
* make cross compilation easier and to be more portable across
* platforms, QPDF avoids having any public header files use the
* results of autoconf testing, so we have to handle this ourselves in
* a static way.
*/
#define _FILE_OFFSET_BITS 64
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#endif /* __QPDFTYPES_H__ */ #endif /* __QPDFTYPES_H__ */

View File

@ -72,6 +72,7 @@
#include <qpdf/DLL.h> #include <qpdf/DLL.h>
#include <qpdf/Types.h> #include <qpdf/Types.h>
#include <qpdf/Constants.h> #include <qpdf/Constants.h>
#include <string.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

View File

@ -28,7 +28,7 @@ Pl_Count::finish()
getNext()->finish(); getNext()->finish();
} }
off_t qpdf_offset_t
Pl_Count::getCount() const Pl_Count::getCount() const
{ {
return this->count; return this->count;

View File

@ -18,12 +18,12 @@
std::string QPDF::qpdf_version = "2.3.1"; std::string QPDF::qpdf_version = "2.3.1";
void void
QPDF::InputSource::setLastOffset(off_t offset) QPDF::InputSource::setLastOffset(qpdf_offset_t offset)
{ {
this->last_offset = offset; this->last_offset = offset;
} }
off_t qpdf_offset_t
QPDF::InputSource::getLastOffset() const QPDF::InputSource::getLastOffset() const
{ {
return this->last_offset; return this->last_offset;
@ -36,7 +36,7 @@ QPDF::InputSource::readLine()
// without caring what the exact terminator is. Consume the // without caring what the exact terminator is. Consume the
// trailing newline characters but don't return them. // trailing newline characters but don't return them.
off_t offset = this->tell(); qpdf_offset_t offset = this->tell();
std::string buf; std::string buf;
enum { st_before_nl, st_at_nl } state = st_before_nl; enum { st_before_nl, st_at_nl } state = st_before_nl;
char ch; char ch;
@ -126,14 +126,14 @@ QPDF::FileInputSource::getName() const
return this->filename; return this->filename;
} }
off_t qpdf_offset_t
QPDF::FileInputSource::tell() QPDF::FileInputSource::tell()
{ {
return QUtil::ftell_off_t(this->file); return QUtil::ftell_off_t(this->file);
} }
void void
QPDF::FileInputSource::seek(off_t offset, int whence) QPDF::FileInputSource::seek(qpdf_offset_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) + " (" +
@ -193,14 +193,14 @@ QPDF::BufferInputSource::getName() const
return this->description; return this->description;
} }
off_t qpdf_offset_t
QPDF::BufferInputSource::tell() QPDF::BufferInputSource::tell()
{ {
return this->cur_offset; return this->cur_offset;
} }
void void
QPDF::BufferInputSource::seek(off_t offset, int whence) QPDF::BufferInputSource::seek(qpdf_offset_t offset, int whence)
{ {
switch (whence) switch (whence)
{ {
@ -209,7 +209,7 @@ QPDF::BufferInputSource::seek(off_t offset, int whence)
break; break;
case SEEK_END: case SEEK_END:
this->cur_offset = (off_t)this->buf->getSize() + offset; this->cur_offset = (qpdf_offset_t)this->buf->getSize() + offset;
break; break;
case SEEK_CUR: case SEEK_CUR:
@ -232,7 +232,7 @@ QPDF::BufferInputSource::rewind()
size_t size_t
QPDF::BufferInputSource::read(char* buffer, size_t length) QPDF::BufferInputSource::read(char* buffer, size_t length)
{ {
off_t end_pos = (off_t) this->buf->getSize(); qpdf_offset_t end_pos = (qpdf_offset_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;
@ -453,7 +453,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 = atol(m2.getMatch(1).c_str()); qpdf_offset_t xref_offset = QUtil::string_to_ll(m2.getMatch(1).c_str());
read_xref(xref_offset); read_xref(xref_offset);
} }
catch (QPDFExc& e) catch (QPDFExc& e)
@ -524,7 +524,7 @@ QPDF::reconstruct_xref(QPDFExc& e)
} }
this->file->seek(0, SEEK_END); this->file->seek(0, SEEK_END);
off_t eof = this->file->tell(); qpdf_offset_t eof = this->file->tell();
this->file->seek(0, SEEK_SET); this->file->seek(0, SEEK_SET);
bool in_obj = false; bool in_obj = false;
while (this->file->tell() < eof) while (this->file->tell() < eof)
@ -591,7 +591,7 @@ QPDF::reconstruct_xref(QPDFExc& e)
} }
void void
QPDF::read_xref(off_t xref_offset) QPDF::read_xref(qpdf_offset_t xref_offset)
{ {
std::map<int, int> free_table; std::map<int, int> free_table;
while (xref_offset) while (xref_offset)
@ -634,7 +634,7 @@ QPDF::read_xref(off_t xref_offset)
} }
int int
QPDF::read_xrefTable(off_t xref_offset) QPDF::read_xrefTable(qpdf_offset_t xref_offset)
{ {
PCRE xref_first_re("^\\s*(\\d+)\\s+(\\d+)"); PCRE xref_first_re("^\\s*(\\d+)\\s+(\\d+)");
PCRE xref_entry_re("(?s:(^\\d{10}) (\\d{5}) ([fn])[ \r\n]{2}$)"); PCRE xref_entry_re("(?s:(^\\d{10}) (\\d{5}) ([fn])[ \r\n]{2}$)");
@ -692,7 +692,7 @@ QPDF::read_xrefTable(off_t xref_offset)
insertXrefEntry(i, 1, f1, f2); insertXrefEntry(i, 1, f1, f2);
} }
} }
off_t pos = this->file->tell(); qpdf_offset_t pos = this->file->tell();
QPDFTokenizer::Token t = readToken(this->file); QPDFTokenizer::Token t = readToken(this->file);
if (t == QPDFTokenizer::Token(QPDFTokenizer::tt_word, "trailer")) if (t == QPDFTokenizer::Token(QPDFTokenizer::tt_word, "trailer"))
{ {
@ -791,7 +791,7 @@ QPDF::read_xrefTable(off_t xref_offset)
} }
int int
QPDF::read_xrefStream(off_t xref_offset) QPDF::read_xrefStream(qpdf_offset_t xref_offset)
{ {
bool found = false; bool found = false;
if (! this->ignore_xref_streams) if (! this->ignore_xref_streams)
@ -830,7 +830,7 @@ QPDF::read_xrefStream(off_t xref_offset)
} }
int int
QPDF::processXRefStream(off_t xref_offset, QPDFObjectHandle& xref_obj) QPDF::processXRefStream(qpdf_offset_t xref_offset, QPDFObjectHandle& xref_obj)
{ {
QPDFObjectHandle dict = xref_obj.getDict(); QPDFObjectHandle dict = xref_obj.getDict();
QPDFObjectHandle W_obj = dict.getKey("/W"); QPDFObjectHandle W_obj = dict.getKey("/W");
@ -1123,7 +1123,7 @@ QPDF::readObject(PointerHolder<InputSource> input,
int objid, int generation, bool in_object_stream) int objid, int generation, bool in_object_stream)
{ {
setLastObjectDescription(description, objid, generation); setLastObjectDescription(description, objid, generation);
off_t offset = input->tell(); qpdf_offset_t offset = input->tell();
QPDFObjectHandle object = readObjectInternal( QPDFObjectHandle object = readObjectInternal(
input, objid, generation, in_object_stream, false, false); input, objid, generation, in_object_stream, false, false);
// Override last_offset so that it points to the beginning of the // Override last_offset so that it points to the beginning of the
@ -1149,7 +1149,7 @@ QPDF::readObjectInternal(PointerHolder<InputSource> input,
QPDFObjectHandle object; QPDFObjectHandle object;
off_t offset = input->tell(); qpdf_offset_t offset = input->tell();
std::vector<QPDFObjectHandle> olist; std::vector<QPDFObjectHandle> olist;
bool done = false; bool done = false;
while (! done) while (! done)
@ -1347,7 +1347,7 @@ QPDF::readObjectInternal(PointerHolder<InputSource> input,
if (! in_object_stream) if (! in_object_stream)
{ {
// check for stream // check for stream
off_t cur_offset = input->tell(); qpdf_offset_t cur_offset = input->tell();
if (readToken(input) == if (readToken(input) ==
QPDFTokenizer::Token(QPDFTokenizer::tt_word, "stream")) QPDFTokenizer::Token(QPDFTokenizer::tt_word, "stream"))
{ {
@ -1416,7 +1416,7 @@ QPDF::readObjectInternal(PointerHolder<InputSource> input,
// Must get offset before accessing any additional // Must get offset before accessing any additional
// 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(); qpdf_offset_t stream_offset = input->tell();
size_t length = 0; size_t length = 0;
try try
@ -1440,7 +1440,8 @@ QPDF::readObjectInternal(PointerHolder<InputSource> input,
} }
length = length_obj.getIntValue(); length = length_obj.getIntValue();
input->seek(stream_offset + (off_t)length, SEEK_SET); input->seek(
stream_offset + (qpdf_offset_t)length, SEEK_SET);
if (! (readToken(input) == if (! (readToken(input) ==
QPDFTokenizer::Token( QPDFTokenizer::Token(
QPDFTokenizer::tt_word, "endstream"))) QPDFTokenizer::tt_word, "endstream")))
@ -1480,7 +1481,8 @@ QPDF::readObjectInternal(PointerHolder<InputSource> input,
size_t size_t
QPDF::recoverStreamLength(PointerHolder<InputSource> input, QPDF::recoverStreamLength(PointerHolder<InputSource> input,
int objid, int generation, off_t stream_offset) int objid, int generation,
qpdf_offset_t stream_offset)
{ {
PCRE endobj_re("^\\s*endobj\\b"); PCRE endobj_re("^\\s*endobj\\b");
@ -1491,10 +1493,10 @@ QPDF::recoverStreamLength(PointerHolder<InputSource> input,
"attempting to recover stream length")); "attempting to recover stream length"));
input->seek(0, SEEK_END); input->seek(0, SEEK_END);
off_t eof = input->tell(); qpdf_offset_t eof = input->tell();
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; qpdf_offset_t last_line_offset = 0;
size_t length = 0; size_t length = 0;
while (input->tell() < eof) while (input->tell() < eof)
{ {
@ -1568,7 +1570,7 @@ QPDF::recoverStreamLength(PointerHolder<InputSource> input,
QPDFTokenizer::Token QPDFTokenizer::Token
QPDF::readToken(PointerHolder<InputSource> input) QPDF::readToken(PointerHolder<InputSource> input)
{ {
off_t offset = input->tell(); qpdf_offset_t offset = input->tell();
QPDFTokenizer::Token token; QPDFTokenizer::Token token;
bool unread_char; bool unread_char;
char char_to_unread; char char_to_unread;
@ -1611,7 +1613,7 @@ QPDF::readToken(PointerHolder<InputSource> input)
QPDFObjectHandle QPDFObjectHandle
QPDF::readObjectAtOffset(bool try_recovery, QPDF::readObjectAtOffset(bool try_recovery,
off_t offset, std::string const& description, qpdf_offset_t offset, std::string const& description,
int exp_objid, int exp_generation, int exp_objid, int exp_generation,
int& objid, int& generation) int& objid, int& generation)
{ {
@ -1663,7 +1665,7 @@ QPDF::readObjectAtOffset(bool try_recovery,
if (this->xref_table.count(og) && if (this->xref_table.count(og) &&
(this->xref_table[og].getType() == 1)) (this->xref_table[og].getType() == 1))
{ {
off_t new_offset = this->xref_table[og].getOffset(); qpdf_offset_t new_offset = this->xref_table[og].getOffset();
QPDFObjectHandle result = readObjectAtOffset( QPDFObjectHandle result = readObjectAtOffset(
false, new_offset, description, false, new_offset, description,
exp_objid, exp_generation, objid, generation); exp_objid, exp_generation, objid, generation);
@ -1717,7 +1719,7 @@ QPDF::readObjectAtOffset(bool try_recovery,
// linearization hint tables. Offsets and lengths of objects // linearization hint tables. Offsets and lengths of objects
// may imply the end of an object to be anywhere between these // may imply the end of an object to be anywhere between these
// values. // values.
off_t end_before_space = this->file->tell(); qpdf_offset_t end_before_space = this->file->tell();
// skip over spaces // skip over spaces
while (true) while (true)
@ -1738,7 +1740,7 @@ QPDF::readObjectAtOffset(bool try_recovery,
"EOF after endobj"); "EOF after endobj");
} }
} }
off_t end_after_space = this->file->tell(); qpdf_offset_t end_after_space = this->file->tell();
this->obj_cache[og] = this->obj_cache[og] =
ObjCache(QPDFObjectHandle::ObjAccessor::getObject(oh), ObjCache(QPDFObjectHandle::ObjAccessor::getObject(oh),
@ -1768,7 +1770,7 @@ QPDF::resolve(int objid, int generation)
{ {
case 1: case 1:
{ {
off_t offset = entry.getOffset(); qpdf_offset_t offset = entry.getOffset();
// Object stored in cache by readObjectAtOffset // Object stored in cache by readObjectAtOffset
int aobjid; int aobjid;
int ageneration; int ageneration;
@ -1812,8 +1814,10 @@ QPDF::resolveObjectsInStream(int obj_stream_number)
// For linearization data in the object, use the data from the // For linearization data in the object, use the data from the
// object stream for the objects in the stream. // object stream for the objects in the stream.
ObjGen stream_og(obj_stream_number, 0); ObjGen stream_og(obj_stream_number, 0);
off_t end_before_space = this->obj_cache[stream_og].end_before_space; qpdf_offset_t end_before_space =
off_t end_after_space = this->obj_cache[stream_og].end_after_space; this->obj_cache[stream_og].end_before_space;
qpdf_offset_t end_after_space =
this->obj_cache[stream_og].end_after_space;
QPDFObjectHandle dict = obj_stream.getDict(); QPDFObjectHandle dict = obj_stream.getDict();
if (! (dict.getKey("/Type").isName() && if (! (dict.getKey("/Type").isName() &&
@ -2102,7 +2106,7 @@ QPDF::getCompressibleObjects()
void void
QPDF::pipeStreamData(int objid, int generation, QPDF::pipeStreamData(int objid, int generation,
off_t offset, size_t length, qpdf_offset_t offset, size_t length,
QPDFObjectHandle stream_dict, QPDFObjectHandle stream_dict,
Pipeline* pipeline) Pipeline* pipeline)
{ {

View File

@ -4,7 +4,7 @@
QPDFExc::QPDFExc(qpdf_error_code_e error_code, QPDFExc::QPDFExc(qpdf_error_code_e error_code,
std::string const& filename, std::string const& filename,
std::string const& object, std::string const& object,
off_t offset, qpdf_offset_t offset,
std::string const& message) : std::string const& message) :
std::runtime_error(createWhat(filename, object, offset, message)), std::runtime_error(createWhat(filename, object, offset, message)),
error_code(error_code), error_code(error_code),
@ -22,7 +22,7 @@ QPDFExc::~QPDFExc() throw ()
std::string std::string
QPDFExc::createWhat(std::string const& filename, QPDFExc::createWhat(std::string const& filename,
std::string const& object, std::string const& object,
off_t offset, qpdf_offset_t offset,
std::string const& message) std::string const& message)
{ {
std::string result; std::string result;
@ -73,7 +73,7 @@ QPDFExc::getObject() const
return this->object; return this->object;
} }
off_t qpdf_offset_t
QPDFExc::getFilePosition() const QPDFExc::getFilePosition() const
{ {
return this->offset; return this->offset;

View File

@ -632,7 +632,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, size_t length) qpdf_offset_t offset, size_t length)
{ {
return QPDFObjectHandle(new QPDF_Stream( return QPDFObjectHandle(new QPDF_Stream(
qpdf, objid, generation, qpdf, objid, generation,

View File

@ -879,7 +879,7 @@ 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 ");
off_t pos = this->pipeline->getCount(); qpdf_offset_t pos = this->pipeline->getCount();
writeString(QUtil::int_to_string(prev)); writeString(QUtil::int_to_string(prev));
int nspaces = (int)(pos - this->pipeline->getCount() + 11); int nspaces = (int)(pos - this->pipeline->getCount() + 11);
assert(nspaces >= 0); assert(nspaces >= 0);
@ -1165,7 +1165,7 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level,
} }
void void
QPDFWriter::writeObjectStreamOffsets(std::vector<off_t>& offsets, QPDFWriter::writeObjectStreamOffsets(std::vector<qpdf_offset_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)
@ -1191,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<off_t> offsets; std::vector<qpdf_offset_t> offsets;
off_t first = 0; qpdf_offset_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.
@ -1210,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<off_t>::iterator iter = offsets.begin(); for (std::vector<qpdf_offset_t>::iterator iter = offsets.begin();
iter != offsets.end(); ++iter) iter != offsets.end(); ++iter)
{ {
*iter -= first; *iter -= first;
@ -1820,13 +1820,14 @@ 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, off_t hint_offset, off_t hint_length) int hint_id, qpdf_offset_t hint_offset,
qpdf_offset_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));
off_t space_before_zero = this->pipeline->getCount(); qpdf_offset_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)
{ {
@ -1868,10 +1869,11 @@ 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,
off_t hint_offset, off_t hint_length, qpdf_offset_t hint_offset,
qpdf_offset_t hint_length,
bool skip_compression) bool skip_compression)
{ {
off_t xref_offset = this->pipeline->getCount(); qpdf_offset_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
@ -2081,13 +2083,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();
off_t space_before_zero = 0; qpdf_offset_t space_before_zero = 0;
off_t file_size = 0; qpdf_offset_t file_size = 0;
off_t part6_end_offset = 0; qpdf_offset_t part6_end_offset = 0;
off_t first_half_max_obj_offset = 0; qpdf_offset_t first_half_max_obj_offset = 0;
off_t second_xref_offset = 0; qpdf_offset_t second_xref_offset = 0;
off_t first_xref_end = 0; qpdf_offset_t first_xref_end = 0;
off_t second_xref_end = 0; qpdf_offset_t second_xref_end = 0;
this->next_objid = part4_first_obj; this->next_objid = part4_first_obj;
enqueuePart(part4); enqueuePart(part4);
@ -2101,7 +2103,7 @@ QPDFWriter::writeLinearized()
enqueuePart(part9); enqueuePart(part9);
assert(this->next_objid == after_second_half); assert(this->next_objid == after_second_half);
off_t hint_length = 0; qpdf_offset_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.
@ -2122,7 +2124,7 @@ 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.
off_t pos = this->pipeline->getCount(); qpdf_offset_t pos = this->pipeline->getCount();
openObject(lindict_id); openObject(lindict_id);
writeString("<<"); writeString("<<");
if (pass == 2) if (pass == 2)
@ -2158,8 +2160,8 @@ QPDFWriter::writeLinearized()
// Part 3: first page cross reference table and trailer. // Part 3: first page cross reference table and trailer.
off_t first_xref_offset = this->pipeline->getCount(); qpdf_offset_t first_xref_offset = this->pipeline->getCount();
off_t hint_offset = 0; qpdf_offset_t hint_offset = 0;
if (pass == 2) if (pass == 2)
{ {
hint_offset = this->xref[hint_id].getOffset(); hint_offset = this->xref[hint_id].getOffset();
@ -2187,7 +2189,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));
off_t endpos = this->pipeline->getCount(); qpdf_offset_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
@ -2264,7 +2266,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));
off_t endpos = this->pipeline->getCount(); qpdf_offset_t endpos = this->pipeline->getCount();
if (pass == 1) if (pass == 1)
{ {
@ -2278,14 +2280,14 @@ QPDFWriter::writeLinearized()
else else
{ {
// Make the file size the same. // Make the file size the same.
off_t pos = this->pipeline->getCount(); qpdf_offset_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() ==
(off_t)(second_xref_end + hint_length)); (qpdf_offset_t)(second_xref_end + hint_length));
} }
} }
else else
@ -2313,7 +2315,7 @@ QPDFWriter::writeLinearized()
activatePipelineStack(); activatePipelineStack();
writeHintStream(hint_id); writeHintStream(hint_id);
popPipelineStack(&hint_buffer); popPipelineStack(&hint_buffer);
hint_length = (off_t)hint_buffer->getSize(); hint_length = (qpdf_offset_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);
@ -2358,7 +2360,7 @@ QPDFWriter::writeStandard()
} }
// Now write out xref. next_objid is now the number of objects. // Now write out xref. next_objid is now the number of objects.
off_t xref_offset = this->pipeline->getCount(); qpdf_offset_t xref_offset = this->pipeline->getCount();
if (this->object_stream_to_objects.empty()) if (this->object_stream_to_objects.empty())
{ {
// Write regular cross-reference table // Write regular cross-reference table

View File

@ -9,7 +9,7 @@ QPDFXRefEntry::QPDFXRefEntry() :
{ {
} }
QPDFXRefEntry::QPDFXRefEntry(int type, off_t field1, int field2) : QPDFXRefEntry::QPDFXRefEntry(int type, qpdf_offset_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;
} }
off_t qpdf_offset_t
QPDFXRefEntry::getOffset() const QPDFXRefEntry::getOffset() const
{ {
if (this->type != 1) if (this->type != 1)

View File

@ -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, size_t length) : qpdf_offset_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);
off_t actual_length = count.getCount(); qpdf_offset_t actual_length = count.getCount();
off_t desired_length = qpdf_offset_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)
{ {

View File

@ -305,15 +305,15 @@ QPDF::readLinearizationData()
} }
QPDFObjectHandle QPDFObjectHandle
QPDF::readHintStream(Pipeline& pl, off_t offset, size_t length) QPDF::readHintStream(Pipeline& pl, qpdf_offset_t offset, size_t length)
{ {
int obj; int obj;
int gen; int gen;
QPDFObjectHandle H = readObjectAtOffset( QPDFObjectHandle H = readObjectAtOffset(
false, offset, "linearization hint stream", -1, 0, obj, gen); false, offset, "linearization hint stream", -1, 0, obj, gen);
ObjCache& oc = this->obj_cache[ObjGen(obj, gen)]; ObjCache& oc = this->obj_cache[ObjGen(obj, gen)];
off_t min_end_offset = oc.end_before_space; qpdf_offset_t min_end_offset = oc.end_before_space;
off_t max_end_offset = oc.end_after_space; qpdf_offset_t max_end_offset = oc.end_after_space;
if (! H.isStream()) if (! H.isStream())
{ {
throw QPDFExc(qpdf_e_damaged_pdf, this->file->getName(), throw QPDFExc(qpdf_e_damaged_pdf, this->file->getName(),
@ -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 + (off_t)length; qpdf_offset_t computed_end = offset + (qpdf_offset_t)length;
if ((computed_end < min_end_offset) || if ((computed_end < min_end_offset) ||
(computed_end > max_end_offset)) (computed_end > max_end_offset))
{ {

View File

@ -82,6 +82,16 @@ QUtil::double_to_string(double num, int decimal_places)
return std::string(t); return std::string(t);
} }
long long
QUtil::string_to_ll(char const* str)
{
#ifdef _MSC_VER
return _strtoi64(str, 0, 10);
#else
return strtoll(str, 0, 10);
#endif
}
void void
QUtil::throw_system_error(std::string const& description) QUtil::throw_system_error(std::string const& description)
{ {
@ -109,22 +119,22 @@ QUtil::fopen_wrapper(std::string const& description, FILE* f)
} }
int int
QUtil::fseek_off_t(FILE* stream, off_t offset, int whence) QUtil::fseek_off_t(FILE* stream, qpdf_offset_t offset, int whence)
{ {
#if HAVE_FSEEKO #if HAVE_FSEEKO
return fseeko(stream, offset, whence); return fseeko(stream, (off_t)offset, whence);
#else #else
return fseek(stream, offset, whence); return fseek(stream, (long)offset, whence);
#endif #endif
} }
off_t qpdf_offset_t
QUtil::ftell_off_t(FILE* stream) QUtil::ftell_off_t(FILE* stream)
{ {
#if HAVE_FSEEKO #if HAVE_FSEEKO
return ftello(stream); return (qpdf_offset_t)ftello(stream);
#else #else
return ftell(stream); return (qpdf_offset_t)ftell(stream);
#endif #endif
} }

View File

@ -14,7 +14,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, size_t length); qpdf_offset_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 objid; int objid;
int generation; int generation;
QPDFObjectHandle stream_dict; QPDFObjectHandle stream_dict;
off_t offset; qpdf_offset_t offset;
size_t length; size_t length;
PointerHolder<Buffer> stream_data; PointerHolder<Buffer> stream_data;
PointerHolder<QPDFObjectHandle::StreamDataProvider> stream_provider; PointerHolder<QPDFObjectHandle::StreamDataProvider> stream_provider;