From f3385c1e03ae31c17d1062bfe2d94f41c9265f8b Mon Sep 17 00:00:00 2001 From: ExPikaPaka Date: Wed, 29 Jul 2026 08:20:23 +0200 Subject: [PATCH] Clamp the G-code window reads to the mapped file size --- src/slic3r/GUI/GCodeViewer.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index 20bcb109e1..4d895d20a8 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -771,10 +771,16 @@ void GCodeViewer::SequentialView::GCodeWindow::render(float top, float bottom, f auto update_lines = [this](uint64_t start_id, uint64_t end_id) { std::vector ret; ret.reserve(end_id - start_id + 1); + // Orca: m_lines_ends indexes into a memory mapping, so it must be clamped to the mapping. If the + // file was modified behind our back (an in-place post-processing script that shrank it), an + // unchecked read is an access violation, which the caller's try/catch cannot catch on Windows. + const size_t file_size = m_file.size(); for (uint64_t id = start_id; id <= end_id; ++id) { // read line from file - const size_t start = id == 1 ? 0 : m_lines_ends[id - 2]; - const size_t original_len = m_lines_ends[id - 1] - start; + // Keep one entry per id: render() indexes m_lines by (id - start_id). + const size_t start = id == 1 ? 0 : std::min(m_lines_ends[id - 2], file_size); + const size_t end = std::min(m_lines_ends[id - 1], file_size); + const size_t original_len = end > start ? end - start : 0; const size_t len = std::min(original_len, (size_t) 55); std::string gline(m_file.data() + start, len);