Current master fails with image #2565: segmentation fault when trying to access outofband offest: check all locations

This commit is contained in:
Mohamed Ali Chebbi 2023-04-13 01:20:02 +02:00 committed by Rosen Penev
parent e403f3a4c4
commit a530cf9d03

View File

@ -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());
}