Author: brane
Date: Wed Aug  6 07:52:54 2025
New Revision: 1927634

Log:
Fix another integer narrowing warning.

* buckets/http2_frame_buckets.c
  (serf__bucket_http2_frame_create): Change the max_payload_size argument
   from an apr_uint32_t to an apr_size_t, because that's how we store it
   in our internal data structures. Move the size check to the beginning
   of the function so that we can never use a payload size that's too large.

* protocols/http2_buckets.h
  (serf__bucket_http2_frame_create): Update the prototype.

Modified:
   serf/trunk/buckets/http2_frame_buckets.c
   serf/trunk/protocols/http2_buckets.h

Modified: serf/trunk/buckets/http2_frame_buckets.c
==============================================================================
--- serf/trunk/buckets/http2_frame_buckets.c    Wed Aug  6 07:45:01 2025        
(r1927633)
+++ serf/trunk/buckets/http2_frame_buckets.c    Wed Aug  6 07:52:54 2025        
(r1927634)
@@ -630,12 +630,17 @@ serf__bucket_http2_frame_create(serf_buc
                                     void *baton,
                                     apr_int32_t *stream_id),
                                 void *stream_id_baton,
-                                apr_uint32_t max_payload_size,
+                                apr_size_t max_payload_size,
                                 serf_bucket_alloc_t *alloc)
 {
-    serf_http2_frame_context_t *ctx = serf_bucket_mem_alloc(alloc,
-                                                            sizeof(*ctx));
+    serf_http2_frame_context_t *ctx;
 
+    /* The upper limit for HTTP/2 MAX_FRAME_SIZE is 16 MiB - 1.
+       https://www.rfc-editor.org/rfc/rfc9113.html#section-4.2 */
+    if (max_payload_size > 0xFFFFFF)
+        max_payload_size = 0xFFFFFF;
+
+    ctx = serf_bucket_mem_alloc(alloc, sizeof(*ctx));
     ctx->alloc = alloc;
     ctx->stream = stream;
     ctx->chunk = serf_bucket_aggregate_create(alloc);
@@ -643,9 +648,6 @@ serf__bucket_http2_frame_create(serf_buc
     ctx->frametype = frame_type;
     ctx->flags = flags;
 
-    if (max_payload_size > 0xFFFFFF)
-        max_payload_size = 0xFFFFFF;
-
     if (!stream_id_alloc || (stream_id && *stream_id >= 0))
     {
       /* Avoid all alloc handling; we know the final id */
@@ -980,4 +982,3 @@ const serf_bucket_type_t serf_bucket_typ
     serf_http2_frame_get_remaining,
     serf_http2_frame_set_config
 };
-

Modified: serf/trunk/protocols/http2_buckets.h
==============================================================================
--- serf/trunk/protocols/http2_buckets.h        Wed Aug  6 07:45:01 2025        
(r1927633)
+++ serf/trunk/protocols/http2_buckets.h        Wed Aug  6 07:52:54 2025        
(r1927634)
@@ -202,7 +202,7 @@ serf__bucket_http2_frame_create(serf_buc
                                       void *baton,
                                       apr_int32_t *stream_id),
                                 void *stream_id_baton,
-                                apr_uint32_t max_payload_size,
+                                apr_size_t max_payload_size,
                                 serf_bucket_alloc_t *alloc);
 
 /* ==================================================================== */

Reply via email to