Skip to content

Commit

Permalink
Keep zlib streams when switching encodings
Browse files Browse the repository at this point in the history
Both RealVNC and TigerVNC clients expect zlib streams to remain when
switching encodings, so when they switch back, inflate fails if the
encoder is discared.

fixes #109
  • Loading branch information
any1 committed Feb 2, 2024
1 parent 4148503 commit a77ff63
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ struct nvnc_client {
struct cut_text cut_text;
bool is_ext_notified;
struct encoder* encoder;
struct encoder* zrle_encoder;
struct encoder* tight_encoder;
uint32_t cursor_seq;
int quality;

Expand Down
29 changes: 28 additions & 1 deletion src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ static void client_close(struct nvnc_client* client)
client->encoder->on_done = NULL;
}
encoder_unref(client->encoder);
encoder_unref(client->zrle_encoder);
encoder_unref(client->tight_encoder);
pixman_region_fini(&client->damage);
free(client->cut_text.buffer);
free(client);
Expand Down Expand Up @@ -1111,7 +1113,32 @@ static void process_fb_update_requests(struct nvnc_client* client)
client->encoder->on_done = NULL;
}
encoder_unref(client->encoder);
client->encoder = encoder_new(encoding, width, height);

/* Zlib streams need to be saved so we keep encoders around that
* use them.
*/
switch (encoding) {
case RFB_ENCODING_ZRLE:
if (!client->zrle_encoder) {
client->zrle_encoder = encoder_new(encoding,
width, height);
}
client->encoder = client->zrle_encoder;
encoder_ref(client->encoder);
break;
case RFB_ENCODING_TIGHT:
if (!client->tight_encoder) {
client->tight_encoder = encoder_new(encoding,
width, height);
}
client->encoder = client->tight_encoder;
encoder_ref(client->encoder);
break;
default:
client->encoder = encoder_new(encoding, width, height);
break;
}

if (!client->encoder) {
nvnc_log(NVNC_LOG_ERROR, "Failed to allocate new encoder");
return;
Expand Down

0 comments on commit a77ff63

Please sign in to comment.