From 24693697b6e32158f1aad79800bc05a6776595ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milo=C5=A1=20Komar=C4=8Devi=C4=87?= Date: Mon, 17 Jun 2024 17:24:30 +0200 Subject: [PATCH] Always copy the JPEG segment size --- src/jpgimage.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/jpgimage.cpp b/src/jpgimage.cpp index 1d10e659..feb2e111 100644 --- a/src/jpgimage.cpp +++ b/src/jpgimage.cpp @@ -454,7 +454,9 @@ void JpegBase::printStructure(std::ostream& out, PrintStructureOption option, si } else if (bPrint) { const size_t start = 2; const size_t end = size > 34 ? 34 : size; - out << "| " << Internal::binaryToString(makeSlice(buf, start, end)); + out << "| "; + if (start < end) + out << Internal::binaryToString(makeSlice(buf, start, end)); if (signature == iccId_) { // extract the chunk information from the buffer // @@ -601,9 +603,11 @@ DataBuf JpegBase::readNextSegment(byte marker) { // Read the rest of the segment if not empty. DataBuf buf(size); - if (size > 2) { - io_->readOrThrow(buf.data(2), size - 2, ErrorCode::kerFailedToReadImageData); + if (size > 0) { std::copy(sizebuf.begin(), sizebuf.end(), buf.begin()); + if (size > 2) { + io_->readOrThrow(buf.data(2), size - 2, ErrorCode::kerFailedToReadImageData); + } } return buf; }