From a7e269537d8f4b33d1bc8a5a83c53432db9b7560 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Fri, 24 Sep 2010 20:45:18 +0000 Subject: [PATCH] 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 --- examples/pdf-double-page-size.cc | 2 +- examples/pdf-invert-images.cc | 7 +++---- libqpdf/Pl_Buffer.cc | 3 +-- libqpdf/QPDF.cc | 18 ++++++++++++++++-- libqpdf/QPDFObjectHandle.cc | 2 +- libqpdf/QPDFWriter.cc | 16 +++++++--------- libqpdf/QPDF_Stream.cc | 11 +++++------ libqpdf/QPDF_encryption.cc | 3 +-- libqpdf/qpdf-c.cc | 10 +++++----- qpdf/test_driver.cc | 24 +++++++++++------------- 10 files changed, 51 insertions(+), 45 deletions(-) diff --git a/examples/pdf-double-page-size.cc b/examples/pdf-double-page-size.cc index 4377d0d7..bfdd3aef 100644 --- a/examples/pdf-double-page-size.cc +++ b/examples/pdf-double-page-size.cc @@ -66,7 +66,7 @@ int main(int argc, char* argv[]) // Copy text into a buffer without the null terminator PointerHolder b = new Buffer(strlen(content)); - unsigned char* bp = b.getPointer()->getBuffer(); + unsigned char* bp = b->getBuffer(); memcpy(bp, (unsigned char*)content, strlen(content)); try diff --git a/examples/pdf-invert-images.cc b/examples/pdf-invert-images.cc index e84181bc..2dc73251 100644 --- a/examples/pdf-invert-images.cc +++ b/examples/pdf-invert-images.cc @@ -48,8 +48,8 @@ ImageInverter::provideStreamData(int objid, int generation, // image data. Then invert the image data and write the inverted // data to the pipeline. PointerHolder data = this->image_data[objid][generation]; - size_t size = data.getPointer()->getSize(); - unsigned char* buf = data.getPointer()->getBuffer(); + size_t size = data->getSize(); + unsigned char* buf = data->getBuffer(); unsigned char ch; for (size_t i = 0; i < size; ++i) { @@ -142,8 +142,7 @@ int main(int argc, char* argv[]) p, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull(), - inv->image_data[objid][gen].getPointer()-> - getSize()); + inv->image_data[objid][gen]->getSize()); } } } diff --git a/libqpdf/Pl_Buffer.cc b/libqpdf/Pl_Buffer.cc index 1729b2c3..38af153d 100644 --- a/libqpdf/Pl_Buffer.cc +++ b/libqpdf/Pl_Buffer.cc @@ -51,9 +51,8 @@ Pl_Buffer::getBuffer() unsigned char* p = b->getBuffer(); while (! this->data.empty()) { - PointerHolder bph = this->data.front(); + PointerHolder bp = this->data.front(); this->data.pop_front(); - Buffer* bp = bph.getPointer(); size_t bytes = bp->getSize(); memcpy(p, bp->getBuffer(), bytes); p += bytes; diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index 6783f2fb..bf9beac5 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -854,7 +854,7 @@ QPDF::processXRefStream(off_t xref_offset, QPDFObjectHandle& xref_obj) int expected_size = entry_size * num_entries; PointerHolder bp = xref_obj.getStreamData(); - int actual_size = bp.getPointer()->getSize(); + int actual_size = bp->getSize(); if (expected_size != actual_size) { @@ -878,7 +878,7 @@ QPDF::processXRefStream(off_t xref_offset, QPDFObjectHandle& xref_obj) 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) { // Read this entry @@ -1200,6 +1200,20 @@ QPDF::readObjectInternal(PointerHolder input, 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 { throw QPDFExc(qpdf_e_damaged_pdf, input->getName(), diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index 658f4393..b877f3dd 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -528,7 +528,7 @@ std::string QPDFObjectHandle::unparseResolved() { dereference(); - return this->obj.getPointer()->unparse(); + return this->obj->unparse(); } QPDFObjectHandle diff --git a/libqpdf/QPDFWriter.cc b/libqpdf/QPDFWriter.cc index 68fd62f5..0cba17d9 100644 --- a/libqpdf/QPDFWriter.cc +++ b/libqpdf/QPDFWriter.cc @@ -527,8 +527,7 @@ QPDFWriter::writeString(std::string const& str) void QPDFWriter::writeBuffer(PointerHolder& b) { - this->pipeline->write(b.getPointer()->getBuffer(), - b.getPointer()->getSize()); + this->pipeline->write(b->getBuffer(), b->getSize()); } void @@ -1038,7 +1037,7 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level, 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)) { // Don't encrypt stream data for the metadata stream @@ -1226,7 +1225,7 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) writeStringQDF("\n "); writeString(" /Type /ObjStm"); writeStringQDF("\n "); - unsigned long length = stream_buffer.getPointer()->getSize(); + unsigned long length = stream_buffer->getSize(); adjustAESStreamLength(length); writeString(" /Length " + QUtil::int_to_string(length)); writeStringQDF("\n "); @@ -1718,8 +1717,8 @@ QPDFWriter::writeHintStream(int hint_id) openObject(hint_id); setDataKey(hint_id); - unsigned char* hs = hint_buffer.getPointer()->getBuffer(); - unsigned long hlen = hint_buffer.getPointer()->getSize(); + unsigned char* hs = hint_buffer->getBuffer(); + unsigned long hlen = hint_buffer->getSize(); writeString("<< /Filter /FlateDecode /S "); writeString(QUtil::int_to_string(S)); @@ -1888,8 +1887,7 @@ QPDFWriter::writeXRefStream(int xref_id, int max_id, int max_offset, writeStringQDF("\n "); writeString(" /Type /XRef"); writeStringQDF("\n "); - writeString(" /Length " + - QUtil::int_to_string(xref_data.getPointer()->getSize())); + writeString(" /Length " + QUtil::int_to_string(xref_data->getSize())); if (compressed) { writeStringQDF("\n "); @@ -2251,7 +2249,7 @@ QPDFWriter::writeLinearized() activatePipelineStack(); writeHintStream(hint_id); popPipelineStack(&hint_buffer); - hint_length = hint_buffer.getPointer()->getSize(); + hint_length = hint_buffer->getSize(); // Restore hint offset this->xref[hint_id] = QPDFXRefEntry(1, hint_offset, 0); diff --git a/libqpdf/QPDF_Stream.cc b/libqpdf/QPDF_Stream.cc index db6cfb58..dc8c7f93 100644 --- a/libqpdf/QPDF_Stream.cc +++ b/libqpdf/QPDF_Stream.cc @@ -370,16 +370,15 @@ QPDF_Stream::pipeStreamData(Pipeline* pipeline, bool filter, if (this->stream_data.getPointer()) { QTC::TC("qpdf", "QPDF_Stream pipe replaced stream data"); - Buffer& b = *(this->stream_data.getPointer()); - pipeline->write(b.getBuffer(), b.getSize()); + pipeline->write(this->stream_data->getBuffer(), + this->stream_data->getSize()); pipeline->finish(); } else if (this->stream_provider.getPointer()) { - QPDFObjectHandle::StreamDataProvider& p = - (*this->stream_provider.getPointer()); 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 desired_length = this->stream_dict.getKey("/Length").getIntValue(); @@ -424,7 +423,7 @@ QPDF_Stream::replaceStreamData(PointerHolder data, { this->stream_data = data; this->stream_provider = 0; - replaceFilterData(filter, decode_parms, data.getPointer()->getSize()); + replaceFilterData(filter, decode_parms, data->getSize()); } void diff --git a/libqpdf/QPDF_encryption.cc b/libqpdf/QPDF_encryption.cc index 51691399..7e191a27 100644 --- a/libqpdf/QPDF_encryption.cc +++ b/libqpdf/QPDF_encryption.cc @@ -571,8 +571,7 @@ QPDF::decryptString(std::string& str, int objid, int generation) pl.write((unsigned char*)str.c_str(), str.length()); pl.finish(); PointerHolder buf = bufpl.getBuffer(); - str = std::string((char*)buf.getPointer()->getBuffer(), - (size_t)buf.getPointer()->getSize()); + str = std::string((char*)buf->getBuffer(), (size_t)buf->getSize()); } else { diff --git a/libqpdf/qpdf-c.cc b/libqpdf/qpdf-c.cc index 384e0983..d7776d21 100644 --- a/libqpdf/qpdf-c.cc +++ b/libqpdf/qpdf-c.cc @@ -176,7 +176,7 @@ char const* qpdf_get_error_full_text(qpdf_data qpdf, qpdf_error e) { 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) @@ -185,7 +185,7 @@ enum qpdf_error_code_e qpdf_get_error_code(qpdf_data qpdf, qpdf_error e) { 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) @@ -194,7 +194,7 @@ char const* qpdf_get_error_filename(qpdf_data qpdf, qpdf_error e) { 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) @@ -203,7 +203,7 @@ unsigned long qpdf_get_error_file_position(qpdf_data qpdf, qpdf_error e) { return 0; } - return e->exc.getPointer()->getFilePosition(); + return e->exc->getFilePosition(); } 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 e->exc.getPointer()->getMessageDetail().c_str(); + return e->exc->getMessageDetail().c_str(); } void qpdf_set_suppress_warnings(qpdf_data qpdf, QPDF_BOOL value) diff --git a/qpdf/test_driver.cc b/qpdf/test_driver.cc index 6eaec4bc..00d8691d 100644 --- a/qpdf/test_driver.cc +++ b/qpdf/test_driver.cc @@ -37,8 +37,7 @@ class Provider: public QPDFObjectHandle::StreamDataProvider virtual void provideStreamData(int objid, int generation, Pipeline* p) { - p->write(b.getPointer()->getBuffer(), - b.getPointer()->getSize()); + p->write(b->getBuffer(), b->getSize()); if (this->bad_length) { 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"); } PointerHolder 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! qstream.replaceStreamData( b, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull()); @@ -380,8 +379,7 @@ void runtest(int n, char const* filename) PointerHolder p = provider; qstream.replaceStreamData( p, QPDFObjectHandle::newName("/FlateDecode"), - QPDFObjectHandle::newNull(), - b.getPointer()->getSize()); + QPDFObjectHandle::newNull(), b->getSize()); provider->badLength(true); try { @@ -402,7 +400,7 @@ void runtest(int n, char const* filename) { QPDFObjectHandle root = pdf.getRoot(); PointerHolder 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! QPDFObjectHandle qstream = QPDFObjectHandle::newStream(&pdf, b1); QPDFObjectHandle rstream = QPDFObjectHandle::newStream(&pdf); @@ -416,7 +414,7 @@ void runtest(int n, char const* filename) std::cout << "exception: " << e.what() << std::endl; } PointerHolder b2 = new Buffer(22); - bp = b2.getPointer()->getBuffer(); + bp = b2->getBuffer(); memcpy(bp, (char*)"data for other stream\n", 22); // no null! rstream.replaceStreamData( b2, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull()); @@ -430,10 +428,10 @@ void runtest(int n, char const* filename) else if (n == 10) { PointerHolder 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); PointerHolder 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); std::vector pages = pdf.getAllPages(); @@ -451,13 +449,13 @@ void runtest(int n, char const* filename) QPDFObjectHandle qstream = root.getKey("/QStream"); PointerHolder b1 = qstream.getStreamData(); PointerHolder b2 = qstream.getRawStreamData(); - if ((b1.getPointer()->getSize() == 7) && - (memcmp(b1.getPointer()->getBuffer(), "potato\n", 7) == 0)) + if ((b1->getSize() == 7) && + (memcmp(b1->getBuffer(), "potato\n", 7) == 0)) { std::cout << "filtered stream data okay" << std::endl; } - if ((b2.getPointer()->getSize() == 15) && - (memcmp(b2.getPointer()->getBuffer(), "706F7461746F0A\n", 15) == 0)) + if ((b2->getSize() == 15) && + (memcmp(b2->getBuffer(), "706F7461746F0A\n", 15) == 0)) { std::cout << "raw stream data okay" << std::endl; }