Skip to content

Commit 2469369

Browse files
committed
Always copy the JPEG segment size
1 parent 9999608 commit 2469369

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/jpgimage.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,9 @@ void JpegBase::printStructure(std::ostream& out, PrintStructureOption option, si
454454
} else if (bPrint) {
455455
const size_t start = 2;
456456
const size_t end = size > 34 ? 34 : size;
457-
out << "| " << Internal::binaryToString(makeSlice(buf, start, end));
457+
out << "| ";
458+
if (start < end)
459+
out << Internal::binaryToString(makeSlice(buf, start, end));
458460
if (signature == iccId_) {
459461
// extract the chunk information from the buffer
460462
//
@@ -601,9 +603,11 @@ DataBuf JpegBase::readNextSegment(byte marker) {
601603

602604
// Read the rest of the segment if not empty.
603605
DataBuf buf(size);
604-
if (size > 2) {
605-
io_->readOrThrow(buf.data(2), size - 2, ErrorCode::kerFailedToReadImageData);
606+
if (size > 0) {
606607
std::copy(sizebuf.begin(), sizebuf.end(), buf.begin());
608+
if (size > 2) {
609+
io_->readOrThrow(buf.data(2), size - 2, ErrorCode::kerFailedToReadImageData);
610+
}
607611
}
608612
return buf;
609613
}

0 commit comments

Comments
 (0)