From bfb6750b138850aa85deac8f27e7c075b7c70701 Mon Sep 17 00:00:00 2001 From: Viktor Liu Date: Mon, 18 May 2026 07:41:42 +0200 Subject: [PATCH] Reset encoding capability flags on each SetEncodings --- client/vnc/server/session.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/client/vnc/server/session.go b/client/vnc/server/session.go index 1c250c4fc..697fabe76 100644 --- a/client/vnc/server/session.go +++ b/client/vnc/server/session.go @@ -277,6 +277,10 @@ func (s *session) handleSetEncodings() error { var encs []string s.encMu.Lock() + // Per RFC 6143 ยง7.5.3 each SetEncodings replaces the previous list, so + // reset all flags before re-applying. extClipCapsSent stays sticky so + // we don't re-emit Caps every refresh. + s.resetEncodingCaps() for i := range int(numEnc) { enc := int32(binary.BigEndian.Uint32(buf[i*4 : i*4+4])) if name := s.applyEncoding(enc); name != "" { @@ -304,6 +308,23 @@ func (s *session) handleSetEncodings() error { return nil } +// resetEncodingCaps zeroes the encoding capability flags so the next pass +// through applyEncoding reflects exactly what the client just advertised. +// Caller holds s.encMu. tight / copyRectDet allocations are kept; their +// runtime use is gated by the boolean flags here. +func (s *session) resetEncodingCaps() { + s.useTight = false + s.useCopyRect = false + s.clientSupportsDesktopSize = false + s.clientSupportsExtendedDesktopSize = false + s.clientSupportsDesktopName = false + s.clientSupportsLastRect = false + s.clientSupportsQEMUKey = false + s.clientSupportsExtClipboard = false + s.clientJPEGQuality = -1 + s.clientZlibLevel = -1 +} + // applyEncoding records a single encoding/pseudo-encoding from a SetEncodings // message. Returns the short name used in the debug log, or "" if the value // is one we don't recognise. Caller holds s.encMu.