From 4632707630cbb861d15705593109dc3fdbbcc4b3 Mon Sep 17 00:00:00 2001 From: James Holderness Date: Sun, 22 Sep 2024 16:17:53 +0100 Subject: [PATCH] Fix sixel crash when buffer is reflowed. --- src/terminal/adapter/SixelParser.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/terminal/adapter/SixelParser.cpp b/src/terminal/adapter/SixelParser.cpp index f9dbdf6603a..979dd42371c 100644 --- a/src/terminal/adapter/SixelParser.cpp +++ b/src/terminal/adapter/SixelParser.cpp @@ -715,8 +715,16 @@ void SixelParser::_eraseImageBufferRows(const int rowCount, const til::CoordType const auto pixelCount = rowCount * _cellSize.height; const auto bufferOffset = rowOffset * _cellSize.height * _imageMaxWidth; const auto bufferOffsetEnd = bufferOffset + pixelCount * _imageMaxWidth; - _imageBuffer.erase(_imageBuffer.begin() + bufferOffset, _imageBuffer.begin() + bufferOffsetEnd); - _imageCursor.y -= pixelCount; + if (static_cast(bufferOffsetEnd) >= _imageBuffer.size()) [[unlikely]] + { + _imageBuffer.clear(); + _imageCursor.y = 0; + } + else + { + _imageBuffer.erase(_imageBuffer.begin() + bufferOffset, _imageBuffer.begin() + bufferOffsetEnd); + _imageCursor.y -= pixelCount; + } } void SixelParser::_maybeFlushImageBuffer(const bool endOfSequence)