From d591e8ff37cd53a90ef8cc5896fa82aebda25d06 Mon Sep 17 00:00:00 2001 From: John Campion Jr Date: Thu, 5 Nov 2026 20:22:45 -0500 Subject: [PATCH] Make DECRQCRA opt-in (TerminalOptions.ChecksumReportsEnabled, default off) --- README.md | 17 ++++++++++ src/XTerm.NET.Tests/ChecksumReportTests.cs | 32 +++++++++++++++++-- src/XTerm.NET.Tests/DeviceReportTests.cs | 1 + .../Options/TerminalOptionsTests.cs | 1 + src/XTerm.NET.Tests/VtTestBehaviourTests.cs | 1 + src/XTerm.NET/InputHandler.Csi.cs | 5 +++ src/XTerm.NET/Options/TerminalOptions.cs | 17 ++++++++++ 7 files changed, 72 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 467d0066..44fa6789 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,23 @@ line falls out of the scrollback — and a resize does nothing to it at all. See ## Compliance ![Compliance](https://raw.githubusercontent.com/tomlm/Iciclecreek.Avalonia.Terminal/main/compliance.png) +## Behaviour changes + +**DECRQCRA is off by default.** `CSI Pid ; Pp ; Pt ; Pl ; Pb ; Pr * y` asks for a checksum of a +rectangle of the screen. Asked one cell at a time, it gives back the text, so a program, or a remote +host you've just ssh'd to, can read what was on screen before it started, alternate screen included. +WezTerm turned it off for the same reason, xterm gates it behind `allowWindowOps`, and iTerm2 asks +first. While it is off the request is ignored and nothing is sent back, which is what xterm and +WezTerm do. + +esctest reads every cell back through DECRQCRA, so turn it back on for a conformance run: + +```csharp +var terminal = new Terminal(new TerminalOptions { ChecksumReportsEnabled = true }); +// or, on a running terminal: +terminal.Options.ChecksumReportsEnabled = true; +``` + ## Upgrading to 3.0 **3.0 changes how Sixel is stored.** If you only host a terminal and draw text, or draw only Kitty diff --git a/src/XTerm.NET.Tests/ChecksumReportTests.cs b/src/XTerm.NET.Tests/ChecksumReportTests.cs index ef7578cd..081646f0 100644 --- a/src/XTerm.NET.Tests/ChecksumReportTests.cs +++ b/src/XTerm.NET.Tests/ChecksumReportTests.cs @@ -10,8 +10,36 @@ public class ChecksumReportTests { private const string Esc = ""; - private static Terminal NewTerminal(int cols = 20, int rows = 5) => - new(new TerminalOptions { Cols = cols, Rows = rows }); + // Opted in, as an esctest run has to be: the report is off by default (tomlm/XTerm.NET#190). + private static Terminal NewTerminal(int cols = 20, int rows = 5, bool enabled = true) => + new(new TerminalOptions { Cols = cols, Rows = rows, ChecksumReportsEnabled = enabled }); + + /// + /// Off by default: DECRQCRA reads the screen back one cell at a time, so a program could recover + /// what was displayed before it started. Like xterm and WezTerm when it is disallowed, the + /// request goes unanswered rather than drawing a reply that could pass for a sum. + /// + [Fact] + public void Is_silent_by_default() + { + var terminal = new Terminal(new TerminalOptions { Cols = 20, Rows = 5 }); + terminal.Write("Hello"); + + Assert.Null(Reply(terminal, $"{Esc}[1;0;1;1;1;1*y")); + Assert.Null(Reply(terminal, $"{Esc}[1*y")); + } + + [Fact] + public void Is_silent_when_disabled_and_answers_once_enabled() + { + var terminal = NewTerminal(enabled: false); + terminal.Write("Hello"); + Assert.Null(Reply(terminal, $"{Esc}[1;0;1;1;1;1*y")); + + // The option is read per request, so a host can turn it on for a running terminal. + terminal.Options.ChecksumReportsEnabled = true; + Assert.Equal(Report(1, 'H'), Reply(terminal, $"{Esc}[1;0;1;1;1;1*y")); + } private static string? Reply(Terminal terminal, string sequence) { diff --git a/src/XTerm.NET.Tests/DeviceReportTests.cs b/src/XTerm.NET.Tests/DeviceReportTests.cs index 98054924..ee5aca00 100644 --- a/src/XTerm.NET.Tests/DeviceReportTests.cs +++ b/src/XTerm.NET.Tests/DeviceReportTests.cs @@ -144,6 +144,7 @@ public void Decrqtsr_WithNoParameterAsksForNothing() public void Decrqcra_IsSilentBelowLevel64() { var (terminal, replies) = Create(); + terminal.Options.ChecksumReportsEnabled = true; // opt-in; the level gate is what's tested terminal.Write(Esc + "[64\"p"); terminal.Write(Esc + "[1;0;1;1;1;1*y"); Assert.Single(replies); // answered at VT400 diff --git a/src/XTerm.NET.Tests/Options/TerminalOptionsTests.cs b/src/XTerm.NET.Tests/Options/TerminalOptionsTests.cs index 59aed1e6..36a2d314 100644 --- a/src/XTerm.NET.Tests/Options/TerminalOptionsTests.cs +++ b/src/XTerm.NET.Tests/Options/TerminalOptionsTests.cs @@ -39,6 +39,7 @@ public void Constructor_SetsDefaultValues() Assert.Equal(RendererType.Canvas, options.RendererType); Assert.True(options.ClipboardWriteEnabled); Assert.False(options.ClipboardReadEnabled); + Assert.False(options.ChecksumReportsEnabled); // DECRQCRA reads the screen back: opt-in Assert.NotNull(options.WindowOptions); Assert.NotNull(options.Theme); Assert.Equal(1, options.MinimumContrastRatio); diff --git a/src/XTerm.NET.Tests/VtTestBehaviourTests.cs b/src/XTerm.NET.Tests/VtTestBehaviourTests.cs index 440dcf39..79ab7441 100644 --- a/src/XTerm.NET.Tests/VtTestBehaviourTests.cs +++ b/src/XTerm.NET.Tests/VtTestBehaviourTests.cs @@ -170,6 +170,7 @@ public void A_tab_stop_can_be_set_and_landed_on() public void Rectangular_area_checksums_negate_the_sum_of_the_characters() { var terminal = Sized(20, 5); + terminal.Options.ChecksumReportsEnabled = true; // vttest's checksum test needs the opt-in var replies = new List(); terminal.DataReceived += (_, e) => replies.Add(e.Data); diff --git a/src/XTerm.NET/InputHandler.Csi.cs b/src/XTerm.NET/InputHandler.Csi.cs index 2ace064c..0e034236 100644 --- a/src/XTerm.NET/InputHandler.Csi.cs +++ b/src/XTerm.NET/InputHandler.Csi.cs @@ -1753,6 +1753,11 @@ private void RequestChecksumRectangularArea(Params parameters) if (!RectangularEditingAvailable) return; + // A read-back of the screen, so opt-in; see TerminalOptions.ChecksumReportsEnabled. Silent + // when off, as xterm and WezTerm are, rather than a reply that could be mistaken for a sum. + if (!_terminal.Options.ChecksumReportsEnabled) + return; + var id = parameters.GetParam(0, 0); // parameters[1] is the page, ignored. Coordinates are read in the ORIGIN MODE system, // like a cursor address and like every rectangle operation: a program that addresses its diff --git a/src/XTerm.NET/Options/TerminalOptions.cs b/src/XTerm.NET/Options/TerminalOptions.cs index 11d04928..ae785f60 100644 --- a/src/XTerm.NET/Options/TerminalOptions.cs +++ b/src/XTerm.NET/Options/TerminalOptions.cs @@ -254,6 +254,22 @@ public int TabStopWidth /// public bool ClipboardReadEnabled { get; set; } = false; + /// + /// Whether DECRQCRA (CSI Pid ; Pp ; Pt ; Pl ; Pb ; Pr * y), the checksum of a + /// rectangular area, is answered. + /// + /// + /// Disabled by default for the same reason as : it is a + /// read-back. Checksumming one cell at a time recovers the screen's text, so a program -- or a + /// remote host the user has just ssh'd to -- can read what was displayed before it started, + /// including the alternate screen the last full-screen application left behind. WezTerm turned + /// it off for this reason, xterm gates it behind allowWindowOps, and iTerm2 asks first. + /// While off the request is ignored and nothing is sent, which is what xterm and WezTerm + /// do when it is disallowed. esctest reads every cell back through this, so a conformance run + /// needs it set true. + /// + public bool ChecksumReportsEnabled { get; set; } = false; + /// /// Whether control characters survive . /// @@ -547,6 +563,7 @@ public TerminalOptions(TerminalOptions other) KittyNotificationsEnabled = other.KittyNotificationsEnabled; ClipboardWriteEnabled = other.ClipboardWriteEnabled; ClipboardReadEnabled = other.ClipboardReadEnabled; + ChecksumReportsEnabled = other.ChecksumReportsEnabled; AllowPasteControls = other.AllowPasteControls; MaxClipboardBytes = other.MaxClipboardBytes; KittyKeyboardEnabled = other.KittyKeyboardEnabled;