Commit b1d845e708f99f5a77a27b2c0ca088f2f69ea4dd
1 parent
db06e075
Split QPDF member file into file and file_sp to facilitate aliasing
To be encapsulated later.
Showing
2 changed files
with
15 additions
and
8 deletions
libqpdf/QPDF.cc
| ... | ... | @@ -198,7 +198,8 @@ QPDF::EncryptionParameters::EncryptionParameters() : |
| 198 | 198 | |
| 199 | 199 | QPDF::Members::Members(QPDF& qpdf) : |
| 200 | 200 | log(QPDFLogger::defaultLogger()), |
| 201 | - file(new InvalidInputSource()), | |
| 201 | + file_sp(new InvalidInputSource()), | |
| 202 | + file(file_sp.get()), | |
| 202 | 203 | encp(new EncryptionParameters), |
| 203 | 204 | xref_table(qpdf) |
| 204 | 205 | { |
| ... | ... | @@ -272,14 +273,16 @@ QPDF::processMemoryFile( |
| 272 | 273 | void |
| 273 | 274 | QPDF::processInputSource(std::shared_ptr<InputSource> source, char const* password) |
| 274 | 275 | { |
| 275 | - m->file = source; | |
| 276 | + m->file_sp = source; | |
| 277 | + m->file = source.get(); | |
| 276 | 278 | parse(password); |
| 277 | 279 | } |
| 278 | 280 | |
| 279 | 281 | void |
| 280 | 282 | QPDF::closeInputSource() |
| 281 | 283 | { |
| 282 | - m->file = std::shared_ptr<InputSource>(new InvalidInputSource()); | |
| 284 | + m->file_sp = std::shared_ptr<InputSource>(new InvalidInputSource()); | |
| 285 | + m->file = m->file_sp.get(); | |
| 283 | 286 | } |
| 284 | 287 | |
| 285 | 288 | void |
| ... | ... | @@ -412,7 +415,9 @@ QPDF::findHeader() |
| 412 | 415 | // PDF header, all explicit offsets in the file are such that 0 points to the beginning |
| 413 | 416 | // of the header. |
| 414 | 417 | QTC::TC("qpdf", "QPDF global offset"); |
| 415 | - m->file = std::shared_ptr<InputSource>(new OffsetInputSource(m->file, global_offset)); | |
| 418 | + m->file_sp = | |
| 419 | + std::shared_ptr<InputSource>(new OffsetInputSource(m->file_sp, global_offset)); | |
| 420 | + m->file = m->file_sp.get(); | |
| 416 | 421 | } |
| 417 | 422 | } |
| 418 | 423 | return valid; |
| ... | ... | @@ -1541,7 +1546,7 @@ QPDF::readStream(QPDFObjectHandle& object, QPDFObjGen og, qpdf_offset_t offset) |
| 1541 | 1546 | } catch (QPDFExc& e) { |
| 1542 | 1547 | if (m->attempt_recovery) { |
| 1543 | 1548 | warn(e); |
| 1544 | - length = recoverStreamLength(m->file, og, stream_offset); | |
| 1549 | + length = recoverStreamLength(m->file_sp, og, stream_offset); | |
| 1545 | 1550 | } else { |
| 1546 | 1551 | throw; |
| 1547 | 1552 | } |
| ... | ... | @@ -2452,7 +2457,7 @@ QPDF::copyStreamData(QPDFObjectHandle result, QPDFObjectHandle foreign) |
| 2452 | 2457 | } else { |
| 2453 | 2458 | auto foreign_stream_data = std::make_shared<ForeignStreamData>( |
| 2454 | 2459 | foreign_stream_qpdf.m->encp, |
| 2455 | - foreign_stream_qpdf.m->file, | |
| 2460 | + foreign_stream_qpdf.m->file_sp, | |
| 2456 | 2461 | foreign.getObjGen(), |
| 2457 | 2462 | stream->getParsedOffset(), |
| 2458 | 2463 | stream->getLength(), |
| ... | ... | @@ -2776,7 +2781,7 @@ QPDF::pipeStreamData( |
| 2776 | 2781 | { |
| 2777 | 2782 | return pipeStreamData( |
| 2778 | 2783 | m->encp, |
| 2779 | - m->file, | |
| 2784 | + m->file_sp, | |
| 2780 | 2785 | *this, |
| 2781 | 2786 | og, |
| 2782 | 2787 | offset, | ... | ... |
libqpdf/qpdf/QPDF_private.hh
| ... | ... | @@ -528,7 +528,9 @@ class QPDF::Members |
| 528 | 528 | std::shared_ptr<QPDFLogger> log; |
| 529 | 529 | unsigned long long unique_id{0}; |
| 530 | 530 | QPDFTokenizer tokenizer; |
| 531 | - std::shared_ptr<InputSource> file; | |
| 531 | + // If file_sp is updated, file must also be updated. | |
| 532 | + std::shared_ptr<InputSource> file_sp; | |
| 533 | + InputSource* file; | |
| 532 | 534 | std::string last_object_description; |
| 533 | 535 | bool provided_password_is_hex_key{false}; |
| 534 | 536 | bool suppress_warnings{false}; | ... | ... |