From 19a0ff401d8e0f6b0209885b04b21b4c97884f61 Mon Sep 17 00:00:00 2001 From: Marco Fortina Date: Sat, 16 May 2026 06:09:09 +0000 Subject: [PATCH] libvncserver: read HTTP files in aligned chunks --- src/libvncserver/httpd.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libvncserver/httpd.c b/src/libvncserver/httpd.c index 7cefadc4..ade3f424 100644 --- a/src/libvncserver/httpd.c +++ b/src/libvncserver/httpd.c @@ -295,6 +295,7 @@ httpProcessInput(rfbScreenInfoPtr rfbScreen) unsigned int maxFnameLen; FILE* fd; rfbBool performSubstitutions = FALSE; + size_t bytesToRead; char str[256+32]; #ifndef WIN32 char* user=getenv("USER"); @@ -484,8 +485,12 @@ if(rfbScreen->httpEnableProxyConnect) { /* end the header */ rfbWriteExact(&cl, "\r\n", 2); + /* .vnc substitutions need one byte for NUL termination. Other + HTTP files can use the full, aligned buffer. */ + bytesToRead = performSubstitutions ? BUF_SIZE - 1 : BUF_SIZE; + while (1) { - int n = fread(buf, 1, BUF_SIZE-1, fd); + int n = fread(buf, 1, bytesToRead, fd); if (n < 0) { rfbLogPerror("httpProcessInput: read"); fclose(fd);