From 408c992504b6e39d2a59104b2b3b987e98213659 Mon Sep 17 00:00:00 2001 From: Stackie Jia Date: Sat, 9 May 2026 15:43:54 +0800 Subject: [PATCH 1/2] fix: restore URL buffer size to 2048 bytes The zero-copy refactor (879acbc) inadvertently halved HTTP_URL_BUFFER_SIZE from 2048 to 1024 when moving it from connection.h to service.h. This causes truncation for users with long upstream URLs containing many query parameters. Restore all pipeline-synchronized URL buffer constants to 2048 and adjust the merged-URL overflow test accordingly. --- e2e/test_m3u.py | 6 +++--- src/http.h | 4 ++-- src/rtsp.h | 6 +++--- src/service.h | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/e2e/test_m3u.py b/e2e/test_m3u.py index bbfd379..0866d4a 100644 --- a/e2e/test_m3u.py +++ b/e2e/test_m3u.py @@ -1060,9 +1060,9 @@ def test_merged_url_overflow_returns_500(self, r2h_binary): rtsp = MockRTSPServer(num_packets=500) rtsp.start() try: - # ~600 bytes per side guarantees the merged URL exceeds 1024. - configured_pad = "padconfigured=" + ("a" * 600) - request_pad = "padrequest=" + ("b" * 600) + # ~1200 bytes per side guarantees the merged URL exceeds 2048. + configured_pad = "padconfigured=" + ("a" * 1200) + request_pad = "padrequest=" + ("b" * 1200) config = make_m3u_rtsp_config(r2h_port, rtsp.port, "OverflowMerge", "?" + configured_pad) r2h = R2HProcess(r2h_binary, r2h_port, config_content=config, capture_log=True) r2h.start() diff --git a/src/http.h b/src/http.h index 4306861..1ddf370 100644 --- a/src/http.h +++ b/src/http.h @@ -25,7 +25,7 @@ typedef enum { HTTP_PARSE_REQ_LINE = 0, HTTP_PARSE_HEADERS, HTTP_PARSE_BODY, HTT /* HTTP request structure */ typedef struct { char method[16]; - char url[1024]; + char url[2048]; char hostname[256]; char user_agent[256]; char accept[256]; @@ -212,7 +212,7 @@ void http_send_401(connection_t *conn); * @param port Output buffer for port (can be NULL), size should be at least 16 * bytes * @param path Output buffer for path (can be NULL), size should be at least - * 1024 bytes + * 2048 bytes * @return 0 on success, -1 on error */ int http_parse_url_components(const char *url, char *protocol, char *host, char *port, char *path); diff --git a/src/rtsp.h b/src/rtsp.h index 402a9d8..d31f3cd 100644 --- a/src/rtsp.h +++ b/src/rtsp.h @@ -33,20 +33,20 @@ /* RTSP server URL - complete RTSP URL. Kept in sync with HTTP_URL_BUFFER_SIZE * (service.h) so the entire pipeline shares one URL ceiling and there is no * silent mid-pipeline truncation. */ -#define RTSP_SERVER_URL_SIZE 1024 +#define RTSP_SERVER_URL_SIZE 2048 /* RTSP server hostname - DNS name or IP address */ #define RTSP_SERVER_HOST_SIZE 256 /* RTSP server path - path component of URL with query string. Same sizing * rationale as RTSP_SERVER_URL_SIZE. */ -#define RTSP_SERVER_PATH_SIZE 1024 +#define RTSP_SERVER_PATH_SIZE 2048 #define RTSP_CREDENTIAL_SIZE 128 /* URL copy buffer - for URL parsing operations. Same sizing rationale as * RTSP_SERVER_URL_SIZE. */ -#define RTSP_URL_COPY_SIZE 1024 +#define RTSP_URL_COPY_SIZE 2048 /* Time conversion buffers - for playseek time formatting */ #define RTSP_TIME_STRING_SIZE 64 diff --git a/src/service.h b/src/service.h index b901296..9d74ac0 100644 --- a/src/service.h +++ b/src/service.h @@ -15,7 +15,7 @@ * rtsp.h) is sized to match. Keep all four in sync to avoid silent * mid-pipeline truncation. */ #ifndef HTTP_URL_BUFFER_SIZE -#define HTTP_URL_BUFFER_SIZE 1024 +#define HTTP_URL_BUFFER_SIZE 2048 #endif /* HTTP URL component buffers - for parsing multicast URLs */ From 3f9ad398af7dd8aaba5d583a337737c9c156a7ce Mon Sep 17 00:00:00 2001 From: Stackie Jia Date: Sat, 9 May 2026 15:55:14 +0800 Subject: [PATCH 2/2] fix: address PR review feedback on URL buffer restore - Move HTTP_URL_BUFFER_SIZE definition from service.h to http.h so the macro is the single source of truth; use it for http_request_t.url instead of a hard-coded literal. - Raise config file MAX_LINE from 1024 to 4096 so inline M3U URLs up to 2048 bytes are not silently truncated by fgets. - Fix http_parse_url_components path copy limit from 1023 to 2047 to match the restored 2048-byte ceiling. --- src/configuration.c | 3 ++- src/http.c | 4 ++-- src/http.h | 10 +++++++++- src/service.h | 10 ---------- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/configuration.c b/src/configuration.c index 4196911..82dd7fe 100644 --- a/src/configuration.c +++ b/src/configuration.c @@ -1,5 +1,6 @@ #include "configuration.h" #include "epg.h" +#include "http.h" #include "m3u.h" #include "service.h" #include "utils.h" @@ -13,7 +14,7 @@ #include #include -#define MAX_LINE 1024 +#define MAX_LINE 4096 /* GLOBAL */ config_t config; diff --git a/src/http.c b/src/http.c index 4bac6cd..b292137 100644 --- a/src/http.c +++ b/src/http.c @@ -786,8 +786,8 @@ int http_parse_url_components(const char *url, char *protocol, char *host, char /* Extract path if present */ if (path_start && path) { - strncpy(path, path_start, 1023); - path[1023] = '\0'; + strncpy(path, path_start, 2047); + path[2047] = '\0'; } /* Parse host:port */ diff --git a/src/http.h b/src/http.h index 1ddf370..4b24b1d 100644 --- a/src/http.h +++ b/src/http.h @@ -3,6 +3,14 @@ #include +/* Maximum URL buffer size shared across the HTTP/RTSP pipeline. + * RTSP_SERVER_URL_SIZE, RTSP_SERVER_PATH_SIZE, and RTSP_URL_COPY_SIZE (rtsp.h) + * are sized to match. Keep all in sync to avoid silent mid-pipeline + * truncation. Compile-time override: -DHTTP_URL_BUFFER_SIZE=N */ +#ifndef HTTP_URL_BUFFER_SIZE +#define HTTP_URL_BUFFER_SIZE 2048 +#endif + /* Forward declaration */ typedef struct connection_s connection_t; @@ -25,7 +33,7 @@ typedef enum { HTTP_PARSE_REQ_LINE = 0, HTTP_PARSE_HEADERS, HTTP_PARSE_BODY, HTT /* HTTP request structure */ typedef struct { char method[16]; - char url[2048]; + char url[HTTP_URL_BUFFER_SIZE]; char hostname[256]; char user_agent[256]; char accept[256]; diff --git a/src/service.h b/src/service.h index 9d74ac0..dbebfa3 100644 --- a/src/service.h +++ b/src/service.h @@ -8,16 +8,6 @@ /* ========== HTTP/SERVICE BUFFER SIZE CONFIGURATION ========== */ -/* HTTP URL working buffer - for URL manipulation. The query-merge path in - * service_create_with_query_merge() builds into this same buffer and then - * re-parses through service_create_from_*_url(), and the RTSP layer - * (RTSP_SERVER_URL_SIZE / RTSP_SERVER_PATH_SIZE / RTSP_URL_COPY_SIZE in - * rtsp.h) is sized to match. Keep all four in sync to avoid silent - * mid-pipeline truncation. */ -#ifndef HTTP_URL_BUFFER_SIZE -#define HTTP_URL_BUFFER_SIZE 2048 -#endif - /* HTTP URL component buffers - for parsing multicast URLs */ #ifndef HTTP_ADDR_COMPONENT_SIZE #define HTTP_ADDR_COMPONENT_SIZE 256