2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-11-16 01:27:07 +00:00

update code to new PointerHolder, and reintroduce change that was accidentally backed out

git-svn-id: svn+q:///qpdf/trunk@1031 71b93d88-0707-0410-a8cf-f5a4172ac649
This commit is contained in:
Jay Berkenbilt 2010-09-24 20:45:18 +00:00
parent ce8b1ba6a5
commit a7e269537d
10 changed files with 51 additions and 45 deletions

View File

@ -66,7 +66,7 @@ int main(int argc, char* argv[])
// Copy text into a buffer without the null terminator // Copy text into a buffer without the null terminator
PointerHolder<Buffer> b = new Buffer(strlen(content)); PointerHolder<Buffer> b = new Buffer(strlen(content));
unsigned char* bp = b.getPointer()->getBuffer(); unsigned char* bp = b->getBuffer();
memcpy(bp, (unsigned char*)content, strlen(content)); memcpy(bp, (unsigned char*)content, strlen(content));
try try

View File

@ -48,8 +48,8 @@ ImageInverter::provideStreamData(int objid, int generation,
// image data. Then invert the image data and write the inverted // image data. Then invert the image data and write the inverted
// data to the pipeline. // data to the pipeline.
PointerHolder<Buffer> data = this->image_data[objid][generation]; PointerHolder<Buffer> data = this->image_data[objid][generation];
size_t size = data.getPointer()->getSize(); size_t size = data->getSize();
unsigned char* buf = data.getPointer()->getBuffer(); unsigned char* buf = data->getBuffer();
unsigned char ch; unsigned char ch;
for (size_t i = 0; i < size; ++i) for (size_t i = 0; i < size; ++i)
{ {
@ -142,8 +142,7 @@ int main(int argc, char* argv[])
p, p,
QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull(),
QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull(),
inv->image_data[objid][gen].getPointer()-> inv->image_data[objid][gen]->getSize());
getSize());
} }
} }
} }

View File

@ -51,9 +51,8 @@ Pl_Buffer::getBuffer()
unsigned char* p = b->getBuffer(); unsigned char* p = b->getBuffer();
while (! this->data.empty()) while (! this->data.empty())
{ {
PointerHolder<Buffer> bph = this->data.front(); PointerHolder<Buffer> bp = this->data.front();
this->data.pop_front(); this->data.pop_front();
Buffer* bp = bph.getPointer();
size_t bytes = bp->getSize(); size_t bytes = bp->getSize();
memcpy(p, bp->getBuffer(), bytes); memcpy(p, bp->getBuffer(), bytes);
p += bytes; p += bytes;

View File

@ -854,7 +854,7 @@ QPDF::processXRefStream(off_t xref_offset, QPDFObjectHandle& xref_obj)
int expected_size = entry_size * num_entries; int expected_size = entry_size * num_entries;
PointerHolder<Buffer> bp = xref_obj.getStreamData(); PointerHolder<Buffer> bp = xref_obj.getStreamData();
int actual_size = bp.getPointer()->getSize(); int actual_size = bp->getSize();
if (expected_size != actual_size) if (expected_size != actual_size)
{ {
@ -878,7 +878,7 @@ QPDF::processXRefStream(off_t xref_offset, QPDFObjectHandle& xref_obj)
bool saw_first_compressed_object = false; bool saw_first_compressed_object = false;
unsigned char const* data = bp.getPointer()->getBuffer(); unsigned char const* data = bp->getBuffer();
for (int i = 0; i < num_entries; ++i) for (int i = 0; i < num_entries; ++i)
{ {
// Read this entry // Read this entry
@ -1200,6 +1200,20 @@ QPDF::readObjectInternal(PointerHolder<InputSource> input,
olist.pop_back(); olist.pop_back();
olist.pop_back(); olist.pop_back();
} }
else if ((value == "endobj") &&
(! (in_array || in_dictionary)))
{
// Nothing in the PDF spec appears to allow empty
// objects, but they have been encountered in
// actual PDF files and Adobe Reader appears to
// ignore them.
warn(QPDFExc(qpdf_e_damaged_pdf, input->getName(),
this->last_object_description,
input->getLastOffset(),
"empty object treated as null"));
object = QPDFObjectHandle::newNull();
input->seek(input->getLastOffset(), SEEK_SET);
}
else else
{ {
throw QPDFExc(qpdf_e_damaged_pdf, input->getName(), throw QPDFExc(qpdf_e_damaged_pdf, input->getName(),

View File

@ -528,7 +528,7 @@ std::string
QPDFObjectHandle::unparseResolved() QPDFObjectHandle::unparseResolved()
{ {
dereference(); dereference();
return this->obj.getPointer()->unparse(); return this->obj->unparse();
} }
QPDFObjectHandle QPDFObjectHandle

View File

@ -527,8 +527,7 @@ QPDFWriter::writeString(std::string const& str)
void void
QPDFWriter::writeBuffer(PointerHolder<Buffer>& b) QPDFWriter::writeBuffer(PointerHolder<Buffer>& b)
{ {
this->pipeline->write(b.getPointer()->getBuffer(), this->pipeline->write(b->getBuffer(), b->getSize());
b.getPointer()->getSize());
} }
void void
@ -1038,7 +1037,7 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level,
compress = false; compress = false;
} }
this->cur_stream_length = stream_data.getPointer()->getSize(); this->cur_stream_length = stream_data->getSize();
if (is_metadata && this->encrypted && (! this->encrypt_metadata)) if (is_metadata && this->encrypted && (! this->encrypt_metadata))
{ {
// Don't encrypt stream data for the metadata stream // Don't encrypt stream data for the metadata stream
@ -1226,7 +1225,7 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object)
writeStringQDF("\n "); writeStringQDF("\n ");
writeString(" /Type /ObjStm"); writeString(" /Type /ObjStm");
writeStringQDF("\n "); writeStringQDF("\n ");
unsigned long length = stream_buffer.getPointer()->getSize(); unsigned long 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 ");
@ -1718,8 +1717,8 @@ QPDFWriter::writeHintStream(int hint_id)
openObject(hint_id); openObject(hint_id);
setDataKey(hint_id); setDataKey(hint_id);
unsigned char* hs = hint_buffer.getPointer()->getBuffer(); unsigned char* hs = hint_buffer->getBuffer();
unsigned long hlen = hint_buffer.getPointer()->getSize(); unsigned long hlen = hint_buffer->getSize();
writeString("<< /Filter /FlateDecode /S "); writeString("<< /Filter /FlateDecode /S ");
writeString(QUtil::int_to_string(S)); writeString(QUtil::int_to_string(S));
@ -1888,8 +1887,7 @@ QPDFWriter::writeXRefStream(int xref_id, int max_id, int max_offset,
writeStringQDF("\n "); writeStringQDF("\n ");
writeString(" /Type /XRef"); writeString(" /Type /XRef");
writeStringQDF("\n "); writeStringQDF("\n ");
writeString(" /Length " + writeString(" /Length " + QUtil::int_to_string(xref_data->getSize()));
QUtil::int_to_string(xref_data.getPointer()->getSize()));
if (compressed) if (compressed)
{ {
writeStringQDF("\n "); writeStringQDF("\n ");
@ -2251,7 +2249,7 @@ QPDFWriter::writeLinearized()
activatePipelineStack(); activatePipelineStack();
writeHintStream(hint_id); writeHintStream(hint_id);
popPipelineStack(&hint_buffer); popPipelineStack(&hint_buffer);
hint_length = hint_buffer.getPointer()->getSize(); hint_length = 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);

View File

@ -370,16 +370,15 @@ QPDF_Stream::pipeStreamData(Pipeline* pipeline, bool filter,
if (this->stream_data.getPointer()) if (this->stream_data.getPointer())
{ {
QTC::TC("qpdf", "QPDF_Stream pipe replaced stream data"); QTC::TC("qpdf", "QPDF_Stream pipe replaced stream data");
Buffer& b = *(this->stream_data.getPointer()); pipeline->write(this->stream_data->getBuffer(),
pipeline->write(b.getBuffer(), b.getSize()); this->stream_data->getSize());
pipeline->finish(); pipeline->finish();
} }
else if (this->stream_provider.getPointer()) else if (this->stream_provider.getPointer())
{ {
QPDFObjectHandle::StreamDataProvider& p =
(*this->stream_provider.getPointer());
Pl_Count count("stream provider count", pipeline); Pl_Count count("stream provider count", pipeline);
p.provideStreamData(this->objid, this->generation, &count); this->stream_provider->provideStreamData(
this->objid, this->generation, &count);
size_t actual_length = count.getCount(); size_t actual_length = count.getCount();
size_t desired_length = size_t desired_length =
this->stream_dict.getKey("/Length").getIntValue(); this->stream_dict.getKey("/Length").getIntValue();
@ -424,7 +423,7 @@ QPDF_Stream::replaceStreamData(PointerHolder<Buffer> data,
{ {
this->stream_data = data; this->stream_data = data;
this->stream_provider = 0; this->stream_provider = 0;
replaceFilterData(filter, decode_parms, data.getPointer()->getSize()); replaceFilterData(filter, decode_parms, data->getSize());
} }
void void

View File

@ -571,8 +571,7 @@ 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.getPointer()->getBuffer(), str = std::string((char*)buf->getBuffer(), (size_t)buf->getSize());
(size_t)buf.getPointer()->getSize());
} }
else else
{ {

View File

@ -176,7 +176,7 @@ char const* qpdf_get_error_full_text(qpdf_data qpdf, qpdf_error e)
{ {
return ""; return "";
} }
return e->exc.getPointer()->what(); return e->exc->what();
} }
enum qpdf_error_code_e qpdf_get_error_code(qpdf_data qpdf, qpdf_error e) enum qpdf_error_code_e qpdf_get_error_code(qpdf_data qpdf, qpdf_error e)
@ -185,7 +185,7 @@ enum qpdf_error_code_e qpdf_get_error_code(qpdf_data qpdf, qpdf_error e)
{ {
return qpdf_e_success; return qpdf_e_success;
} }
return e->exc.getPointer()->getErrorCode(); return e->exc->getErrorCode();
} }
char const* qpdf_get_error_filename(qpdf_data qpdf, qpdf_error e) char const* qpdf_get_error_filename(qpdf_data qpdf, qpdf_error e)
@ -194,7 +194,7 @@ char const* qpdf_get_error_filename(qpdf_data qpdf, qpdf_error e)
{ {
return ""; return "";
} }
return e->exc.getPointer()->getFilename().c_str(); return e->exc->getFilename().c_str();
} }
unsigned long qpdf_get_error_file_position(qpdf_data qpdf, qpdf_error e) unsigned long qpdf_get_error_file_position(qpdf_data qpdf, qpdf_error e)
@ -203,7 +203,7 @@ unsigned long qpdf_get_error_file_position(qpdf_data qpdf, qpdf_error e)
{ {
return 0; return 0;
} }
return e->exc.getPointer()->getFilePosition(); return e->exc->getFilePosition();
} }
char const* qpdf_get_error_message_detail(qpdf_data qpdf, qpdf_error e) char const* qpdf_get_error_message_detail(qpdf_data qpdf, qpdf_error e)
@ -212,7 +212,7 @@ char const* qpdf_get_error_message_detail(qpdf_data qpdf, qpdf_error e)
{ {
return ""; return "";
} }
return e->exc.getPointer()->getMessageDetail().c_str(); return e->exc->getMessageDetail().c_str();
} }
void qpdf_set_suppress_warnings(qpdf_data qpdf, QPDF_BOOL value) void qpdf_set_suppress_warnings(qpdf_data qpdf, QPDF_BOOL value)

View File

@ -37,8 +37,7 @@ class Provider: public QPDFObjectHandle::StreamDataProvider
virtual void provideStreamData(int objid, int generation, virtual void provideStreamData(int objid, int generation,
Pipeline* p) Pipeline* p)
{ {
p->write(b.getPointer()->getBuffer(), p->write(b->getBuffer(), b->getSize());
b.getPointer()->getSize());
if (this->bad_length) if (this->bad_length)
{ {
unsigned char ch = ' '; unsigned char ch = ' ';
@ -352,7 +351,7 @@ void runtest(int n, char const* filename)
throw std::logic_error("test 7 run on file with no QStream"); throw std::logic_error("test 7 run on file with no QStream");
} }
PointerHolder<Buffer> b = new Buffer(20); PointerHolder<Buffer> b = new Buffer(20);
unsigned char* bp = b.getPointer()->getBuffer(); unsigned char* bp = b->getBuffer();
memcpy(bp, (char*)"new data for stream\n", 20); // no null! memcpy(bp, (char*)"new data for stream\n", 20); // no null!
qstream.replaceStreamData( qstream.replaceStreamData(
b, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull()); b, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull());
@ -380,8 +379,7 @@ void runtest(int n, char const* filename)
PointerHolder<QPDFObjectHandle::StreamDataProvider> p = provider; PointerHolder<QPDFObjectHandle::StreamDataProvider> p = provider;
qstream.replaceStreamData( qstream.replaceStreamData(
p, QPDFObjectHandle::newName("/FlateDecode"), p, QPDFObjectHandle::newName("/FlateDecode"),
QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull(), b->getSize());
b.getPointer()->getSize());
provider->badLength(true); provider->badLength(true);
try try
{ {
@ -402,7 +400,7 @@ void runtest(int n, char const* filename)
{ {
QPDFObjectHandle root = pdf.getRoot(); QPDFObjectHandle root = pdf.getRoot();
PointerHolder<Buffer> b1 = new Buffer(20); PointerHolder<Buffer> b1 = new Buffer(20);
unsigned char* bp = b1.getPointer()->getBuffer(); unsigned char* bp = b1->getBuffer();
memcpy(bp, (char*)"data for new stream\n", 20); // no null! memcpy(bp, (char*)"data for new stream\n", 20); // no null!
QPDFObjectHandle qstream = QPDFObjectHandle::newStream(&pdf, b1); QPDFObjectHandle qstream = QPDFObjectHandle::newStream(&pdf, b1);
QPDFObjectHandle rstream = QPDFObjectHandle::newStream(&pdf); QPDFObjectHandle rstream = QPDFObjectHandle::newStream(&pdf);
@ -416,7 +414,7 @@ void runtest(int n, char const* filename)
std::cout << "exception: " << e.what() << std::endl; std::cout << "exception: " << e.what() << std::endl;
} }
PointerHolder<Buffer> b2 = new Buffer(22); PointerHolder<Buffer> b2 = new Buffer(22);
bp = b2.getPointer()->getBuffer(); bp = b2->getBuffer();
memcpy(bp, (char*)"data for other stream\n", 22); // no null! memcpy(bp, (char*)"data for other stream\n", 22); // no null!
rstream.replaceStreamData( rstream.replaceStreamData(
b2, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull()); b2, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull());
@ -430,10 +428,10 @@ void runtest(int n, char const* filename)
else if (n == 10) else if (n == 10)
{ {
PointerHolder<Buffer> b1 = new Buffer(37); PointerHolder<Buffer> b1 = new Buffer(37);
unsigned char* bp = b1.getPointer()->getBuffer(); unsigned char* bp = b1->getBuffer();
memcpy(bp, (char*)"BT /F1 12 Tf 72 620 Td (Baked) Tj ET\n", 37); memcpy(bp, (char*)"BT /F1 12 Tf 72 620 Td (Baked) Tj ET\n", 37);
PointerHolder<Buffer> b2 = new Buffer(38); PointerHolder<Buffer> b2 = new Buffer(38);
bp = b2.getPointer()->getBuffer(); bp = b2->getBuffer();
memcpy(bp, (char*)"BT /F1 18 Tf 72 520 Td (Mashed) Tj ET\n", 38); memcpy(bp, (char*)"BT /F1 18 Tf 72 520 Td (Mashed) Tj ET\n", 38);
std::vector<QPDFObjectHandle> pages = pdf.getAllPages(); std::vector<QPDFObjectHandle> pages = pdf.getAllPages();
@ -451,13 +449,13 @@ void runtest(int n, char const* filename)
QPDFObjectHandle qstream = root.getKey("/QStream"); QPDFObjectHandle qstream = root.getKey("/QStream");
PointerHolder<Buffer> b1 = qstream.getStreamData(); PointerHolder<Buffer> b1 = qstream.getStreamData();
PointerHolder<Buffer> b2 = qstream.getRawStreamData(); PointerHolder<Buffer> b2 = qstream.getRawStreamData();
if ((b1.getPointer()->getSize() == 7) && if ((b1->getSize() == 7) &&
(memcmp(b1.getPointer()->getBuffer(), "potato\n", 7) == 0)) (memcmp(b1->getBuffer(), "potato\n", 7) == 0))
{ {
std::cout << "filtered stream data okay" << std::endl; std::cout << "filtered stream data okay" << std::endl;
} }
if ((b2.getPointer()->getSize() == 15) && if ((b2->getSize() == 15) &&
(memcmp(b2.getPointer()->getBuffer(), "706F7461746F0A\n", 15) == 0)) (memcmp(b2->getBuffer(), "706F7461746F0A\n", 15) == 0))
{ {
std::cout << "raw stream data okay" << std::endl; std::cout << "raw stream data okay" << std::endl;
} }