Commit ef866d68cd77cad9640350715adf3374fd5719c7

Authored by m-holger
1 parent c422b918

In QPDF::readStream remove variable done

Showing 1 changed file with 12 additions and 9 deletions
libqpdf/QPDF.cc
@@ -1331,17 +1331,19 @@ QPDF::readStream(QPDFObjectHandle& object, QPDFObjGen og, qpdf_offset_t offset) @@ -1331,17 +1331,19 @@ QPDF::readStream(QPDFObjectHandle& object, QPDFObjGen og, qpdf_offset_t offset)
1331 // accept a carriage return by itself when followed by a non-newline character, so that's what 1331 // accept a carriage return by itself when followed by a non-newline character, so that's what
1332 // we do here. We have also seen files that have extraneous whitespace between the stream 1332 // we do here. We have also seen files that have extraneous whitespace between the stream
1333 // keyword and the newline. 1333 // keyword and the newline.
1334 - bool done = false;  
1335 - while (!done) {  
1336 - done = true; 1334 + while (true) {
1337 char ch; 1335 char ch;
1338 if (m->file->read(&ch, 1) == 0) { 1336 if (m->file->read(&ch, 1) == 0) {
1339 // A premature EOF here will result in some other problem that will get reported at 1337 // A premature EOF here will result in some other problem that will get reported at
1340 // another time. 1338 // another time.
1341 - } else if (ch == '\n') { 1339 + break;
  1340 + }
  1341 + if (ch == '\n') {
1342 // ready to read stream data 1342 // ready to read stream data
1343 QTC::TC("qpdf", "QPDF stream with NL only"); 1343 QTC::TC("qpdf", "QPDF stream with NL only");
1344 - } else if (ch == '\r') { 1344 + break;
  1345 + }
  1346 + if (ch == '\r') {
1345 // Read another character 1347 // Read another character
1346 if (m->file->read(&ch, 1) != 0) { 1348 if (m->file->read(&ch, 1) != 0) {
1347 if (ch == '\n') { 1349 if (ch == '\n') {
@@ -1356,15 +1358,16 @@ QPDF::readStream(QPDFObjectHandle& object, QPDFObjGen og, qpdf_offset_t offset) @@ -1356,15 +1358,16 @@ QPDF::readStream(QPDFObjectHandle& object, QPDFObjGen og, qpdf_offset_t offset)
1356 m->file->tell(), "stream keyword followed by carriage return only")); 1358 m->file->tell(), "stream keyword followed by carriage return only"));
1357 } 1359 }
1358 } 1360 }
1359 - } else if (QUtil::is_space(ch)) {  
1360 - warn(damagedPDF(m->file->tell(), "stream keyword followed by extraneous whitespace"));  
1361 - done = false;  
1362 - } else { 1361 + break;
  1362 + }
  1363 + if (!QUtil::is_space(ch)) {
1363 QTC::TC("qpdf", "QPDF stream without newline"); 1364 QTC::TC("qpdf", "QPDF stream without newline");
1364 m->file->unreadCh(ch); 1365 m->file->unreadCh(ch);
1365 warn(damagedPDF( 1366 warn(damagedPDF(
1366 m->file->tell(), "stream keyword not followed by proper line terminator")); 1367 m->file->tell(), "stream keyword not followed by proper line terminator"));
  1368 + break;
1367 } 1369 }
  1370 + warn(damagedPDF(m->file->tell(), "stream keyword followed by extraneous whitespace"));
1368 } 1371 }
1369 1372
1370 // Must get offset before accessing any additional objects since resolving a previously 1373 // Must get offset before accessing any additional objects since resolving a previously