Commit f81cb10d4f25a83416df3a4564e1e5fb74ed3fdd

Authored by Charles Otto
1 parent 6e505719

Don't qFatal on reads that are longer than the remaining data

This is normal operation, the QDataStream will sometimes request
blocks larger than the amount remaining, in that case it's fine just
to return the max amount available instead of erroring.
Showing 1 changed file with 5 additions and 3 deletions
openbr/core/qtutils.cpp
@@ -532,7 +532,9 @@ bool BlockCompression::open(QIODevice::OpenMode mode) @@ -532,7 +532,9 @@ bool BlockCompression::open(QIODevice::OpenMode mode)
532 quint32 block_size; 532 quint32 block_size;
533 blockReader >> block_size; 533 blockReader >> block_size;
534 compressedBlock.resize(block_size); 534 compressedBlock.resize(block_size);
535 - blockReader.readRawData(compressedBlock.data(), block_size); 535 + int read_count = blockReader.readRawData(compressedBlock.data(), block_size);
  536 + if (read_count != block_size)
  537 + qFatal("Failed to read initial block");
536 538
537 decompressedBlock = qUncompress(compressedBlock); 539 decompressedBlock = qUncompress(compressedBlock);
538 540
@@ -589,6 +591,8 @@ qint64 BlockCompression::readData(char *data, qint64 remaining) @@ -589,6 +591,8 @@ qint64 BlockCompression::readData(char *data, qint64 remaining)
589 // read the size of the next block 591 // read the size of the next block
590 quint32 block_size; 592 quint32 block_size;
591 blockReader >> block_size; 593 blockReader >> block_size;
  594 + if (block_size == 0)
  595 + break;
592 596
593 compressedBlock.resize(block_size); 597 compressedBlock.resize(block_size);
594 int actualRead = blockReader.readRawData(compressedBlock.data(), block_size); 598 int actualRead = blockReader.readRawData(compressedBlock.data(), block_size);
@@ -603,8 +607,6 @@ qint64 BlockCompression::readData(char *data, qint64 remaining) @@ -603,8 +607,6 @@ qint64 BlockCompression::readData(char *data, qint64 remaining)
603 } 607 }
604 } 608 }
605 609
606 - if (read != initial)  
607 - qFatal("Failed to read enough");  
608 bool condition = blockReader.atEnd() && !basis->isReadable() ; 610 bool condition = blockReader.atEnd() && !basis->isReadable() ;
609 if (condition) 611 if (condition)
610 qWarning("Returning -1 from read"); 612 qWarning("Returning -1 from read");