Commit f81cb10d4f25a83416df3a4564e1e5fb74ed3fdd
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 | 532 | quint32 block_size; |
| 533 | 533 | blockReader >> block_size; |
| 534 | 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 | 539 | decompressedBlock = qUncompress(compressedBlock); |
| 538 | 540 | |
| ... | ... | @@ -589,6 +591,8 @@ qint64 BlockCompression::readData(char *data, qint64 remaining) |
| 589 | 591 | // read the size of the next block |
| 590 | 592 | quint32 block_size; |
| 591 | 593 | blockReader >> block_size; |
| 594 | + if (block_size == 0) | |
| 595 | + break; | |
| 592 | 596 | |
| 593 | 597 | compressedBlock.resize(block_size); |
| 594 | 598 | int actualRead = blockReader.readRawData(compressedBlock.data(), block_size); |
| ... | ... | @@ -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 | 610 | bool condition = blockReader.atEnd() && !basis->isReadable() ; |
| 609 | 611 | if (condition) |
| 610 | 612 | qWarning("Returning -1 from read"); | ... | ... |