diff --git a/src/jpgimage.cpp b/src/jpgimage.cpp index facb1054..10264013 100644 --- a/src/jpgimage.cpp +++ b/src/jpgimage.cpp @@ -153,7 +153,7 @@ void JpegBase::readMetadata() { // Read the rest of the segment. DataBuf buf(size); - /// \todo check if it makes sense to check for size + /// check if the segment is not empty if (size > 2) { io_->readOrThrow(buf.data(2), size - 2, ErrorCode::kerFailedToReadImageData); std::copy(sizebuf.begin(), sizebuf.end(), buf.begin()); @@ -352,9 +352,9 @@ void JpegBase::printStructure(std::ostream& out, PrintStructureOption option, si const auto [sizebuf, size] = readSegmentSize(marker, *io_); - // Read the rest of the segment. + // Read the rest of the segment if not empty. DataBuf buf(size); - if (size > 0) { + if (size > 2) { io_->readOrThrow(buf.data(2), size - 2, ErrorCode::kerFailedToReadImageData); std::copy(sizebuf.begin(), sizebuf.end(), buf.begin()); } @@ -564,9 +564,9 @@ void JpegBase::writeMetadata() { DataBuf JpegBase::readNextSegment(byte marker) { const auto [sizebuf, size] = readSegmentSize(marker, *io_); - // Read the rest of the segment. + // Read the rest of the segment if not empty. DataBuf buf(size); - if (size > 0) { + if (size > 2) { io_->readOrThrow(buf.data(2), size - 2, ErrorCode::kerFailedToReadImageData); std::copy(sizebuf.begin(), sizebuf.end(), buf.begin()); }