From 2344409c574e9fe3fe1d66cb51a56415cfea965b Mon Sep 17 00:00:00 2001 From: Khem Raj Date: Wed, 21 Oct 2026 08:51:51 -0700 Subject: [PATCH] ngtcp2: Fix example server build on 32-bit targets The example server keeps the file size in a uint64_t and uses it as the size of a std::span, which clang rejects as narrowing on targets with a 32-bit size_t, such as riscv32: examples/server.cc:236:54: error: non-constant-expression cannot be narrowed from type 'uint64_t' (aka 'unsigned long long') to 'size_type' (aka 'unsigned int') in initializer list [-Wc++11-narrowing] Add a patch that stores the length as a size_t and rejects files too large to map instead of truncating their size. AI-Generated: Uses Claude Code Signed-off-by: Khem Raj --- ...Do-not-truncate-file-sizes-on-32-bit.patch | 63 +++++++++++++++++++ .../recipes-protocols/ngtcp2/ngtcp2_1.25.0.bb | 4 +- 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 meta-networking/recipes-protocols/ngtcp2/ngtcp2/0001-examples-server-Do-not-truncate-file-sizes-on-32-bit.patch diff --git a/meta-networking/recipes-protocols/ngtcp2/ngtcp2/0001-examples-server-Do-not-truncate-file-sizes-on-32-bit.patch b/meta-networking/recipes-protocols/ngtcp2/ngtcp2/0001-examples-server-Do-not-truncate-file-sizes-on-32-bit.patch new file mode 100644 index 0000000000..746663dc20 --- /dev/null +++ b/meta-networking/recipes-protocols/ngtcp2/ngtcp2/0001-examples-server-Do-not-truncate-file-sizes-on-32-bit.patch @@ -0,0 +1,63 @@ +From: Khem Raj +Date: Wed, 21 Oct 2026 09:00:00 -0700 +Subject: [PATCH] examples/server: Do not truncate file sizes on 32-bit + targets + +FileEntry::len is a uint64_t, but it is used for mmap() and as the size +of the resp_data std::span, both of which take a size_t. On targets +where size_t is 32 bits, such as riscv32, clang rejects the narrowing in +the span initializer: + + examples/server.cc:236:54: error: non-constant-expression cannot be + narrowed from type 'uint64_t' (aka 'unsigned long long') to + 'size_type' (aka 'unsigned int') in initializer list [-Wc++11-narrowing] + +The value is already truncated earlier, where st_size is cast to size_t +before mmap(), so a file larger than the address space would be served +with the wrong length. + +Store the length as a size_t, and fail open_file() with +Error::INTEGER_OVERFLOW when the file is too large to map, instead of +truncating its size. + +Upstream-Status: Submitted [https://github.com/ngtcp2/ngtcp2/pull/2330] +Signed-off-by: Khem Raj +--- + examples/server.cc | 7 +++++++ + examples/server.h | 2 +- + 2 files changed, 8 insertions(+), 1 deletion(-) + +--- a/examples/server.cc ++++ b/examples/server.cc +@@ -31,6 +31,8 @@ + #include + #include + #include ++#include ++#include + + #include + #include +@@ -216,6 +218,11 @@ + close(fd); + } else { + fe.fd = fd; ++ // A file larger than the address space cannot be mapped. ++ if (std::cmp_greater(st.st_size, std::numeric_limits::max())) { ++ close(fd); ++ return std::unexpected{Error::INTEGER_OVERFLOW}; ++ } + fe.len = static_cast(st.st_size); + if (fe.len) { + fe.map = mmap(nullptr, fe.len, PROT_READ, MAP_SHARED, fd, 0); +--- a/examples/server.h ++++ b/examples/server.h +@@ -68,7 +68,7 @@ + }; + + struct FileEntry { +- uint64_t len{}; ++ size_t len{}; + void *map{}; + int fd{}; + uint8_t flags{}; diff --git a/meta-networking/recipes-protocols/ngtcp2/ngtcp2_1.25.0.bb b/meta-networking/recipes-protocols/ngtcp2/ngtcp2_1.25.0.bb index 2f91ec9318..a9d834a1b2 100644 --- a/meta-networking/recipes-protocols/ngtcp2/ngtcp2_1.25.0.bb +++ b/meta-networking/recipes-protocols/ngtcp2/ngtcp2_1.25.0.bb @@ -4,7 +4,9 @@ BUGTRACKER = "https://github.com/ngtcp2/ngtcp2/issues" LICENSE = "MIT" LIC_FILES_CHKSUM = "file://COPYING;md5=de0966c8ff4f62661a3da92967a75434" -SRC_URI = "gitsm://github.com/ngtcp2/ngtcp2;protocol=https;branch=main;tag=v${PV}" +SRC_URI = "gitsm://github.com/ngtcp2/ngtcp2;protocol=https;branch=main;tag=v${PV} \ + file://0001-examples-server-Do-not-truncate-file-sizes-on-32-bit.patch \ + " SRCREV = "f9e9ff01ad2c8116bc09de4f644b0028a61486a6" DEPENDS = "brotli libev nghttp3"