Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always copy the JPEG segment size #2989

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/jpgimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Comment on lines -457 to +459
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any better ideas how to return an empty slice/string here w/o throwing an exception are welcome...

if (signature == iccId_) {
// extract the chunk information from the buffer
//
Expand Down Expand Up @@ -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;
}
Expand Down
Loading