Commit 0dee39707583b300bc745c923452a848d0f02c88
1 parent
9f7f9496
In QPDF::pipeStreamData read buffer in a single read
Showing
1 changed file
with
8 additions
and
15 deletions
libqpdf/QPDF.cc
| ... | ... | @@ -2419,23 +2419,17 @@ QPDF::pipeStreamData( |
| 2419 | 2419 | } |
| 2420 | 2420 | |
| 2421 | 2421 | bool attempted_finish = false; |
| 2422 | - bool success = false; | |
| 2423 | 2422 | try { |
| 2424 | 2423 | file->seek(offset, SEEK_SET); |
| 2425 | - char buf[10240]; | |
| 2426 | - while (length > 0) { | |
| 2427 | - size_t to_read = (sizeof(buf) < length ? sizeof(buf) : length); | |
| 2428 | - size_t len = file->read(buf, to_read); | |
| 2429 | - if (len == 0) { | |
| 2430 | - throw damagedPDF( | |
| 2431 | - file, "", file->getLastOffset(), "unexpected EOF reading stream data"); | |
| 2432 | - } | |
| 2433 | - length -= len; | |
| 2434 | - pipeline->write(buf, len); | |
| 2424 | + auto buf = std::make_unique<char[]>(length); | |
| 2425 | + if (auto read = file->read(buf.get(), length); read != length) { | |
| 2426 | + throw damagedPDF( | |
| 2427 | + file, "", offset + toO(read), "unexpected EOF reading stream data"); | |
| 2435 | 2428 | } |
| 2429 | + pipeline->write(buf.get(), length); | |
| 2436 | 2430 | attempted_finish = true; |
| 2437 | 2431 | pipeline->finish(); |
| 2438 | - success = true; | |
| 2432 | + return true; | |
| 2439 | 2433 | } catch (QPDFExc& e) { |
| 2440 | 2434 | if (!suppress_warnings) { |
| 2441 | 2435 | qpdf_for_warning.warn(e); |
| ... | ... | @@ -2458,8 +2452,7 @@ QPDF::pipeStreamData( |
| 2458 | 2452 | file, |
| 2459 | 2453 | "", |
| 2460 | 2454 | file->getLastOffset(), |
| 2461 | - "stream will be re-processed without" | |
| 2462 | - " filtering to avoid data loss")); | |
| 2455 | + "stream will be re-processed without filtering to avoid data loss")); | |
| 2463 | 2456 | } |
| 2464 | 2457 | } |
| 2465 | 2458 | } |
| ... | ... | @@ -2470,7 +2463,7 @@ QPDF::pipeStreamData( |
| 2470 | 2463 | // ignore |
| 2471 | 2464 | } |
| 2472 | 2465 | } |
| 2473 | - return success; | |
| 2466 | + return false ; | |
| 2474 | 2467 | } |
| 2475 | 2468 | |
| 2476 | 2469 | bool | ... | ... |