mirror of
https://github.com/qpdf/qpdf.git
synced 2025-01-02 22:50:20 +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:
parent
c833295a39
commit
81e8752362
@ -1,5 +1,9 @@
|
||||
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
|
||||
|
||||
* QPDFObjectHandle: add shallowCopy() method
|
||||
|
@ -11,6 +11,7 @@ AC_CONFIG_FILES([libqpdf.pc])
|
||||
AC_CONFIG_HEADERS([libqpdf/qpdf/qpdf-config.h])
|
||||
|
||||
AC_PROG_CC
|
||||
AC_PROG_CC_C99
|
||||
AC_PROG_CXX
|
||||
AC_HEADER_STDC
|
||||
LT_INIT([win32-dll])
|
||||
|
@ -27,14 +27,14 @@ class Pl_Count: public Pipeline
|
||||
virtual void finish();
|
||||
// Returns the number of bytes written
|
||||
QPDF_DLL
|
||||
off_t getCount() const;
|
||||
qpdf_offset_t getCount() const;
|
||||
// Returns the last character written, or '\0' if no characters
|
||||
// have been written (in which case getCount() returns 0)
|
||||
QPDF_DLL
|
||||
unsigned char getLastChar() const;
|
||||
|
||||
private:
|
||||
off_t count;
|
||||
qpdf_offset_t count;
|
||||
unsigned char last_char;
|
||||
};
|
||||
|
||||
|
@ -394,7 +394,7 @@ class QPDF
|
||||
friend class QPDF_Stream;
|
||||
private:
|
||||
static void pipeStreamData(QPDF* qpdf, int objid, int generation,
|
||||
off_t offset, size_t length,
|
||||
qpdf_offset_t offset, size_t length,
|
||||
QPDFObjectHandle dict,
|
||||
Pipeline* pipeline)
|
||||
{
|
||||
@ -418,19 +418,19 @@ class QPDF
|
||||
{
|
||||
}
|
||||
|
||||
void setLastOffset(off_t);
|
||||
off_t getLastOffset() const;
|
||||
void setLastOffset(qpdf_offset_t);
|
||||
qpdf_offset_t getLastOffset() const;
|
||||
std::string readLine();
|
||||
|
||||
virtual std::string const& getName() const = 0;
|
||||
virtual off_t tell() = 0;
|
||||
virtual void seek(off_t offset, int whence) = 0;
|
||||
virtual qpdf_offset_t tell() = 0;
|
||||
virtual void seek(qpdf_offset_t offset, int whence) = 0;
|
||||
virtual void rewind() = 0;
|
||||
virtual size_t read(char* buffer, size_t length) = 0;
|
||||
virtual void unreadCh(char ch) = 0;
|
||||
|
||||
protected:
|
||||
off_t last_offset;
|
||||
qpdf_offset_t last_offset;
|
||||
};
|
||||
|
||||
class FileInputSource: public InputSource
|
||||
@ -441,8 +441,8 @@ class QPDF
|
||||
void setFile(FILE* filep);
|
||||
virtual ~FileInputSource();
|
||||
virtual std::string const& getName() const;
|
||||
virtual off_t tell();
|
||||
virtual void seek(off_t offset, int whence);
|
||||
virtual qpdf_offset_t tell();
|
||||
virtual void seek(qpdf_offset_t offset, int whence);
|
||||
virtual void rewind();
|
||||
virtual size_t read(char* buffer, size_t length);
|
||||
virtual void unreadCh(char ch);
|
||||
@ -465,8 +465,8 @@ class QPDF
|
||||
bool own_memory = false);
|
||||
virtual ~BufferInputSource();
|
||||
virtual std::string const& getName() const;
|
||||
virtual off_t tell();
|
||||
virtual void seek(off_t offset, int whence);
|
||||
virtual qpdf_offset_t tell();
|
||||
virtual void seek(qpdf_offset_t offset, int whence);
|
||||
virtual void rewind();
|
||||
virtual size_t read(char* buffer, size_t length);
|
||||
virtual void unreadCh(char ch);
|
||||
@ -475,7 +475,7 @@ class QPDF
|
||||
bool own_memory;
|
||||
std::string description;
|
||||
Buffer* buf;
|
||||
off_t cur_offset;
|
||||
qpdf_offset_t cur_offset;
|
||||
};
|
||||
|
||||
class ObjGen
|
||||
@ -498,8 +498,8 @@ class QPDF
|
||||
{
|
||||
}
|
||||
ObjCache(PointerHolder<QPDFObject> object,
|
||||
off_t end_before_space,
|
||||
off_t end_after_space) :
|
||||
qpdf_offset_t end_before_space,
|
||||
qpdf_offset_t end_after_space) :
|
||||
object(object),
|
||||
end_before_space(end_before_space),
|
||||
end_after_space(end_after_space)
|
||||
@ -507,18 +507,18 @@ class QPDF
|
||||
}
|
||||
|
||||
PointerHolder<QPDFObject> object;
|
||||
off_t end_before_space;
|
||||
off_t end_after_space;
|
||||
qpdf_offset_t end_before_space;
|
||||
qpdf_offset_t end_after_space;
|
||||
};
|
||||
|
||||
void parse(char const* password);
|
||||
void warn(QPDFExc const& e);
|
||||
void setTrailer(QPDFObjectHandle obj);
|
||||
void read_xref(off_t offset);
|
||||
void read_xref(qpdf_offset_t offset);
|
||||
void reconstruct_xref(QPDFExc& e);
|
||||
int read_xrefTable(off_t offset);
|
||||
int read_xrefStream(off_t offset);
|
||||
int processXRefStream(off_t offset, QPDFObjectHandle& xref_stream);
|
||||
int read_xrefTable(qpdf_offset_t offset);
|
||||
int read_xrefStream(qpdf_offset_t offset);
|
||||
int processXRefStream(qpdf_offset_t offset, QPDFObjectHandle& xref_stream);
|
||||
void insertXrefEntry(int obj, int f0, int f1, int f2,
|
||||
bool overwrite = false);
|
||||
void setLastObjectDescription(std::string const& description,
|
||||
@ -532,12 +532,12 @@ class QPDF
|
||||
bool in_array, bool in_dictionary);
|
||||
size_t recoverStreamLength(
|
||||
PointerHolder<InputSource> input, int objid, int generation,
|
||||
off_t stream_offset);
|
||||
qpdf_offset_t stream_offset);
|
||||
QPDFTokenizer::Token readToken(PointerHolder<InputSource>);
|
||||
|
||||
QPDFObjectHandle readObjectAtOffset(
|
||||
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& act_objid, int& act_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
|
||||
void pipeStreamData(int objid, int generation,
|
||||
off_t offset, size_t length,
|
||||
qpdf_offset_t offset, size_t length,
|
||||
QPDFObjectHandle dict,
|
||||
Pipeline* pipeline);
|
||||
|
||||
@ -832,7 +832,8 @@ class QPDF
|
||||
void readLinearizationData();
|
||||
bool checkLinearizationInternal();
|
||||
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 readHSharedObject(BitStream);
|
||||
void readHGeneric(BitStream, HGeneric&);
|
||||
|
@ -21,7 +21,7 @@ class QPDFExc: public std::runtime_error
|
||||
QPDFExc(qpdf_error_code_e error_code,
|
||||
std::string const& filename,
|
||||
std::string const& object,
|
||||
off_t offset,
|
||||
qpdf_offset_t offset,
|
||||
std::string const& message);
|
||||
QPDF_DLL
|
||||
virtual ~QPDFExc() throw ();
|
||||
@ -43,20 +43,20 @@ class QPDFExc: public std::runtime_error
|
||||
QPDF_DLL
|
||||
std::string const& getObject() const;
|
||||
QPDF_DLL
|
||||
off_t getFilePosition() const;
|
||||
qpdf_offset_t getFilePosition() const;
|
||||
QPDF_DLL
|
||||
std::string const& getMessageDetail() const;
|
||||
|
||||
private:
|
||||
static std::string createWhat(std::string const& filename,
|
||||
std::string const& object,
|
||||
off_t offset,
|
||||
qpdf_offset_t offset,
|
||||
std::string const& message);
|
||||
|
||||
qpdf_error_code_e error_code;
|
||||
std::string filename;
|
||||
std::string object;
|
||||
off_t offset;
|
||||
qpdf_offset_t offset;
|
||||
std::string message;
|
||||
};
|
||||
|
||||
|
@ -347,7 +347,7 @@ class QPDFObjectHandle
|
||||
// object must be dictionary object
|
||||
static QPDFObjectHandle newStream(
|
||||
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(
|
||||
qpdf, objid, generation, stream_dict, offset, length);
|
||||
@ -395,7 +395,7 @@ class QPDFObjectHandle
|
||||
static QPDFObjectHandle newIndirect(QPDF*, int objid, int generation);
|
||||
static QPDFObjectHandle newStream(
|
||||
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 assertType(char const* type_name, bool istype);
|
||||
|
@ -221,7 +221,8 @@ class QPDFWriter
|
||||
void writePad(int nspaces);
|
||||
void assignCompressedObjectNumbers(int objid);
|
||||
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 writeObject(QPDFObjectHandle object, int object_stream_index = -1);
|
||||
void writeTrailer(trailer_e which, int size,
|
||||
@ -268,8 +269,8 @@ class QPDFWriter
|
||||
int prev,
|
||||
bool suppress_offsets,
|
||||
int hint_id,
|
||||
off_t hint_offset,
|
||||
off_t hint_length);
|
||||
qpdf_offset_t hint_offset,
|
||||
qpdf_offset_t hint_length);
|
||||
int writeXRefStream(int objid, int max_id, int max_offset,
|
||||
trailer_e which, int first, int last, int size);
|
||||
int writeXRefStream(int objid, int max_id, int max_offset,
|
||||
@ -277,8 +278,8 @@ class QPDFWriter
|
||||
// for linearization
|
||||
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);
|
||||
int calculateXrefStreamPadding(int xref_bytes);
|
||||
|
||||
|
@ -23,12 +23,12 @@ class QPDFXRefEntry
|
||||
QPDF_DLL
|
||||
QPDFXRefEntry();
|
||||
QPDF_DLL
|
||||
QPDFXRefEntry(int type, off_t field1, int field2);
|
||||
QPDFXRefEntry(int type, qpdf_offset_t field1, int field2);
|
||||
|
||||
QPDF_DLL
|
||||
int getType() const;
|
||||
QPDF_DLL
|
||||
off_t getOffset() const; // only for type 1
|
||||
qpdf_offset_t getOffset() const; // only for type 1
|
||||
QPDF_DLL
|
||||
int getObjStreamNumber() const; // only for type 2
|
||||
QPDF_DLL
|
||||
@ -36,7 +36,7 @@ class QPDFXRefEntry
|
||||
|
||||
private:
|
||||
int type;
|
||||
off_t field1;
|
||||
qpdf_offset_t field1;
|
||||
int field2;
|
||||
};
|
||||
|
||||
|
@ -10,7 +10,6 @@
|
||||
|
||||
#include <qpdf/DLL.h>
|
||||
#include <qpdf/Types.h>
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <stdexcept>
|
||||
@ -26,6 +25,9 @@ namespace QUtil
|
||||
QPDF_DLL
|
||||
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
|
||||
// "description: " the standard string corresponding to the
|
||||
// current value of errno.
|
||||
@ -48,9 +50,9 @@ namespace QUtil
|
||||
|
||||
// Wrap around off_t versions of fseek and ftell if available
|
||||
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
|
||||
off_t ftell_off_t(FILE* stream);
|
||||
qpdf_offset_t ftell_off_t(FILE* stream);
|
||||
|
||||
QPDF_DLL
|
||||
char* copy_string(std::string const&);
|
||||
|
@ -1,20 +1,11 @@
|
||||
#ifndef __QPDFTYPES_H__
|
||||
#define __QPDFTYPES_H__
|
||||
|
||||
/* This file must be included before any system files. It should be
|
||||
* included right after <qpdf/DLL.h> within the library.
|
||||
/* Provide an offset type that should be as big as off_t on just about
|
||||
* 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
|
||||
* 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>
|
||||
typedef long long int qpdf_offset_t;
|
||||
|
||||
#endif /* __QPDFTYPES_H__ */
|
||||
|
@ -72,6 +72,7 @@
|
||||
#include <qpdf/DLL.h>
|
||||
#include <qpdf/Types.h>
|
||||
#include <qpdf/Constants.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -28,7 +28,7 @@ Pl_Count::finish()
|
||||
getNext()->finish();
|
||||
}
|
||||
|
||||
off_t
|
||||
qpdf_offset_t
|
||||
Pl_Count::getCount() const
|
||||
{
|
||||
return this->count;
|
||||
|
@ -18,12 +18,12 @@
|
||||
std::string QPDF::qpdf_version = "2.3.1";
|
||||
|
||||
void
|
||||
QPDF::InputSource::setLastOffset(off_t offset)
|
||||
QPDF::InputSource::setLastOffset(qpdf_offset_t offset)
|
||||
{
|
||||
this->last_offset = offset;
|
||||
}
|
||||
|
||||
off_t
|
||||
qpdf_offset_t
|
||||
QPDF::InputSource::getLastOffset() const
|
||||
{
|
||||
return this->last_offset;
|
||||
@ -36,7 +36,7 @@ QPDF::InputSource::readLine()
|
||||
// without caring what the exact terminator is. Consume the
|
||||
// trailing newline characters but don't return them.
|
||||
|
||||
off_t offset = this->tell();
|
||||
qpdf_offset_t offset = this->tell();
|
||||
std::string buf;
|
||||
enum { st_before_nl, st_at_nl } state = st_before_nl;
|
||||
char ch;
|
||||
@ -126,14 +126,14 @@ QPDF::FileInputSource::getName() const
|
||||
return this->filename;
|
||||
}
|
||||
|
||||
off_t
|
||||
qpdf_offset_t
|
||||
QPDF::FileInputSource::tell()
|
||||
{
|
||||
return QUtil::ftell_off_t(this->file);
|
||||
}
|
||||
|
||||
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::int_to_string(offset) + " (" +
|
||||
@ -193,14 +193,14 @@ QPDF::BufferInputSource::getName() const
|
||||
return this->description;
|
||||
}
|
||||
|
||||
off_t
|
||||
qpdf_offset_t
|
||||
QPDF::BufferInputSource::tell()
|
||||
{
|
||||
return this->cur_offset;
|
||||
}
|
||||
|
||||
void
|
||||
QPDF::BufferInputSource::seek(off_t offset, int whence)
|
||||
QPDF::BufferInputSource::seek(qpdf_offset_t offset, int whence)
|
||||
{
|
||||
switch (whence)
|
||||
{
|
||||
@ -209,7 +209,7 @@ QPDF::BufferInputSource::seek(off_t offset, int whence)
|
||||
break;
|
||||
|
||||
case SEEK_END:
|
||||
this->cur_offset = (off_t)this->buf->getSize() + offset;
|
||||
this->cur_offset = (qpdf_offset_t)this->buf->getSize() + offset;
|
||||
break;
|
||||
|
||||
case SEEK_CUR:
|
||||
@ -232,7 +232,7 @@ QPDF::BufferInputSource::rewind()
|
||||
size_t
|
||||
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)
|
||||
{
|
||||
this->last_offset = end_pos;
|
||||
@ -453,7 +453,7 @@ QPDF::parse(char const* password)
|
||||
throw QPDFExc(qpdf_e_damaged_pdf, this->file->getName(), "", 0,
|
||||
"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);
|
||||
}
|
||||
catch (QPDFExc& e)
|
||||
@ -524,7 +524,7 @@ QPDF::reconstruct_xref(QPDFExc& e)
|
||||
}
|
||||
|
||||
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);
|
||||
bool in_obj = false;
|
||||
while (this->file->tell() < eof)
|
||||
@ -591,7 +591,7 @@ QPDF::reconstruct_xref(QPDFExc& e)
|
||||
}
|
||||
|
||||
void
|
||||
QPDF::read_xref(off_t xref_offset)
|
||||
QPDF::read_xref(qpdf_offset_t xref_offset)
|
||||
{
|
||||
std::map<int, int> free_table;
|
||||
while (xref_offset)
|
||||
@ -634,7 +634,7 @@ QPDF::read_xref(off_t xref_offset)
|
||||
}
|
||||
|
||||
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_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);
|
||||
}
|
||||
}
|
||||
off_t pos = this->file->tell();
|
||||
qpdf_offset_t pos = this->file->tell();
|
||||
QPDFTokenizer::Token t = readToken(this->file);
|
||||
if (t == QPDFTokenizer::Token(QPDFTokenizer::tt_word, "trailer"))
|
||||
{
|
||||
@ -791,7 +791,7 @@ QPDF::read_xrefTable(off_t xref_offset)
|
||||
}
|
||||
|
||||
int
|
||||
QPDF::read_xrefStream(off_t xref_offset)
|
||||
QPDF::read_xrefStream(qpdf_offset_t xref_offset)
|
||||
{
|
||||
bool found = false;
|
||||
if (! this->ignore_xref_streams)
|
||||
@ -830,7 +830,7 @@ QPDF::read_xrefStream(off_t xref_offset)
|
||||
}
|
||||
|
||||
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 W_obj = dict.getKey("/W");
|
||||
@ -1123,7 +1123,7 @@ QPDF::readObject(PointerHolder<InputSource> input,
|
||||
int objid, int generation, bool in_object_stream)
|
||||
{
|
||||
setLastObjectDescription(description, objid, generation);
|
||||
off_t offset = input->tell();
|
||||
qpdf_offset_t offset = input->tell();
|
||||
QPDFObjectHandle object = readObjectInternal(
|
||||
input, objid, generation, in_object_stream, false, false);
|
||||
// Override last_offset so that it points to the beginning of the
|
||||
@ -1149,7 +1149,7 @@ QPDF::readObjectInternal(PointerHolder<InputSource> input,
|
||||
|
||||
QPDFObjectHandle object;
|
||||
|
||||
off_t offset = input->tell();
|
||||
qpdf_offset_t offset = input->tell();
|
||||
std::vector<QPDFObjectHandle> olist;
|
||||
bool done = false;
|
||||
while (! done)
|
||||
@ -1347,7 +1347,7 @@ QPDF::readObjectInternal(PointerHolder<InputSource> input,
|
||||
if (! in_object_stream)
|
||||
{
|
||||
// check for stream
|
||||
off_t cur_offset = input->tell();
|
||||
qpdf_offset_t cur_offset = input->tell();
|
||||
if (readToken(input) ==
|
||||
QPDFTokenizer::Token(QPDFTokenizer::tt_word, "stream"))
|
||||
{
|
||||
@ -1416,7 +1416,7 @@ QPDF::readObjectInternal(PointerHolder<InputSource> input,
|
||||
// Must get offset before accessing any additional
|
||||
// objects since resolving a previously unresolved
|
||||
// indirect object will change file position.
|
||||
off_t stream_offset = input->tell();
|
||||
qpdf_offset_t stream_offset = input->tell();
|
||||
size_t length = 0;
|
||||
|
||||
try
|
||||
@ -1440,7 +1440,8 @@ QPDF::readObjectInternal(PointerHolder<InputSource> input,
|
||||
}
|
||||
|
||||
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) ==
|
||||
QPDFTokenizer::Token(
|
||||
QPDFTokenizer::tt_word, "endstream")))
|
||||
@ -1480,7 +1481,8 @@ QPDF::readObjectInternal(PointerHolder<InputSource> input,
|
||||
|
||||
size_t
|
||||
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");
|
||||
|
||||
@ -1491,10 +1493,10 @@ QPDF::recoverStreamLength(PointerHolder<InputSource> input,
|
||||
"attempting to recover stream length"));
|
||||
|
||||
input->seek(0, SEEK_END);
|
||||
off_t eof = input->tell();
|
||||
qpdf_offset_t eof = input->tell();
|
||||
input->seek(stream_offset, SEEK_SET);
|
||||
std::string last_line;
|
||||
off_t last_line_offset = 0;
|
||||
qpdf_offset_t last_line_offset = 0;
|
||||
size_t length = 0;
|
||||
while (input->tell() < eof)
|
||||
{
|
||||
@ -1568,7 +1570,7 @@ QPDF::recoverStreamLength(PointerHolder<InputSource> input,
|
||||
QPDFTokenizer::Token
|
||||
QPDF::readToken(PointerHolder<InputSource> input)
|
||||
{
|
||||
off_t offset = input->tell();
|
||||
qpdf_offset_t offset = input->tell();
|
||||
QPDFTokenizer::Token token;
|
||||
bool unread_char;
|
||||
char char_to_unread;
|
||||
@ -1611,7 +1613,7 @@ QPDF::readToken(PointerHolder<InputSource> input)
|
||||
|
||||
QPDFObjectHandle
|
||||
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& objid, int& generation)
|
||||
{
|
||||
@ -1663,7 +1665,7 @@ QPDF::readObjectAtOffset(bool try_recovery,
|
||||
if (this->xref_table.count(og) &&
|
||||
(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(
|
||||
false, new_offset, description,
|
||||
exp_objid, exp_generation, objid, generation);
|
||||
@ -1717,7 +1719,7 @@ QPDF::readObjectAtOffset(bool try_recovery,
|
||||
// linearization hint tables. Offsets and lengths of objects
|
||||
// may imply the end of an object to be anywhere between these
|
||||
// values.
|
||||
off_t end_before_space = this->file->tell();
|
||||
qpdf_offset_t end_before_space = this->file->tell();
|
||||
|
||||
// skip over spaces
|
||||
while (true)
|
||||
@ -1738,7 +1740,7 @@ QPDF::readObjectAtOffset(bool try_recovery,
|
||||
"EOF after endobj");
|
||||
}
|
||||
}
|
||||
off_t end_after_space = this->file->tell();
|
||||
qpdf_offset_t end_after_space = this->file->tell();
|
||||
|
||||
this->obj_cache[og] =
|
||||
ObjCache(QPDFObjectHandle::ObjAccessor::getObject(oh),
|
||||
@ -1768,7 +1770,7 @@ QPDF::resolve(int objid, int generation)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
off_t offset = entry.getOffset();
|
||||
qpdf_offset_t offset = entry.getOffset();
|
||||
// Object stored in cache by readObjectAtOffset
|
||||
int aobjid;
|
||||
int ageneration;
|
||||
@ -1812,8 +1814,10 @@ QPDF::resolveObjectsInStream(int obj_stream_number)
|
||||
// For linearization data in the object, use the data from the
|
||||
// object stream for the objects in the stream.
|
||||
ObjGen stream_og(obj_stream_number, 0);
|
||||
off_t end_before_space = this->obj_cache[stream_og].end_before_space;
|
||||
off_t end_after_space = this->obj_cache[stream_og].end_after_space;
|
||||
qpdf_offset_t end_before_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();
|
||||
if (! (dict.getKey("/Type").isName() &&
|
||||
@ -2102,7 +2106,7 @@ QPDF::getCompressibleObjects()
|
||||
|
||||
void
|
||||
QPDF::pipeStreamData(int objid, int generation,
|
||||
off_t offset, size_t length,
|
||||
qpdf_offset_t offset, size_t length,
|
||||
QPDFObjectHandle stream_dict,
|
||||
Pipeline* pipeline)
|
||||
{
|
||||
|
@ -4,7 +4,7 @@
|
||||
QPDFExc::QPDFExc(qpdf_error_code_e error_code,
|
||||
std::string const& filename,
|
||||
std::string const& object,
|
||||
off_t offset,
|
||||
qpdf_offset_t offset,
|
||||
std::string const& message) :
|
||||
std::runtime_error(createWhat(filename, object, offset, message)),
|
||||
error_code(error_code),
|
||||
@ -22,7 +22,7 @@ QPDFExc::~QPDFExc() throw ()
|
||||
std::string
|
||||
QPDFExc::createWhat(std::string const& filename,
|
||||
std::string const& object,
|
||||
off_t offset,
|
||||
qpdf_offset_t offset,
|
||||
std::string const& message)
|
||||
{
|
||||
std::string result;
|
||||
@ -73,7 +73,7 @@ QPDFExc::getObject() const
|
||||
return this->object;
|
||||
}
|
||||
|
||||
off_t
|
||||
qpdf_offset_t
|
||||
QPDFExc::getFilePosition() const
|
||||
{
|
||||
return this->offset;
|
||||
|
@ -632,7 +632,7 @@ QPDFObjectHandle::newDictionary(
|
||||
QPDFObjectHandle
|
||||
QPDFObjectHandle::newStream(QPDF* qpdf, int objid, int generation,
|
||||
QPDFObjectHandle stream_dict,
|
||||
off_t offset, size_t length)
|
||||
qpdf_offset_t offset, size_t length)
|
||||
{
|
||||
return QPDFObjectHandle(new QPDF_Stream(
|
||||
qpdf, objid, generation,
|
||||
|
@ -879,7 +879,7 @@ QPDFWriter::writeTrailer(trailer_e which, int size, bool xref_stream, int prev)
|
||||
if (which == t_lin_first)
|
||||
{
|
||||
writeString(" /Prev ");
|
||||
off_t pos = this->pipeline->getCount();
|
||||
qpdf_offset_t pos = this->pipeline->getCount();
|
||||
writeString(QUtil::int_to_string(prev));
|
||||
int nspaces = (int)(pos - this->pipeline->getCount() + 11);
|
||||
assert(nspaces >= 0);
|
||||
@ -1165,7 +1165,7 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level,
|
||||
}
|
||||
|
||||
void
|
||||
QPDFWriter::writeObjectStreamOffsets(std::vector<off_t>& offsets,
|
||||
QPDFWriter::writeObjectStreamOffsets(std::vector<qpdf_offset_t>& offsets,
|
||||
int first_obj)
|
||||
{
|
||||
for (unsigned int i = 0; i < offsets.size(); ++i)
|
||||
@ -1191,8 +1191,8 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object)
|
||||
int old_id = object.getObjectID();
|
||||
int new_id = obj_renumber[old_id];
|
||||
|
||||
std::vector<off_t> offsets;
|
||||
off_t first = 0;
|
||||
std::vector<qpdf_offset_t> offsets;
|
||||
qpdf_offset_t first = 0;
|
||||
|
||||
// Generate stream itself. We have to do this in two passes so we
|
||||
// can calculate offsets in the first pass.
|
||||
@ -1210,7 +1210,7 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object)
|
||||
// Adjust offsets to skip over comment before first object
|
||||
|
||||
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 -= first;
|
||||
@ -1820,13 +1820,14 @@ QPDFWriter::writeXRefTable(trailer_e which, int first, int last, int size)
|
||||
int
|
||||
QPDFWriter::writeXRefTable(trailer_e which, int first, int last, int size,
|
||||
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(QUtil::int_to_string(first));
|
||||
writeString(" ");
|
||||
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");
|
||||
for (int i = first; i <= last; ++i)
|
||||
{
|
||||
@ -1868,10 +1869,11 @@ int
|
||||
QPDFWriter::writeXRefStream(int xref_id, int max_id, int max_offset,
|
||||
trailer_e which, int first, int last, int size,
|
||||
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)
|
||||
{
|
||||
off_t xref_offset = this->pipeline->getCount();
|
||||
qpdf_offset_t xref_offset = this->pipeline->getCount();
|
||||
int space_before_zero = xref_offset - 1;
|
||||
|
||||
// field 1 contains offsets and object stream identifiers
|
||||
@ -2081,13 +2083,13 @@ QPDFWriter::writeLinearized()
|
||||
|
||||
int part4_end_marker = part4.back().getObjectID();
|
||||
int part6_end_marker = part6.back().getObjectID();
|
||||
off_t space_before_zero = 0;
|
||||
off_t file_size = 0;
|
||||
off_t part6_end_offset = 0;
|
||||
off_t first_half_max_obj_offset = 0;
|
||||
off_t second_xref_offset = 0;
|
||||
off_t first_xref_end = 0;
|
||||
off_t second_xref_end = 0;
|
||||
qpdf_offset_t space_before_zero = 0;
|
||||
qpdf_offset_t file_size = 0;
|
||||
qpdf_offset_t part6_end_offset = 0;
|
||||
qpdf_offset_t first_half_max_obj_offset = 0;
|
||||
qpdf_offset_t second_xref_offset = 0;
|
||||
qpdf_offset_t first_xref_end = 0;
|
||||
qpdf_offset_t second_xref_end = 0;
|
||||
|
||||
this->next_objid = part4_first_obj;
|
||||
enqueuePart(part4);
|
||||
@ -2101,7 +2103,7 @@ QPDFWriter::writeLinearized()
|
||||
enqueuePart(part9);
|
||||
assert(this->next_objid == after_second_half);
|
||||
|
||||
off_t hint_length = 0;
|
||||
qpdf_offset_t hint_length = 0;
|
||||
PointerHolder<Buffer> hint_buffer;
|
||||
|
||||
// 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
|
||||
// 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);
|
||||
writeString("<<");
|
||||
if (pass == 2)
|
||||
@ -2158,8 +2160,8 @@ QPDFWriter::writeLinearized()
|
||||
|
||||
// Part 3: first page cross reference table and trailer.
|
||||
|
||||
off_t first_xref_offset = this->pipeline->getCount();
|
||||
off_t hint_offset = 0;
|
||||
qpdf_offset_t first_xref_offset = this->pipeline->getCount();
|
||||
qpdf_offset_t hint_offset = 0;
|
||||
if (pass == 2)
|
||||
{
|
||||
hint_offset = this->xref[hint_id].getOffset();
|
||||
@ -2187,7 +2189,7 @@ QPDFWriter::writeLinearized()
|
||||
hint_length + second_xref_offset,
|
||||
hint_id, hint_offset, hint_length,
|
||||
(pass == 1));
|
||||
off_t endpos = this->pipeline->getCount();
|
||||
qpdf_offset_t endpos = this->pipeline->getCount();
|
||||
if (pass == 1)
|
||||
{
|
||||
// Pad so we have enough room for the real xref
|
||||
@ -2264,7 +2266,7 @@ QPDFWriter::writeLinearized()
|
||||
t_lin_second, 0, second_half_end,
|
||||
second_trailer_size,
|
||||
0, 0, 0, 0, (pass == 1));
|
||||
off_t endpos = this->pipeline->getCount();
|
||||
qpdf_offset_t endpos = this->pipeline->getCount();
|
||||
|
||||
if (pass == 1)
|
||||
{
|
||||
@ -2278,14 +2280,14 @@ QPDFWriter::writeLinearized()
|
||||
else
|
||||
{
|
||||
// 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);
|
||||
writeString("\n");
|
||||
|
||||
// If this assertion fails, maybe we didn't have
|
||||
// enough padding above.
|
||||
assert(this->pipeline->getCount() ==
|
||||
(off_t)(second_xref_end + hint_length));
|
||||
(qpdf_offset_t)(second_xref_end + hint_length));
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -2313,7 +2315,7 @@ QPDFWriter::writeLinearized()
|
||||
activatePipelineStack();
|
||||
writeHintStream(hint_id);
|
||||
popPipelineStack(&hint_buffer);
|
||||
hint_length = (off_t)hint_buffer->getSize();
|
||||
hint_length = (qpdf_offset_t)hint_buffer->getSize();
|
||||
|
||||
// Restore hint offset
|
||||
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.
|
||||
off_t xref_offset = this->pipeline->getCount();
|
||||
qpdf_offset_t xref_offset = this->pipeline->getCount();
|
||||
if (this->object_stream_to_objects.empty())
|
||||
{
|
||||
// Write regular cross-reference table
|
||||
|
@ -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),
|
||||
field1(field1),
|
||||
field2(field2)
|
||||
@ -27,7 +27,7 @@ QPDFXRefEntry::getType() const
|
||||
return this->type;
|
||||
}
|
||||
|
||||
off_t
|
||||
qpdf_offset_t
|
||||
QPDFXRefEntry::getOffset() const
|
||||
{
|
||||
if (this->type != 1)
|
||||
|
@ -22,7 +22,7 @@ std::map<std::string, std::string> QPDF_Stream::filter_abbreviations;
|
||||
|
||||
QPDF_Stream::QPDF_Stream(QPDF* qpdf, int objid, int generation,
|
||||
QPDFObjectHandle stream_dict,
|
||||
off_t offset, size_t length) :
|
||||
qpdf_offset_t offset, size_t length) :
|
||||
qpdf(qpdf),
|
||||
objid(objid),
|
||||
generation(generation),
|
||||
@ -379,8 +379,8 @@ QPDF_Stream::pipeStreamData(Pipeline* pipeline, bool filter,
|
||||
Pl_Count count("stream provider count", pipeline);
|
||||
this->stream_provider->provideStreamData(
|
||||
this->objid, this->generation, &count);
|
||||
off_t actual_length = count.getCount();
|
||||
off_t desired_length =
|
||||
qpdf_offset_t actual_length = count.getCount();
|
||||
qpdf_offset_t desired_length =
|
||||
this->stream_dict.getKey("/Length").getIntValue();
|
||||
if (actual_length == desired_length)
|
||||
{
|
||||
|
@ -305,15 +305,15 @@ QPDF::readLinearizationData()
|
||||
}
|
||||
|
||||
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 gen;
|
||||
QPDFObjectHandle H = readObjectAtOffset(
|
||||
false, offset, "linearization hint stream", -1, 0, obj, gen);
|
||||
ObjCache& oc = this->obj_cache[ObjGen(obj, gen)];
|
||||
off_t min_end_offset = oc.end_before_space;
|
||||
off_t max_end_offset = oc.end_after_space;
|
||||
qpdf_offset_t min_end_offset = oc.end_before_space;
|
||||
qpdf_offset_t max_end_offset = oc.end_after_space;
|
||||
if (! H.isStream())
|
||||
{
|
||||
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");
|
||||
}
|
||||
off_t computed_end = offset + (off_t)length;
|
||||
qpdf_offset_t computed_end = offset + (qpdf_offset_t)length;
|
||||
if ((computed_end < min_end_offset) ||
|
||||
(computed_end > max_end_offset))
|
||||
{
|
||||
|
@ -82,6 +82,16 @@ QUtil::double_to_string(double num, int decimal_places)
|
||||
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
|
||||
QUtil::throw_system_error(std::string const& description)
|
||||
{
|
||||
@ -109,22 +119,22 @@ QUtil::fopen_wrapper(std::string const& description, FILE* f)
|
||||
}
|
||||
|
||||
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
|
||||
return fseeko(stream, offset, whence);
|
||||
return fseeko(stream, (off_t)offset, whence);
|
||||
#else
|
||||
return fseek(stream, offset, whence);
|
||||
return fseek(stream, (long)offset, whence);
|
||||
#endif
|
||||
}
|
||||
|
||||
off_t
|
||||
qpdf_offset_t
|
||||
QUtil::ftell_off_t(FILE* stream)
|
||||
{
|
||||
#if HAVE_FSEEKO
|
||||
return ftello(stream);
|
||||
return (qpdf_offset_t)ftello(stream);
|
||||
#else
|
||||
return ftell(stream);
|
||||
return (qpdf_offset_t)ftell(stream);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ class QPDF_Stream: public QPDFObject
|
||||
public:
|
||||
QPDF_Stream(QPDF*, int objid, int generation,
|
||||
QPDFObjectHandle stream_dict,
|
||||
off_t offset, size_t length);
|
||||
qpdf_offset_t offset, size_t length);
|
||||
virtual ~QPDF_Stream();
|
||||
virtual std::string unparse();
|
||||
QPDFObjectHandle getDict() const;
|
||||
@ -51,7 +51,7 @@ class QPDF_Stream: public QPDFObject
|
||||
int objid;
|
||||
int generation;
|
||||
QPDFObjectHandle stream_dict;
|
||||
off_t offset;
|
||||
qpdf_offset_t offset;
|
||||
size_t length;
|
||||
PointerHolder<Buffer> stream_data;
|
||||
PointerHolder<QPDFObjectHandle::StreamDataProvider> stream_provider;
|
||||
|
Loading…
Reference in New Issue
Block a user