Skip to content

fix(graphics): mirror decoder GR-mode adaptation in RLGR1 encoder#1370

Open
Rocco De Angelis (rdeangel) wants to merge 1 commit into
Devolutions:masterfrom
rdeangel:fix/rlgr1-encoder-gr-adaptation
Open

fix(graphics): mirror decoder GR-mode adaptation in RLGR1 encoder#1370
Rocco De Angelis (rdeangel) wants to merge 1 commit into
Devolutions:masterfrom
rdeangel:fix/rlgr1-encoder-gr-adaptation

Conversation

@rdeangel

Copy link
Copy Markdown

Problem

In rlgr::encode, the RLGR1 GR-mode zero branch updates kp with UP_GR (+4), while the decoder's corresponding branch (compute_rlgr1_magnitude) uses UQ_GR (+3), which is the value MS-RDPRFX 3.1.8.1.7.2 and FreeRDP's rfx_rlgr.c prescribe for GR mode. Because RLGR adaptation is implicit, encoder and decoder must update k identically from the coded symbols alone; with this mismatch the two sides' k diverges as soon as a zero value is coded in GR mode, and the remainder of the bitstream is misinterpreted (mode selection and run lengths depend on k).

Evidence

A randomized encode→decode round-trip (deterministic LCG, mostly-zero inputs with small magnitudes, i.e. the shape of quantized wavelet coefficients) failed on 1877 of 2000 inputs before this change. Example:

input:   [0, 2, -1, 7, 0, 0,  4,  -6, 7, 0, 1, 0, -4,  0,  0,  4, 1]
decoded: [0, 2, -1, 7, 0, 0,  2, -16, 5, 0, 2, 1,  4, -1, -1, -2, 0]

The divergence starts right after the first GR-mode zero. With the one-line fix, all 2000 round-trips pass.

Changes

  • Use UQ_GR in the GR-mode zero branch of the RLGR1 encoder, mirroring the decoder.
  • Add a rlgr1_round_trip_randomized regression test (rlgr.rs previously had no tests).

Found while debugging RemoteFX Progressive (EGFX) interop against xrdp in an IronRDP-based client.

🤖 Generated with Claude Code

In the GR-mode zero branch the RLGR1 encoder updated kp with UP_GR (+4)
while the decoder (compute_rlgr1_magnitude) uses UQ_GR (+3). The
asymmetric adaptation makes the adaptive k parameter diverge between
the two sides, after which the bitstream is misinterpreted: a
randomized encode->decode round-trip failed on 1877 of 2000 inputs
before this change.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant