From 0433fe8c0fdb4c6983b4d770c8b6099929a0578c Mon Sep 17 00:00:00 2001 From: Will Anderson Date: Sun, 10 May 2026 19:23:10 -0500 Subject: [PATCH] Fix http_response() truncating envelope via stale _tl_fs_read_len MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit http_response() builds a JSON envelope wrapping the body. If the caller previously called fs_read() (which sets _tl_fs_read_len = file_size), http_worker used that stale value as the response copy length — truncating the larger envelope to the original file size before it reached http_send_response. The truncated envelope had the body field cut mid-string; jp_parse_string_raw failed, env_body = "", and http_send_all sent file_size bytes of garbage past the empty string. Fix: reset _tl_fs_read_len = 0 at the start of http_response(). The hint was set for the raw file bytes; the envelope is a new string and must use strlen() for its length. --- runtime/el_runtime.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/runtime/el_runtime.c b/runtime/el_runtime.c index 4d2874e..1356ae8 100644 --- a/runtime/el_runtime.c +++ b/runtime/el_runtime.c @@ -1961,6 +1961,13 @@ el_val_t http_response(el_val_t status, el_val_t headers_json, el_val_t body) { const char* b = EL_CSTR(body); if (!b) b = ""; + /* Clear the fs_read binary-length hint: the envelope we're about to build + * is a fresh JSON string, not the raw file bytes. Without this reset, + * http_worker would use the stale _tl_fs_read_len (= original file size) + * to copy the response — truncating the larger envelope before it reaches + * http_send_response and http_parse_envelope. */ + _tl_fs_read_len = 0; + JsonBuf out; jb_init(&out); jb_puts(&out, EL_HTTP_RESPONSE_TAG); /* {"el_http_response":1 */ jb_puts(&out, ",\"status\":"); -- 2.52.0