Commit a7e269537d8f4b33d1bc8a5a83c53432db9b7560
1 parent
ce8b1ba6
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
Showing
10 changed files
with
51 additions
and
45 deletions
examples/pdf-double-page-size.cc
| ... | ... | @@ -66,7 +66,7 @@ int main(int argc, char* argv[]) |
| 66 | 66 | |
| 67 | 67 | // Copy text into a buffer without the null terminator |
| 68 | 68 | PointerHolder<Buffer> b = new Buffer(strlen(content)); |
| 69 | - unsigned char* bp = b.getPointer()->getBuffer(); | |
| 69 | + unsigned char* bp = b->getBuffer(); | |
| 70 | 70 | memcpy(bp, (unsigned char*)content, strlen(content)); |
| 71 | 71 | |
| 72 | 72 | try | ... | ... |
examples/pdf-invert-images.cc
| ... | ... | @@ -48,8 +48,8 @@ ImageInverter::provideStreamData(int objid, int generation, |
| 48 | 48 | // image data. Then invert the image data and write the inverted |
| 49 | 49 | // data to the pipeline. |
| 50 | 50 | PointerHolder<Buffer> data = this->image_data[objid][generation]; |
| 51 | - size_t size = data.getPointer()->getSize(); | |
| 52 | - unsigned char* buf = data.getPointer()->getBuffer(); | |
| 51 | + size_t size = data->getSize(); | |
| 52 | + unsigned char* buf = data->getBuffer(); | |
| 53 | 53 | unsigned char ch; |
| 54 | 54 | for (size_t i = 0; i < size; ++i) |
| 55 | 55 | { |
| ... | ... | @@ -142,8 +142,7 @@ int main(int argc, char* argv[]) |
| 142 | 142 | p, |
| 143 | 143 | QPDFObjectHandle::newNull(), |
| 144 | 144 | QPDFObjectHandle::newNull(), |
| 145 | - inv->image_data[objid][gen].getPointer()-> | |
| 146 | - getSize()); | |
| 145 | + inv->image_data[objid][gen]->getSize()); | |
| 147 | 146 | } |
| 148 | 147 | } |
| 149 | 148 | } | ... | ... |
libqpdf/Pl_Buffer.cc
| ... | ... | @@ -51,9 +51,8 @@ Pl_Buffer::getBuffer() |
| 51 | 51 | unsigned char* p = b->getBuffer(); |
| 52 | 52 | while (! this->data.empty()) |
| 53 | 53 | { |
| 54 | - PointerHolder<Buffer> bph = this->data.front(); | |
| 54 | + PointerHolder<Buffer> bp = this->data.front(); | |
| 55 | 55 | this->data.pop_front(); |
| 56 | - Buffer* bp = bph.getPointer(); | |
| 57 | 56 | size_t bytes = bp->getSize(); |
| 58 | 57 | memcpy(p, bp->getBuffer(), bytes); |
| 59 | 58 | p += bytes; | ... | ... |
libqpdf/QPDF.cc
| ... | ... | @@ -854,7 +854,7 @@ QPDF::processXRefStream(off_t xref_offset, QPDFObjectHandle& xref_obj) |
| 854 | 854 | int expected_size = entry_size * num_entries; |
| 855 | 855 | |
| 856 | 856 | PointerHolder<Buffer> bp = xref_obj.getStreamData(); |
| 857 | - int actual_size = bp.getPointer()->getSize(); | |
| 857 | + int actual_size = bp->getSize(); | |
| 858 | 858 | |
| 859 | 859 | if (expected_size != actual_size) |
| 860 | 860 | { |
| ... | ... | @@ -878,7 +878,7 @@ QPDF::processXRefStream(off_t xref_offset, QPDFObjectHandle& xref_obj) |
| 878 | 878 | |
| 879 | 879 | bool saw_first_compressed_object = false; |
| 880 | 880 | |
| 881 | - unsigned char const* data = bp.getPointer()->getBuffer(); | |
| 881 | + unsigned char const* data = bp->getBuffer(); | |
| 882 | 882 | for (int i = 0; i < num_entries; ++i) |
| 883 | 883 | { |
| 884 | 884 | // Read this entry |
| ... | ... | @@ -1200,6 +1200,20 @@ QPDF::readObjectInternal(PointerHolder<InputSource> input, |
| 1200 | 1200 | olist.pop_back(); |
| 1201 | 1201 | olist.pop_back(); |
| 1202 | 1202 | } |
| 1203 | + else if ((value == "endobj") && | |
| 1204 | + (! (in_array || in_dictionary))) | |
| 1205 | + { | |
| 1206 | + // Nothing in the PDF spec appears to allow empty | |
| 1207 | + // objects, but they have been encountered in | |
| 1208 | + // actual PDF files and Adobe Reader appears to | |
| 1209 | + // ignore them. | |
| 1210 | + warn(QPDFExc(qpdf_e_damaged_pdf, input->getName(), | |
| 1211 | + this->last_object_description, | |
| 1212 | + input->getLastOffset(), | |
| 1213 | + "empty object treated as null")); | |
| 1214 | + object = QPDFObjectHandle::newNull(); | |
| 1215 | + input->seek(input->getLastOffset(), SEEK_SET); | |
| 1216 | + } | |
| 1203 | 1217 | else |
| 1204 | 1218 | { |
| 1205 | 1219 | throw QPDFExc(qpdf_e_damaged_pdf, input->getName(), | ... | ... |
libqpdf/QPDFObjectHandle.cc
libqpdf/QPDFWriter.cc
| ... | ... | @@ -527,8 +527,7 @@ QPDFWriter::writeString(std::string const& str) |
| 527 | 527 | void |
| 528 | 528 | QPDFWriter::writeBuffer(PointerHolder<Buffer>& b) |
| 529 | 529 | { |
| 530 | - this->pipeline->write(b.getPointer()->getBuffer(), | |
| 531 | - b.getPointer()->getSize()); | |
| 530 | + this->pipeline->write(b->getBuffer(), b->getSize()); | |
| 532 | 531 | } |
| 533 | 532 | |
| 534 | 533 | void |
| ... | ... | @@ -1038,7 +1037,7 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level, |
| 1038 | 1037 | compress = false; |
| 1039 | 1038 | } |
| 1040 | 1039 | |
| 1041 | - this->cur_stream_length = stream_data.getPointer()->getSize(); | |
| 1040 | + this->cur_stream_length = stream_data->getSize(); | |
| 1042 | 1041 | if (is_metadata && this->encrypted && (! this->encrypt_metadata)) |
| 1043 | 1042 | { |
| 1044 | 1043 | // Don't encrypt stream data for the metadata stream |
| ... | ... | @@ -1226,7 +1225,7 @@ QPDFWriter::writeObjectStream(QPDFObjectHandle object) |
| 1226 | 1225 | writeStringQDF("\n "); |
| 1227 | 1226 | writeString(" /Type /ObjStm"); |
| 1228 | 1227 | writeStringQDF("\n "); |
| 1229 | - unsigned long length = stream_buffer.getPointer()->getSize(); | |
| 1228 | + unsigned long length = stream_buffer->getSize(); | |
| 1230 | 1229 | adjustAESStreamLength(length); |
| 1231 | 1230 | writeString(" /Length " + QUtil::int_to_string(length)); |
| 1232 | 1231 | writeStringQDF("\n "); |
| ... | ... | @@ -1718,8 +1717,8 @@ QPDFWriter::writeHintStream(int hint_id) |
| 1718 | 1717 | openObject(hint_id); |
| 1719 | 1718 | setDataKey(hint_id); |
| 1720 | 1719 | |
| 1721 | - unsigned char* hs = hint_buffer.getPointer()->getBuffer(); | |
| 1722 | - unsigned long hlen = hint_buffer.getPointer()->getSize(); | |
| 1720 | + unsigned char* hs = hint_buffer->getBuffer(); | |
| 1721 | + unsigned long hlen = hint_buffer->getSize(); | |
| 1723 | 1722 | |
| 1724 | 1723 | writeString("<< /Filter /FlateDecode /S "); |
| 1725 | 1724 | writeString(QUtil::int_to_string(S)); |
| ... | ... | @@ -1888,8 +1887,7 @@ QPDFWriter::writeXRefStream(int xref_id, int max_id, int max_offset, |
| 1888 | 1887 | writeStringQDF("\n "); |
| 1889 | 1888 | writeString(" /Type /XRef"); |
| 1890 | 1889 | writeStringQDF("\n "); |
| 1891 | - writeString(" /Length " + | |
| 1892 | - QUtil::int_to_string(xref_data.getPointer()->getSize())); | |
| 1890 | + writeString(" /Length " + QUtil::int_to_string(xref_data->getSize())); | |
| 1893 | 1891 | if (compressed) |
| 1894 | 1892 | { |
| 1895 | 1893 | writeStringQDF("\n "); |
| ... | ... | @@ -2251,7 +2249,7 @@ QPDFWriter::writeLinearized() |
| 2251 | 2249 | activatePipelineStack(); |
| 2252 | 2250 | writeHintStream(hint_id); |
| 2253 | 2251 | popPipelineStack(&hint_buffer); |
| 2254 | - hint_length = hint_buffer.getPointer()->getSize(); | |
| 2252 | + hint_length = hint_buffer->getSize(); | |
| 2255 | 2253 | |
| 2256 | 2254 | // Restore hint offset |
| 2257 | 2255 | this->xref[hint_id] = QPDFXRefEntry(1, hint_offset, 0); | ... | ... |
libqpdf/QPDF_Stream.cc
| ... | ... | @@ -370,16 +370,15 @@ QPDF_Stream::pipeStreamData(Pipeline* pipeline, bool filter, |
| 370 | 370 | if (this->stream_data.getPointer()) |
| 371 | 371 | { |
| 372 | 372 | QTC::TC("qpdf", "QPDF_Stream pipe replaced stream data"); |
| 373 | - Buffer& b = *(this->stream_data.getPointer()); | |
| 374 | - pipeline->write(b.getBuffer(), b.getSize()); | |
| 373 | + pipeline->write(this->stream_data->getBuffer(), | |
| 374 | + this->stream_data->getSize()); | |
| 375 | 375 | pipeline->finish(); |
| 376 | 376 | } |
| 377 | 377 | else if (this->stream_provider.getPointer()) |
| 378 | 378 | { |
| 379 | - QPDFObjectHandle::StreamDataProvider& p = | |
| 380 | - (*this->stream_provider.getPointer()); | |
| 381 | 379 | Pl_Count count("stream provider count", pipeline); |
| 382 | - p.provideStreamData(this->objid, this->generation, &count); | |
| 380 | + this->stream_provider->provideStreamData( | |
| 381 | + this->objid, this->generation, &count); | |
| 383 | 382 | size_t actual_length = count.getCount(); |
| 384 | 383 | size_t desired_length = |
| 385 | 384 | this->stream_dict.getKey("/Length").getIntValue(); |
| ... | ... | @@ -424,7 +423,7 @@ QPDF_Stream::replaceStreamData(PointerHolder<Buffer> data, |
| 424 | 423 | { |
| 425 | 424 | this->stream_data = data; |
| 426 | 425 | this->stream_provider = 0; |
| 427 | - replaceFilterData(filter, decode_parms, data.getPointer()->getSize()); | |
| 426 | + replaceFilterData(filter, decode_parms, data->getSize()); | |
| 428 | 427 | } |
| 429 | 428 | |
| 430 | 429 | void | ... | ... |
libqpdf/QPDF_encryption.cc
| ... | ... | @@ -571,8 +571,7 @@ QPDF::decryptString(std::string& str, int objid, int generation) |
| 571 | 571 | pl.write((unsigned char*)str.c_str(), str.length()); |
| 572 | 572 | pl.finish(); |
| 573 | 573 | PointerHolder<Buffer> buf = bufpl.getBuffer(); |
| 574 | - str = std::string((char*)buf.getPointer()->getBuffer(), | |
| 575 | - (size_t)buf.getPointer()->getSize()); | |
| 574 | + str = std::string((char*)buf->getBuffer(), (size_t)buf->getSize()); | |
| 576 | 575 | } |
| 577 | 576 | else |
| 578 | 577 | { | ... | ... |
libqpdf/qpdf-c.cc
| ... | ... | @@ -176,7 +176,7 @@ char const* qpdf_get_error_full_text(qpdf_data qpdf, qpdf_error e) |
| 176 | 176 | { |
| 177 | 177 | return ""; |
| 178 | 178 | } |
| 179 | - return e->exc.getPointer()->what(); | |
| 179 | + return e->exc->what(); | |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | 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) |
| 185 | 185 | { |
| 186 | 186 | return qpdf_e_success; |
| 187 | 187 | } |
| 188 | - return e->exc.getPointer()->getErrorCode(); | |
| 188 | + return e->exc->getErrorCode(); | |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | 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) |
| 194 | 194 | { |
| 195 | 195 | return ""; |
| 196 | 196 | } |
| 197 | - return e->exc.getPointer()->getFilename().c_str(); | |
| 197 | + return e->exc->getFilename().c_str(); | |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | 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) |
| 203 | 203 | { |
| 204 | 204 | return 0; |
| 205 | 205 | } |
| 206 | - return e->exc.getPointer()->getFilePosition(); | |
| 206 | + return e->exc->getFilePosition(); | |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | 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) |
| 212 | 212 | { |
| 213 | 213 | return ""; |
| 214 | 214 | } |
| 215 | - return e->exc.getPointer()->getMessageDetail().c_str(); | |
| 215 | + return e->exc->getMessageDetail().c_str(); | |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | void qpdf_set_suppress_warnings(qpdf_data qpdf, QPDF_BOOL value) | ... | ... |
qpdf/test_driver.cc
| ... | ... | @@ -37,8 +37,7 @@ class Provider: public QPDFObjectHandle::StreamDataProvider |
| 37 | 37 | virtual void provideStreamData(int objid, int generation, |
| 38 | 38 | Pipeline* p) |
| 39 | 39 | { |
| 40 | - p->write(b.getPointer()->getBuffer(), | |
| 41 | - b.getPointer()->getSize()); | |
| 40 | + p->write(b->getBuffer(), b->getSize()); | |
| 42 | 41 | if (this->bad_length) |
| 43 | 42 | { |
| 44 | 43 | unsigned char ch = ' '; |
| ... | ... | @@ -352,7 +351,7 @@ void runtest(int n, char const* filename) |
| 352 | 351 | throw std::logic_error("test 7 run on file with no QStream"); |
| 353 | 352 | } |
| 354 | 353 | PointerHolder<Buffer> b = new Buffer(20); |
| 355 | - unsigned char* bp = b.getPointer()->getBuffer(); | |
| 354 | + unsigned char* bp = b->getBuffer(); | |
| 356 | 355 | memcpy(bp, (char*)"new data for stream\n", 20); // no null! |
| 357 | 356 | qstream.replaceStreamData( |
| 358 | 357 | b, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull()); |
| ... | ... | @@ -380,8 +379,7 @@ void runtest(int n, char const* filename) |
| 380 | 379 | PointerHolder<QPDFObjectHandle::StreamDataProvider> p = provider; |
| 381 | 380 | qstream.replaceStreamData( |
| 382 | 381 | p, QPDFObjectHandle::newName("/FlateDecode"), |
| 383 | - QPDFObjectHandle::newNull(), | |
| 384 | - b.getPointer()->getSize()); | |
| 382 | + QPDFObjectHandle::newNull(), b->getSize()); | |
| 385 | 383 | provider->badLength(true); |
| 386 | 384 | try |
| 387 | 385 | { |
| ... | ... | @@ -402,7 +400,7 @@ void runtest(int n, char const* filename) |
| 402 | 400 | { |
| 403 | 401 | QPDFObjectHandle root = pdf.getRoot(); |
| 404 | 402 | PointerHolder<Buffer> b1 = new Buffer(20); |
| 405 | - unsigned char* bp = b1.getPointer()->getBuffer(); | |
| 403 | + unsigned char* bp = b1->getBuffer(); | |
| 406 | 404 | memcpy(bp, (char*)"data for new stream\n", 20); // no null! |
| 407 | 405 | QPDFObjectHandle qstream = QPDFObjectHandle::newStream(&pdf, b1); |
| 408 | 406 | QPDFObjectHandle rstream = QPDFObjectHandle::newStream(&pdf); |
| ... | ... | @@ -416,7 +414,7 @@ void runtest(int n, char const* filename) |
| 416 | 414 | std::cout << "exception: " << e.what() << std::endl; |
| 417 | 415 | } |
| 418 | 416 | PointerHolder<Buffer> b2 = new Buffer(22); |
| 419 | - bp = b2.getPointer()->getBuffer(); | |
| 417 | + bp = b2->getBuffer(); | |
| 420 | 418 | memcpy(bp, (char*)"data for other stream\n", 22); // no null! |
| 421 | 419 | rstream.replaceStreamData( |
| 422 | 420 | b2, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull()); |
| ... | ... | @@ -430,10 +428,10 @@ void runtest(int n, char const* filename) |
| 430 | 428 | else if (n == 10) |
| 431 | 429 | { |
| 432 | 430 | PointerHolder<Buffer> b1 = new Buffer(37); |
| 433 | - unsigned char* bp = b1.getPointer()->getBuffer(); | |
| 431 | + unsigned char* bp = b1->getBuffer(); | |
| 434 | 432 | memcpy(bp, (char*)"BT /F1 12 Tf 72 620 Td (Baked) Tj ET\n", 37); |
| 435 | 433 | PointerHolder<Buffer> b2 = new Buffer(38); |
| 436 | - bp = b2.getPointer()->getBuffer(); | |
| 434 | + bp = b2->getBuffer(); | |
| 437 | 435 | memcpy(bp, (char*)"BT /F1 18 Tf 72 520 Td (Mashed) Tj ET\n", 38); |
| 438 | 436 | |
| 439 | 437 | std::vector<QPDFObjectHandle> pages = pdf.getAllPages(); |
| ... | ... | @@ -451,13 +449,13 @@ void runtest(int n, char const* filename) |
| 451 | 449 | QPDFObjectHandle qstream = root.getKey("/QStream"); |
| 452 | 450 | PointerHolder<Buffer> b1 = qstream.getStreamData(); |
| 453 | 451 | PointerHolder<Buffer> b2 = qstream.getRawStreamData(); |
| 454 | - if ((b1.getPointer()->getSize() == 7) && | |
| 455 | - (memcmp(b1.getPointer()->getBuffer(), "potato\n", 7) == 0)) | |
| 452 | + if ((b1->getSize() == 7) && | |
| 453 | + (memcmp(b1->getBuffer(), "potato\n", 7) == 0)) | |
| 456 | 454 | { |
| 457 | 455 | std::cout << "filtered stream data okay" << std::endl; |
| 458 | 456 | } |
| 459 | - if ((b2.getPointer()->getSize() == 15) && | |
| 460 | - (memcmp(b2.getPointer()->getBuffer(), "706F7461746F0A\n", 15) == 0)) | |
| 457 | + if ((b2->getSize() == 15) && | |
| 458 | + (memcmp(b2->getBuffer(), "706F7461746F0A\n", 15) == 0)) | |
| 461 | 459 | { |
| 462 | 460 | std::cout << "raw stream data okay" << std::endl; |
| 463 | 461 | } | ... | ... |